domain2idna

raw JSON →
1.12.4 verified Mon Apr 27 auth: no python

A Python tool to convert domains (or files containing domain lists) to IDNA (Punycode) format. Current version 1.12.4 supports Python >=3.6.2, <4.0. Release cadence is irregular with maintenance updates.

pip install domain2idna
error AttributeError: module 'domain2idna' has no attribute 'get'
cause The 'get' function was deprecated and removed in newer versions.
fix
Use 'from domain2idna import convert' and call 'convert()' instead.
error TypeError: convert() missing 1 required positional argument: 'to_transform'
cause The 'convert()' function requires a string argument representing the domain.
fix
Pass the domain as a string: convert('example.com')
deprecated The 'get' function was deprecated in v1.10.1 and removed in later versions. Use 'convert' instead.
fix Replace 'get()' with 'convert()'.
gotcha The library may return the input unchanged if it is already ASCII or contains common hostnames like 'localhost'. Check the documentation for ignored domains.
fix Be aware that certain strings (e.g., 'localhost', '0.0.0.0') are ignored and returned as-is.

Convert a single domain with non-ASCII characters to IDNA (Punycode) format.

from domain2idna import convert

result = convert('münchen.de')
print(result)  # Output: xn--mnchen-3ya.de