punycode


Namepunycode JSON
Version 0.2.1 PyPI version JSON
download
home_pagehttps://github.com/Yutsuro/punycode
SummaryPunycode Converter Library for Python
upload_time2023-03-27 14:33:10
maintainer
docs_urlNone
authorYutsuro
requires_python
licenseMIT
keywords punycode converter python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ![punycode logo](https://raw.githubusercontent.com/Yutsuro/punycode/main/image/logo.png)



**Punycode Converter Library for Python**



You can convert Punycode domain to/from Unicode domain with only one function: `punycode.convert()`.



## How to use



### Install



```sh

pip install punycode

```



### Function



There is only one function `punycode.convert()`.



* <b>input:</b>  

`input_text: string`  

Input can be both a Punycode domain and a Unicode domain.



* <b>return:</b>  

`output_text: string`  

If you input Punycode domain, the return will be a Unicode domian.  

On the other hand, if you input a Unicode domain, you will get a Punycode domain.



### Code sample



```python

import punycode



# Convert Unicode domain to Punycode domain

str1 = "美しい.世界"

str2 = "こっち.みんな"

str3 = "日本語.jp"

print(f"{str1} -> {punycode.convert(str1)}")

print(f"{str2} -> {punycode.convert(str2)}")

print(f"{str3} -> {punycode.convert(str3)}")



# 僕だけの.世界 -> xn--08j3a5b142t.xn--rhqv96g

# こっち.みんな -> xn--l8j9flb8a.xn--q9jyb4c

# 日本語.jp -> xn--wgv71a119e.jp



# Punycode domain to Unicode domain

str4 = "xn--n8jub8754b.xn--rhqv96g"

str5 = "xn--28j2af.xn--q9jyb4c"

str6 = "xn--wgv71a119e.jp"

print(f"{str4} -> {punycode.convert(str4)}")

print(f"{str5} -> {punycode.convert(str5)}")

print(f"{str6} -> {punycode.convert(str6)}")



# xn--n8jub8754b.xn--rhqv96g -> 美しい.世界

# xn--28j2af.xn--q9jyb4c -> こっち.みんな

# xn--wgv71a119e.jp -> 日本語.jp

```



## ascii_only option (v0.2.0 or later)



If you don't want to convert a Punycode domain to Unicode when you use `convert()` function, you can use `ascii_only` option. (Default: False)



With this option `True`, `convert()` will convert only Unicode domains.



```python

# ascii_only option (v0.2.0 or later)

ascii_only = True



# Only Unicode domains will be converted if ascii_only=True

print(f"{str4} -> {punycode.convert(str4, ascii_only)}")

print(f"{str5} -> {punycode.convert(str5, ascii_only)}")

print(f"{str6} -> {punycode.convert(str6, ascii_only)}")



# xn--n8jub8754b.xn--rhqv96g -> xn--n8jub8754b.xn--rhqv96g

# xn--28j2af.xn--q9jyb4c -> xn--28j2af.xn--q9jyb4c

# xn--wgv71a119e.jp -> xn--wgv71a119e.jp

```



This option is available on 0.2.0 or later version, so if you use v0.1.0, please update `punycode`.



```powershell

pip install -U punycode

```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Yutsuro/punycode",
    "name": "punycode",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "Punycode Converter Python",
    "author": "Yutsuro",
    "author_email": "Yuki@utsu.ro",
    "download_url": "https://files.pythonhosted.org/packages/46/77/767e6ac093cf1bc58af8756e83a7f0ada47fb05c07e246e91f600076e8b3/punycode-0.2.1.tar.gz",
    "platform": null,
    "description": "![punycode logo](https://raw.githubusercontent.com/Yutsuro/punycode/main/image/logo.png)\n\n\n\n**Punycode Converter Library for Python**\n\n\n\nYou can convert Punycode domain to/from Unicode domain with only one function: `punycode.convert()`.\n\n\n\n## How to use\n\n\n\n### Install\n\n\n\n```sh\n\npip install punycode\n\n```\n\n\n\n### Function\n\n\n\nThere is only one function `punycode.convert()`.\n\n\n\n* <b>input:</b>  \n\n`input_text: string`  \n\nInput can be both a Punycode domain and a Unicode domain.\n\n\n\n* <b>return:</b>  \n\n`output_text: string`  \n\nIf you input Punycode domain, the return will be a Unicode domian.  \n\nOn the other hand, if you input a Unicode domain, you will get a Punycode domain.\n\n\n\n### Code sample\n\n\n\n```python\n\nimport punycode\n\n\n\n# Convert Unicode domain to Punycode domain\n\nstr1 = \"\u7f8e\u3057\u3044.\u4e16\u754c\"\n\nstr2 = \"\u3053\u3063\u3061.\u307f\u3093\u306a\"\n\nstr3 = \"\u65e5\u672c\u8a9e.jp\"\n\nprint(f\"{str1} -> {punycode.convert(str1)}\")\n\nprint(f\"{str2} -> {punycode.convert(str2)}\")\n\nprint(f\"{str3} -> {punycode.convert(str3)}\")\n\n\n\n# \u50d5\u3060\u3051\u306e.\u4e16\u754c -> xn--08j3a5b142t.xn--rhqv96g\n\n# \u3053\u3063\u3061.\u307f\u3093\u306a -> xn--l8j9flb8a.xn--q9jyb4c\n\n# \u65e5\u672c\u8a9e.jp -> xn--wgv71a119e.jp\n\n\n\n# Punycode domain to Unicode domain\n\nstr4 = \"xn--n8jub8754b.xn--rhqv96g\"\n\nstr5 = \"xn--28j2af.xn--q9jyb4c\"\n\nstr6 = \"xn--wgv71a119e.jp\"\n\nprint(f\"{str4} -> {punycode.convert(str4)}\")\n\nprint(f\"{str5} -> {punycode.convert(str5)}\")\n\nprint(f\"{str6} -> {punycode.convert(str6)}\")\n\n\n\n# xn--n8jub8754b.xn--rhqv96g -> \u7f8e\u3057\u3044.\u4e16\u754c\n\n# xn--28j2af.xn--q9jyb4c -> \u3053\u3063\u3061.\u307f\u3093\u306a\n\n# xn--wgv71a119e.jp -> \u65e5\u672c\u8a9e.jp\n\n```\n\n\n\n## ascii_only option (v0.2.0 or later)\n\n\n\nIf you don't want to convert a Punycode domain to Unicode when you use `convert()` function, you can use `ascii_only` option. (Default: False)\n\n\n\nWith this option `True`, `convert()` will convert only Unicode domains.\n\n\n\n```python\n\n# ascii_only option (v0.2.0 or later)\n\nascii_only = True\n\n\n\n# Only Unicode domains will be converted if ascii_only=True\n\nprint(f\"{str4} -> {punycode.convert(str4, ascii_only)}\")\n\nprint(f\"{str5} -> {punycode.convert(str5, ascii_only)}\")\n\nprint(f\"{str6} -> {punycode.convert(str6, ascii_only)}\")\n\n\n\n# xn--n8jub8754b.xn--rhqv96g -> xn--n8jub8754b.xn--rhqv96g\n\n# xn--28j2af.xn--q9jyb4c -> xn--28j2af.xn--q9jyb4c\n\n# xn--wgv71a119e.jp -> xn--wgv71a119e.jp\n\n```\n\n\n\nThis option is available on 0.2.0 or later version, so if you use v0.1.0, please update `punycode`.\n\n\n\n```powershell\n\npip install -U punycode\n\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Punycode Converter Library for Python",
    "version": "0.2.1",
    "split_keywords": [
        "punycode",
        "converter",
        "python"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ff93c541a0b9e6838963c8b7bc3a2540bbe988cf56fe8b011ff2e1b3f255d988",
                "md5": "ed61b8816cec0793288ec0e83e982344",
                "sha256": "5c6c2c1fcfdcd50752fe4e68d402495d9ae2a71ac73915bc6af39cc7ccd99eb5"
            },
            "downloads": -1,
            "filename": "punycode-0.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ed61b8816cec0793288ec0e83e982344",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 4186,
            "upload_time": "2023-03-27T14:33:08",
            "upload_time_iso_8601": "2023-03-27T14:33:08.297934Z",
            "url": "https://files.pythonhosted.org/packages/ff/93/c541a0b9e6838963c8b7bc3a2540bbe988cf56fe8b011ff2e1b3f255d988/punycode-0.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4677767e6ac093cf1bc58af8756e83a7f0ada47fb05c07e246e91f600076e8b3",
                "md5": "69deb6e345951f757bb2e9bd9f376dbf",
                "sha256": "2619d4cc3d517f5b15f092d2e4108f37a44689514207f359ae6c5edf4fcc341d"
            },
            "downloads": -1,
            "filename": "punycode-0.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "69deb6e345951f757bb2e9bd9f376dbf",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 3892,
            "upload_time": "2023-03-27T14:33:10",
            "upload_time_iso_8601": "2023-03-27T14:33:10.069126Z",
            "url": "https://files.pythonhosted.org/packages/46/77/767e6ac093cf1bc58af8756e83a7f0ada47fb05c07e246e91f600076e8b3/punycode-0.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-03-27 14:33:10",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "Yutsuro",
    "github_project": "punycode",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "punycode"
}
        
Elapsed time: 0.06102s