METADATA 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. Metadata-Version: 2.4
  2. Name: idna
  3. Version: 3.18
  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 :: Implementation :: CPython
  23. Classifier: Programming Language :: Python :: Implementation :: PyPy
  24. Classifier: Topic :: Internet :: Name Service (DNS)
  25. Classifier: Topic :: Software Development :: Libraries :: Python Modules
  26. Classifier: Topic :: Utilities
  27. License-File: LICENSE.md
  28. Requires-Dist: ruff >= 0.6.2 ; extra == "all"
  29. Requires-Dist: mypy >= 1.11.2 ; extra == "all"
  30. Requires-Dist: pytest >= 8.3.2 ; extra == "all"
  31. Project-URL: Changelog, https://github.com/kjd/idna/blob/master/HISTORY.md
  32. Project-URL: Issue tracker, https://github.com/kjd/idna/issues
  33. Project-URL: Source, https://github.com/kjd/idna
  34. Provides-Extra: all
  35. # Internationalized Domain Names in Applications (IDNA)
  36. Support for [Internationalized Domain Names in Applications
  37. (IDNA)](https://tools.ietf.org/html/rfc5891) and [Unicode IDNA
  38. Compatibility Processing](https://unicode.org/reports/tr46/). It
  39. supersedes the standard library's `encodings.idna`, which only
  40. implements the 2003 specification, offering broader script coverage and
  41. limiting domains with known security vulnerabilities.
  42. ## Usage
  43. Package may be installed from [PyPI](https://pypi.org/project/idna/) via
  44. the typical methods (e.g. `python3 -m pip install idna`)
  45. For typical usage, the `encode` and `decode` functions will take a
  46. domain name argument and perform a conversion to ASCII-compatible encoding
  47. (known as A-labels), or to Unicode strings (known as U-labels)
  48. respectively.
  49. ```pycon
  50. >>> import idna
  51. >>> idna.encode('ドメイン.テスト')
  52. b'xn--eckwd4c7c.xn--zckzah'
  53. >>> print(idna.decode('xn--eckwd4c7c.xn--zckzah'))
  54. ドメイン.テスト
  55. ```
  56. Conversions can be applied at a per-label basis using the `ulabel` or
  57. `alabel` functions for specialized use cases.
  58. ### Compatibility Mapping (UTS #46)
  59. This library provides support for [Unicode IDNA Compatibility
  60. Processing](https://unicode.org/reports/tr46/) which normalizes input from
  61. different potential ways a user may input a domain prior to performing the IDNA
  62. conversion operations. This functionality, known as a
  63. [mapping](https://tools.ietf.org/html/rfc5895), is considered by the
  64. specification to be a local user-interface issue distinct from IDNA
  65. conversion functionality.
  66. For example, "Königsgäßchen" is not a permissible label as capital letters
  67. are not allowed. UTS 46 will convert this into lower case prior to applying
  68. the IDNA conversion.
  69. ```pycon
  70. >>> import idna
  71. >>> idna.encode('Königsgäßchen')
  72. ...
  73. idna.core.InvalidCodepoint: Codepoint U+004B at position 1 of 'Königsgäßchen' not allowed
  74. >>> idna.encode('Königsgäßchen', uts46=True)
  75. b'xn--knigsgchen-b4a3dun'
  76. >>> idna.decode('xn--knigsgchen-b4a3dun')
  77. 'königsgäßchen'
  78. ```
  79. When performing a decode operation for display purposes, `decode()`
  80. accepts a `display=True` argument that leaves any `xn--` label that
  81. fails to decode unchanged. This is useful for user interface display
  82. where a domain is in use, the A-label form can be presented when it
  83. is not a valid IDN.
  84. ## Exceptions
  85. All errors raised during conversion derive from the `idna.IDNAError`
  86. base class. The more specific exceptions are:
  87. * `idna.IDNABidiError` — raised when a label contains an illegal
  88. combination of left-to-right and right-to-left characters.
  89. * `idna.InvalidCodepoint` — raised when a label contains a codepoint
  90. that is INVALID for IDNA.
  91. * `idna.InvalidCodepointContext` — raised when a CONTEXTO or CONTEXTJ
  92. codepoint appears in a position whose contextual requirements are
  93. not satisfied.
  94. ## Command-line tool
  95. The package supports command-line usage to convert domain names
  96. between their Unicode and ASCII-compatible forms. It can be run either
  97. as a module (`python3 -m idna`) or, once installed (such as with `uv
  98. tool` or `pipx`), via the `idna` script:
  99. ```bash
  100. $ uv tool install idna
  101. $ idna xn--e1afmkfd.xn--p1ai
  102. пример.рф
  103. $ idna пример.рф
  104. xn--e1afmkfd.xn--p1ai
  105. ```
  106. Mode can be specified with `-e`/`--encode` or `-d`/`--decode`, otherwise
  107. it will be chosen automatically based on the first input. Multiple
  108. domains can be supplied either as arguments or through standard input.
  109. UTS #46 mapping is applied by default, which lets the tool accept
  110. inputs that aren't strictly valid IDNA 2008 by normalising them first,
  111. pass `--strict` to disable UTS #46.
  112. Conversion failures are reported on stderr together with the
  113. offending input; processing continues with the remaining domains and
  114. the tool exits with a non-zero status if any conversion failed.
  115. ## Additional Notes
  116. * **Version support**. This library supports Python 3.9 and higher.
  117. As this library serves as a low-level toolkit for a variety of
  118. applications, we strive to support all versions of Python that are
  119. not beyond end-of-life.
  120. * **Emoji**. It is an occasional request to support emoji domains in
  121. this library. Encoding of symbols like emoji is expressly prohibited by
  122. the IDNA technical standard, and emoji domains are broadly phased
  123. out across the domain industry due to associated security risks.
  124. * **Regenerating lookup tables**. The IDNA and UTS 46 functionality
  125. relies upon pre-calculated lookup tables, generated using the
  126. `idna-data` script in [`tools/`](tools/README.md).