METADATA 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. Metadata-Version: 2.5
  2. Name: idna
  3. Version: 3.20
  4. Summary: Internationalized Domain Names in Applications (IDNA)
  5. Author-email: Kim Davies <kim+pypi@gumleaf.org>
  6. Requires-Python: >=3.9
  7. Description-Content-Type: text/markdown
  8. License-Expression: BSD-3-Clause
  9. Classifier: Development Status :: 5 - Production/Stable
  10. Classifier: Intended Audience :: Developers
  11. Classifier: Intended Audience :: System Administrators
  12. Classifier: Operating System :: OS Independent
  13. Classifier: Programming Language :: Python
  14. Classifier: Programming Language :: Python :: 3
  15. Classifier: Programming Language :: Python :: 3 :: Only
  16. Classifier: Programming Language :: Python :: 3.9
  17. Classifier: Programming Language :: Python :: 3.10
  18. Classifier: Programming Language :: Python :: 3.11
  19. Classifier: Programming Language :: Python :: 3.12
  20. Classifier: Programming Language :: Python :: 3.13
  21. Classifier: Programming Language :: Python :: 3.14
  22. Classifier: Programming Language :: Python :: 3.15
  23. Classifier: Programming Language :: Python :: Implementation :: CPython
  24. Classifier: Programming Language :: Python :: Implementation :: PyPy
  25. Classifier: Topic :: Internet :: Name Service (DNS)
  26. Classifier: Topic :: Software Development :: Libraries :: Python Modules
  27. Classifier: Topic :: Utilities
  28. License-File: LICENSE.md
  29. Requires-Dist: ruff >= 0.16.0 ; extra == "all"
  30. Requires-Dist: mypy >= 1.11.2 ; extra == "all"
  31. Requires-Dist: ty >= 0.0.37 ; extra == "all"
  32. Requires-Dist: pytest >= 8.3.2 ; extra == "all"
  33. Requires-Dist: hypothesis >= 6.141.1 ; extra == "all"
  34. Requires-Dist: coverage >= 7.10.0 ; extra == "all"
  35. Project-URL: Changelog, https://github.com/kjd/idna/blob/master/HISTORY.md
  36. Project-URL: Issue tracker, https://github.com/kjd/idna/issues
  37. Project-URL: Source, https://github.com/kjd/idna
  38. Provides-Extra: all
  39. Import-Name: idna
  40. # Internationalized Domain Names in Applications (IDNA)
  41. Support for [Internationalized Domain Names in Applications
  42. (IDNA)](https://tools.ietf.org/html/rfc5891) and [Unicode IDNA
  43. Compatibility Processing](https://unicode.org/reports/tr46/). It
  44. supersedes the standard library's `encodings.idna`, which only
  45. implements the 2003 specification, offering broader script coverage and
  46. limiting domains with known security vulnerabilities.
  47. ## Usage
  48. Package may be installed from [PyPI](https://pypi.org/project/idna/) via
  49. the typical methods (e.g. `python3 -m pip install idna`)
  50. For typical usage, the `encode` and `decode` functions will take a
  51. domain name argument and perform a conversion to ASCII-compatible encoding
  52. (known as A-labels), or to Unicode strings (known as U-labels)
  53. respectively.
  54. ```pycon
  55. >>> import idna
  56. >>> idna.encode('ドメイン.テスト')
  57. b'xn--eckwd4c7c.xn--zckzah'
  58. >>> print(idna.decode('xn--eckwd4c7c.xn--zckzah'))
  59. ドメイン.テスト
  60. ```
  61. Conversions can be applied at a per-label basis using the `ulabel` or
  62. `alabel` functions for specialized use cases.
  63. ### Compatibility Mapping (UTS #46)
  64. This library provides support for [Unicode IDNA Compatibility
  65. Processing](https://unicode.org/reports/tr46/) which normalizes input from
  66. different potential ways a user may input a domain prior to performing the IDNA
  67. conversion operations. This functionality, known as a
  68. [mapping](https://tools.ietf.org/html/rfc5895), is considered by the
  69. specification to be a local user-interface issue distinct from IDNA
  70. conversion functionality.
  71. For example, "Königsgäßchen" is not a permissible label as capital letters
  72. are not allowed. UTS #46 will convert this into lower case prior to applying
  73. the IDNA conversion.
  74. ```pycon
  75. >>> import idna
  76. >>> idna.encode('Königsgäßchen')
  77. ...
  78. idna.core.InvalidCodepoint: Codepoint U+004B at position 1 of 'Königsgäßchen' not allowed
  79. >>> idna.encode('Königsgäßchen', uts46=True)
  80. b'xn--knigsgchen-b4a3dun'
  81. >>> idna.decode('xn--knigsgchen-b4a3dun')
  82. 'königsgäßchen'
  83. ```
  84. When performing a decode operation for display purposes, `decode()`
  85. accepts a `display=True` argument that leaves any `xn--` label that
  86. fails to decode unchanged. This is useful for user interface display
  87. where a domain is in use, the A-label form can be presented when it
  88. is not a valid IDN.
  89. ## Exceptions
  90. All errors raised during conversion derive from the `idna.IDNAError`
  91. base class. The more specific exceptions are:
  92. * `idna.IDNABidiError` — raised when a label contains an illegal
  93. combination of left-to-right and right-to-left characters.
  94. * `idna.InvalidCodepoint` — raised when a label contains a codepoint
  95. that is INVALID for IDNA.
  96. * `idna.InvalidCodepointContext` — raised when a CONTEXTO or CONTEXTJ
  97. codepoint appears in a position whose contextual requirements are
  98. not satisfied.
  99. Exceptions carry machine-readable attributes so that applications do
  100. not need to parse the message: `code` is a short, stable identifier
  101. for the rule that failed (such as `disallowed_codepoint` or
  102. `label_too_long`); and, when the failure can be attributed to a
  103. particular character, `text` (the label or domain being validated),
  104. `codepoint` (the offending codepoint as an integer) and `position`
  105. are set.
  106. ## Command-line tool
  107. The package supports command-line usage to convert domain names
  108. between their Unicode and ASCII-compatible forms. It can be run either
  109. as a module (`python3 -m idna`) or, once installed (such as with `uv
  110. tool` or `pipx`), via the `idna` script:
  111. ```bash
  112. $ uv tool install idna
  113. $ idna xn--e1afmkfd.xn--p1ai
  114. пример.рф
  115. $ idna пример.рф
  116. xn--e1afmkfd.xn--p1ai
  117. ```
  118. Mode can be specified with `-e`/`--encode` or `-d`/`--decode`, otherwise
  119. it will be chosen automatically based on the first input. Multiple
  120. domains can be supplied either as arguments or through standard input.
  121. UTS #46 mapping is applied by default, which lets the tool accept
  122. inputs that aren't strictly valid IDNA 2008 by normalising them first,
  123. pass `--strict` to disable UTS #46.
  124. Conversion failures are reported on stderr together with the
  125. offending input; processing continues with the remaining domains and
  126. the tool exits with a non-zero status if any conversion failed.
  127. ## Additional Notes
  128. * **Python version support**. This library supports Python 3.9 and higher.
  129. As this library serves as a low-level toolkit for a variety of
  130. applications, we strive to support all versions of Python that are
  131. not beyond end-of-life. Free-threaded Python is also supported,
  132. as the library holds no mutable global state the functions can be
  133. called concurrently from multiple threads.
  134. * **Unicode version**. The IDNA and UTS #46 lookup tables are generated
  135. from a specific Unicode release. Some Unicode data depends on the
  136. running Python's `unicodedata` module, so on an older Python a
  137. character new to Unicode may be rejected as unknown even if this
  138. library knows about it.
  139. * **Emoji**. It is an occasional request to support emoji domains in
  140. this library. Encoding of symbols like emoji is expressly prohibited by
  141. the IDNA technical standard, and emoji domains are broadly phased
  142. out across the domain industry due to associated security risks.
  143. * **Regenerating lookup tables**. The IDNA and UTS #46 functionality
  144. relies upon pre-calculated lookup tables, generated using the
  145. `idna-data` script in [`tools/`](tools/README.md).