pydn2


Namepydn2 JSON
Version 0.0.6 PyPI version JSON
download
home_pageNone
SummaryThin wrapper around libidn2
upload_time2025-02-12 17:38:19
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseMIT
keywords libidn2 idn2 idn2008
VCS
bugtrack_url
requirements pytest setuptools
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pydn2

**pydn2** is a Python binding for [libidn2](https://libidn.gitlab.io/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](https://www.gnu.org/software/libidn/libidn2/manual/libidn2.html) is installed on your system. On macOS with Homebrew, you can install it via:
  ```bash
  brew install libidn2
  ```
  On linux debian based system:
  ```bash
  sudo apt-get -y install libidn2-0 libidn2-dev
  ```
- A C compiler that supports building Python C extensions.
- Python 3.9–3.12 (and possibly newer versions if you update the CI matrix).

## Installation

```bash
pip install pydn2
```

## Usage

```python
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.


## Benchmark

| Method                    | Conversion Output | Single-thread Benchmark (sec, 1,000,000 iterations) | Multi-thread Benchmark (sec, 1,000,000 iterations) |
|---------------------------|-------------------|----------------------------------------------------:|---------------------------------------------------:|
| **pydn2 (IDNA2008/TR46)** | `xn--i-n3p.com`   |                                            1.170304 |                                           1.156370 |
| **builtin (IDNA2003)**    | `xn--i-n3p.com`   |                                            6.716825 |                                           6.674858 |

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pydn2",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "libidn2, idn2, IDN2008",
    "author": null,
    "author_email": "StupidCodeFactory <ymarquet@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/51/24/ab27c783dca59dddfff118e861ebbd86bc0a41b9a8ef1dfad26340c2fa92/pydn2-0.0.6.tar.gz",
    "platform": null,
    "description": "# pydn2\n\n**pydn2** is a Python binding for [libidn2](https://libidn.gitlab.io/libidn2/), the GNU implementation of the Internationalized Domain Names (IDNA) protocol (IDNA2008/TR46). This extension enables you to perform various domain name conversions\u2014such as converting between Unicode (U-label) and ASCII-compatible (A-label) representations\u2014and supports the full public API of libidn2.\n\n## Features\n\n- **Conversion Functions**\n  - Convert Unicode domain names to their ASCII (Punycode) equivalents.\n  - Convert Punycode domains back to Unicode.\n  - Perform lookup conversions for registration and DNS lookup.\n- **Error Handling**\n  - Retrieve human-readable error messages and error code names.\n- **Compliance with IDNA2008/TR46**\n  - Uses flags to control normalization and processing (e.g. NFC, transitional/non-transitional).\n\n## Requirements\n\n- **libidn2**\n  Make sure [libidn2](https://www.gnu.org/software/libidn/libidn2/manual/libidn2.html) is installed on your system. On macOS with Homebrew, you can install it via:\n  ```bash\n  brew install libidn2\n  ```\n  On linux debian based system:\n  ```bash\n  sudo apt-get -y install libidn2-0 libidn2-dev\n  ```\n- A C compiler that supports building Python C extensions.\n- Python 3.9\u20133.12 (and possibly newer versions if you update the CI matrix).\n\n## Installation\n\n```bash\npip install pydn2\n```\n\n## Usage\n\n```python\nimport pydn2\n\n# Convert a Unicode domain to its ASCII (Punycode) representation:\nascii_domain = pydn2.to_ascii_8z(\"b\u00fccher\", 0)\nprint(ascii_domain)  # e.g., \"xn--bcher-kva\"\n\n# Convert a Punycode domain back to Unicode:\nunicode_domain = pydn2.to_unicode_8z8z(\"xn--bcher-kva\", 0)\nprint(unicode_domain)  # e.g., \"b\u00fccher\"\n\n# You can also use flags for additional processing:\nascii_domain_transitional = pydn2.to_ascii_8z(\"\u262e\ufe0f.com\", pydn2.IDN2_NFC_INPUT | pydn2.IDN2_TRANSITIONAL)\nprint(ascii_domain_transitional)\n```\n\n## Module Constants\n\nThe extension exposes several flag constants for controlling conversion behavior:\n- IDN2_NFC_INPUT \u2013 Apply NFC normalization on input.\n- IDN2_ALABEL_ROUNDTRIP \u2013 Apply additional round-trip conversion of A-label inputs.\n- IDN2_TRANSITIONAL \u2013 Perform Unicode TR46 transitional processing.\n- IDN2_NONTRANSITIONAL \u2013 Perform Unicode TR46 non-transitional processing (default).\n- IDN2_NO_TR46 \u2013 Disable any TR46 transitional or non-transitional processing.\n- IDN2_USE_STD3_ASCII_RULES \u2013 Use STD3 ASCII rules.\n\n\n## Benchmark\n\n| Method                    | Conversion Output | Single-thread Benchmark (sec, 1,000,000 iterations) | Multi-thread Benchmark (sec, 1,000,000 iterations) |\n|---------------------------|-------------------|----------------------------------------------------:|---------------------------------------------------:|\n| **pydn2 (IDNA2008/TR46)** | `xn--i-n3p.com`   |                                            1.170304 |                                           1.156370 |\n| **builtin (IDNA2003)**    | `xn--i-n3p.com`   |                                            6.716825 |                                           6.674858 |\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Thin wrapper around libidn2",
    "version": "0.0.6",
    "project_urls": {
        "Changelog": "https://github.com/StupidCodeFactory/pydn2/releases",
        "Documentation": "https://github.com/StupidCodeFactory/pydn2/blob/main/tests/test_pydn2.py",
        "Homepage": "https://github.com/StupidCodeFactory/pydn2",
        "Repository": "https://github.com/StupidCodeFactory/pydn2"
    },
    "split_keywords": [
        "libidn2",
        " idn2",
        " idn2008"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "5124ab27c783dca59dddfff118e861ebbd86bc0a41b9a8ef1dfad26340c2fa92",
                "md5": "392e98b2abbc9cb9dd3a0a936d03d0f1",
                "sha256": "9d5ddf97abd3073afccab767c283f76489a6b2f940fe25a6880c86e0974fbe91"
            },
            "downloads": -1,
            "filename": "pydn2-0.0.6.tar.gz",
            "has_sig": false,
            "md5_digest": "392e98b2abbc9cb9dd3a0a936d03d0f1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 5138,
            "upload_time": "2025-02-12T17:38:19",
            "upload_time_iso_8601": "2025-02-12T17:38:19.962562Z",
            "url": "https://files.pythonhosted.org/packages/51/24/ab27c783dca59dddfff118e861ebbd86bc0a41b9a8ef1dfad26340c2fa92/pydn2-0.0.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-12 17:38:19",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "StupidCodeFactory",
    "github_project": "pydn2",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "pytest",
            "specs": []
        },
        {
            "name": "setuptools",
            "specs": []
        }
    ],
    "lcname": "pydn2"
}
        
Elapsed time: 1.26750s