Skip to main content

Internationalized Domain Names in Applications (IDNA)

Support for Internationalized Domain Names in Applications (IDNA) and Unicode IDNA Compatibility Processing. It supersedes the standard library's encodings.idna, which only implements the 2003 specification, offering broader script coverage and limiting domains with known security vulnerabilities.

Usage

Package may be installed from PyPI via the typical methods (e.g. python3 -m pip install idna)

For typical usage, the encode and decode functions will take a domain name argument and perform a conversion to ASCII-compatible encoding (known as A-labels), or to Unicode strings (known as U-labels) respectively.

>>> import idna
>>> idna.encode('ドメイン.テスト')
b'xn--eckwd4c7c.xn--zckzah'
>>> print(idna.decode('xn--eckwd4c7c.xn--zckzah'))
ドメイン.テスト

Conversions can be applied at a per-label basis using the ulabel or alabel functions for specialized use cases.

Compatibility Mapping (UTS #46)

This library provides support for Unicode IDNA Compatibility Processing which normalizes input from different potential ways a user may input a domain prior to performing the IDNA conversion operations. This functionality, known as a mapping, is considered by the specification to be a local user-interface issue distinct from IDNA conversion functionality.

For example, "Königsgäßchen" is not a permissible label as capital letters are not allowed. UTS #46 will convert this into lower case prior to applying the IDNA conversion.

>>> import idna
>>> idna.encode('Königsgäßchen')
...
idna.core.InvalidCodepoint: Codepoint U+004B at position 1 of 'Königsgäßchen' not allowed
>>> idna.encode('Königsgäßchen', uts46=True)
b'xn--knigsgchen-b4a3dun'
>>> idna.decode('xn--knigsgchen-b4a3dun')
'königsgäßchen'

When performing a decode operation for display purposes, decode() accepts a display=True argument that leaves any xn-- label that fails to decode unchanged. This is useful for user interface display where a domain is in use, the A-label form can be presented when it is not a valid IDN.

Exceptions

All errors raised during conversion derive from the idna.IDNAError base class. The more specific exceptions are:

  • idna.IDNABidiError — raised when a label contains an illegal combination of left-to-right and right-to-left characters.
  • idna.InvalidCodepoint — raised when a label contains a codepoint that is INVALID for IDNA.
  • idna.InvalidCodepointContext — raised when a CONTEXTO or CONTEXTJ codepoint appears in a position whose contextual requirements are not satisfied.

Exceptions carry machine-readable attributes so that applications do not need to parse the message: code is a short, stable identifier for the rule that failed (such as disallowed_codepoint or label_too_long); and, when the failure can be attributed to a particular character, text (the label or domain being validated), codepoint (the offending codepoint as an integer) and position are set.

Command-line tool

The package supports command-line usage to convert domain names between their Unicode and ASCII-compatible forms. It can be run either as a module (python3 -m idna) or, once installed (such as with uv tool or pipx), via the idna script:

$ uv tool install idna
$ idna xn--e1afmkfd.xn--p1ai
пример.рф
$ idna пример.рф
xn--e1afmkfd.xn--p1ai

Mode can be specified with -e/--encode or -d/--decode, otherwise it will be chosen automatically based on the first input. Multiple domains can be supplied either as arguments or through standard input. UTS #46 mapping is applied by default, which lets the tool accept inputs that aren't strictly valid IDNA 2008 by normalising them first, pass --strict to disable UTS #46.

Conversion failures are reported on stderr together with the offending input; processing continues with the remaining domains and the tool exits with a non-zero status if any conversion failed.

Additional Notes

  • Python version support. This library supports Python 3.9 and higher. As this library serves as a low-level toolkit for a variety of applications, we strive to support all versions of Python that are not beyond end-of-life. Free-threaded Python is also supported, as the library holds no mutable global state the functions can be called concurrently from multiple threads.

  • Unicode version. The IDNA and UTS #46 lookup tables are generated from a specific Unicode release. Some Unicode data depends on the running Python's unicodedata module, so on an older Python a character new to Unicode may be rejected as unknown even if this library knows about it.

  • Emoji. It is an occasional request to support emoji domains in this library. Encoding of symbols like emoji is expressly prohibited by the IDNA technical standard, and emoji domains are broadly phased out across the domain industry due to associated security risks.

  • Regenerating lookup tables. The IDNA and UTS #46 functionality relies upon pre-calculated lookup tables, generated using the idna-data script in tools/.

Release files for idna 3.20

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for idna 3.20
File Size Uploaded
idna-3.20.tar.gz 216.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for idna 3.20
File Interpreter ABI Platform
idna-3.20-py3-none-any.whl Python 3 none any Details

Total release size: 286.0 kB

Release files / idna-3.20.tar.gz

Download URL idna-3.20.tar.gz
Size 216.5 kB
Tags Source
SHA-256 checksum
How to use checksums
a7db850025b95ded1eae8a46181a1a6c56c92c96f0e2b005d9ff8dc0210cab44
BLAKE2b-256 checksum
How to use checksums
f5088eea9d4b8302028f3abb2c0813953f7aec26d33b7a8960ed760e65ff29fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 17, 2026.

Transparency log

Release files / idna-3.20-py3-none-any.whl

Download URL idna-3.20-py3-none-any.whl
Size 69.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ab7ae7122974553370f0bdb919e1a960b2cd1bc1ef0276416d896db81c14582c
BLAKE2b-256 checksum
How to use checksums
58a2bb081bab032533a855d44de1d56f8e8426114ff1ba5d1f07a438a0a654f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 17, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

3.20 This release

2 release files

3.19

2 release files

3.18

2 release files

3.17

2 release files

3.16

2 release files

3.15

2 release files

3.14

2 release files

3.13

2 release files

3.12

2 release files

3.11

2 release files

3.10

2 release files

3.9

2 release files

3.8

2 release files

3.7

2 release files

3.6

2 release files

3.5

2 release files

3.4

2 release files

3.3

2 release files

3.2

2 release files

3.1

2 release files

3.0

2 release files

2.10

2 release files

2.9

2 release files

2.8

2 release files

2.7

2 release files

2.6

2 release files

2.5

2 release files

2.4

2 release files

2.3

2 release files

2.2

2 release files

2.1

3 release files

2.0

2 release files

1.1

1 release file

1.0

1 release file

0.9

1 release file

0.8

1 release file

0.7

1 release file

0.6

1 release file

0.5

1 release file

0.4

1 release file

0.3

1 release file

0.2

1 release file

0.1

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page