Python binding for libidn2
Project description
pydn2
pydn2 is a Python binding for libidn2, the GNU implementation of the Internationalized Domain Names (IDNA) protocol (IDNA2008/TR46). This extension enables you to perform various domain name conversions—such as converting between Unicode (U-label) and ASCII-compatible (A-label) representations—and supports the full public API of libidn2.
Features
- Conversion Functions
- Convert Unicode domain names to their ASCII (Punycode) equivalents.
- Convert Punycode domains back to Unicode.
- Perform lookup conversions for registration and DNS lookup.
- Error Handling
- Retrieve human-readable error messages and error code names.
- Compliance with IDNA2008/TR46
- Uses flags to control normalization and processing (e.g. NFC, transitional/non-transitional).
Requirements
- libidn2
Make sure libidn2 is installed on your system. On macOS with Homebrew, you can install it via:
brew install libidn2
- A C compiler that supports building Python C extensions.
- Python 3.7–3.9 (and possibly newer versions if you update the CI matrix).
Installation
pip install pydn2
Usage
import pydn2
# Convert a Unicode domain to its ASCII (Punycode) representation:
ascii_domain = pydn2.to_ascii_8z("bücher", 0)
print(ascii_domain) # e.g., "xn--bcher-kva"
# Convert a Punycode domain back to Unicode:
unicode_domain = pydn2.to_unicode_8z8z("xn--bcher-kva", 0)
print(unicode_domain) # e.g., "bücher"
# You can also use flags for additional processing:
ascii_domain_transitional = pydn2.to_ascii_8z("☮️.com", pydn2.IDN2_NFC_INPUT | pydn2.IDN2_TRANSITIONAL)
print(ascii_domain_transitional)
Module Constants
The extension exposes several flag constants for controlling conversion behavior:
- IDN2_NFC_INPUT – Apply NFC normalization on input.
- IDN2_ALABEL_ROUNDTRIP – Apply additional round-trip conversion of A-label inputs.
- IDN2_TRANSITIONAL – Perform Unicode TR46 transitional processing.
- IDN2_NONTRANSITIONAL – Perform Unicode TR46 non-transitional processing (default).
- IDN2_NO_TR46 – Disable any TR46 transitional or non-transitional processing.
- IDN2_USE_STD3_ASCII_RULES – Use STD3 ASCII rules.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pydn2-0.0.3.tar.gz
(4.1 kB
view details)
File details
Details for the file pydn2-0.0.3.tar.gz.
File metadata
- Download URL: pydn2-0.0.3.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f8e85eb974ec900a35126d10ea6445b1aabf60acbe67659b9d74e8d28fa7398d
|
|
| MD5 |
20dcdf9e5562f7e0b0ce000cf0f4ee4f
|
|
| BLAKE2b-256 |
6c0d20bbca1d68344145ffde87941b7fd1d90231c2e83711c102bd81f74de565
|