pyconvertu


Namepyconvertu JSON
Version 1.0.6 PyPI version JSON
download
home_pageNone
SummaryFrom/to Classification Converter
upload_time2025-08-26 10:53:25
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseNone
keywords data-science classification converter iso-3166-1 iso-3166-1-alpha-3 iso-3166-1-alpha-2 iso-3166-1-numeric
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # CONVERTU - From/to Classification Converter

Tools for creating and converting between classification systems.

## Installation

```bash
pip install pyconvertu
```

## Quick example
python:  
```python
from convertu import cconv

print(cconv(to="iso3", text=["Czech Republic", "Slovakia"]))
```
bash:  
```bash
cconv -t iso3 'Czech Republic' 'Slovakia'
echo -e "Czech Republic\nSlovakia" | cconv -t iso3
```

## User Reference

```python
cconv(
    data=[...], json_file='...', info=False, dump=False,
    to="...", text="..." | ["...", "..."], *args, **kwargs
)
```

Convert text into a target classification using a JSON mapping, or return mapping/metadata (info/dump modes).

**Parameters:**  

`data` : *list[dict]*, optional  
A complete classification mapping provided directly as a list of dictionaries. If supplied without `json_file`, this data will be used in-memory for conversions without reading from disk.

`json_file` : *str*, optional  
Path to the classification JSON file. If not provided, the default bundled `classification.json` is used. When `data` is not supplied, this file is loaded and used as the source mapping. When `data` is supplied along with `json_file`, the data is written to `json_file`.

`info` : *bool*, default = *False*  
If *True*, return only metadata/sources entries. No conversion.

`dump` : *bool*, default = *False*  
If *True*, return the full mapping (filtered of metadata/sources). No conversion.

`to` : *str*  
Target field name to return from matched records (e.g., "iso3").

`text` : *str* | *list[str]*  
One string or a list of strings to convert. A single string input yields a single string output; a list yields a list.

**Classification passed via `data`**

The JSON must follow the same structure as the bundled classification.json.

```
[
    {
        "regex":    "^(.*afgh.*|\\s*AFG\\s*|\\s*AF\\s*|\\s*4\\s*)$",
        "name_en":  "Afghanistan",
        "name_fr":  "Afghanistan (l')",
        "iso3":     "AFG",
        "iso2":     "AF",
        "isoN":     "4"
    },
    ...
    {
        "metadata": {
            "name_en": "English short name",
            "name_fr": "French short name",
            "iso3": "alpha-3 code",
            "iso2": "alpha-2 code",
            "isoN": "numeric"
        }
    },
    {
        "sources": [
            "[https://www.iso.org/iso-3166-country-codes.html](ISO 3166 COUNTRY CODES)",
            "[https://en.wikipedia.org/wiki/List_of_alternative_country_names](ALTERNATIVE NAMES)"
        ]
    }
]
```

## License

MIT License — see the [LICENSE](LICENSE) file.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pyconvertu",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "data-science, classification, converter, iso-3166-1, iso-3166-1-alpha-3, iso-3166-1-alpha-2, iso-3166-1-numeric",
    "author": null,
    "author_email": "The Economist <29724411+econcz@users.noreply.github.com>",
    "download_url": "https://files.pythonhosted.org/packages/9a/61/ced394c12be7d7c5aa164ed3e5c16476412dc28ffaed2eb6eca0708c0a4f/pyconvertu-1.0.6.tar.gz",
    "platform": null,
    "description": "# CONVERTU - From/to Classification Converter\n\nTools for creating and converting between classification systems.\n\n## Installation\n\n```bash\npip install pyconvertu\n```\n\n## Quick example\npython:  \n```python\nfrom convertu import cconv\n\nprint(cconv(to=\"iso3\", text=[\"Czech Republic\", \"Slovakia\"]))\n```\nbash:  \n```bash\ncconv -t iso3 'Czech Republic' 'Slovakia'\necho -e \"Czech Republic\\nSlovakia\" | cconv -t iso3\n```\n\n## User Reference\n\n```python\ncconv(\n    data=[...], json_file='...', info=False, dump=False,\n    to=\"...\", text=\"...\" | [\"...\", \"...\"], *args, **kwargs\n)\n```\n\nConvert text into a target classification using a JSON mapping, or return mapping/metadata (info/dump modes).\n\n**Parameters:**  \n\n`data` : *list[dict]*, optional  \nA complete classification mapping provided directly as a list of dictionaries. If supplied without `json_file`, this data will be used in-memory for conversions without reading from disk.\n\n`json_file` : *str*, optional  \nPath to the classification JSON file. If not provided, the default bundled `classification.json` is used. When `data` is not supplied, this file is loaded and used as the source mapping. When `data` is supplied along with `json_file`, the data is written to `json_file`.\n\n`info` : *bool*, default = *False*  \nIf *True*, return only metadata/sources entries. No conversion.\n\n`dump` : *bool*, default = *False*  \nIf *True*, return the full mapping (filtered of metadata/sources). No conversion.\n\n`to` : *str*  \nTarget field name to return from matched records (e.g., \"iso3\").\n\n`text` : *str* | *list[str]*  \nOne string or a list of strings to convert. A single string input yields a single string output; a list yields a list.\n\n**Classification passed via `data`**\n\nThe JSON must follow the same structure as the bundled classification.json.\n\n```\n[\n    {\n        \"regex\":    \"^(.*afgh.*|\\\\s*AFG\\\\s*|\\\\s*AF\\\\s*|\\\\s*4\\\\s*)$\",\n        \"name_en\":  \"Afghanistan\",\n        \"name_fr\":  \"Afghanistan (l')\",\n        \"iso3\":     \"AFG\",\n        \"iso2\":     \"AF\",\n        \"isoN\":     \"4\"\n    },\n    ...\n    {\n        \"metadata\": {\n            \"name_en\": \"English short name\",\n            \"name_fr\": \"French short name\",\n            \"iso3\": \"alpha-3 code\",\n            \"iso2\": \"alpha-2 code\",\n            \"isoN\": \"numeric\"\n        }\n    },\n    {\n        \"sources\": [\n            \"[https://www.iso.org/iso-3166-country-codes.html](ISO 3166 COUNTRY CODES)\",\n            \"[https://en.wikipedia.org/wiki/List_of_alternative_country_names](ALTERNATIVE NAMES)\"\n        ]\n    }\n]\n```\n\n## License\n\nMIT License \u2014 see the [LICENSE](LICENSE) file.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "From/to Classification Converter",
    "version": "1.0.6",
    "project_urls": {
        "Bug Tracker": "https://github.com/econcz/pyconvertu/issues",
        "Homepage": "https://github.com/econcz/pyconvertu"
    },
    "split_keywords": [
        "data-science",
        " classification",
        " converter",
        " iso-3166-1",
        " iso-3166-1-alpha-3",
        " iso-3166-1-alpha-2",
        " iso-3166-1-numeric"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "63f54ecd1f48a15e730e64d94baa89ebe3bd1537bc2633c057ae0870e68dd5d0",
                "md5": "747c7581e5b94f524e16788c918e04a9",
                "sha256": "b64558a2a6c8bc3d410dcefc7e99d0a4de245e72ca80d6e684d7ae492b196d78"
            },
            "downloads": -1,
            "filename": "pyconvertu-1.0.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "747c7581e5b94f524e16788c918e04a9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 17909,
            "upload_time": "2025-08-26T10:53:24",
            "upload_time_iso_8601": "2025-08-26T10:53:24.720042Z",
            "url": "https://files.pythonhosted.org/packages/63/f5/4ecd1f48a15e730e64d94baa89ebe3bd1537bc2633c057ae0870e68dd5d0/pyconvertu-1.0.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "9a61ced394c12be7d7c5aa164ed3e5c16476412dc28ffaed2eb6eca0708c0a4f",
                "md5": "3dd569b6de91fcd22d756c5dfb9220f5",
                "sha256": "39692f799571ab559dc48efbce86ae914e3a7652d8a69b2accc4646b0c1ef78f"
            },
            "downloads": -1,
            "filename": "pyconvertu-1.0.6.tar.gz",
            "has_sig": false,
            "md5_digest": "3dd569b6de91fcd22d756c5dfb9220f5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 18665,
            "upload_time": "2025-08-26T10:53:25",
            "upload_time_iso_8601": "2025-08-26T10:53:25.705732Z",
            "url": "https://files.pythonhosted.org/packages/9a/61/ced394c12be7d7c5aa164ed3e5c16476412dc28ffaed2eb6eca0708c0a4f/pyconvertu-1.0.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-26 10:53:25",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "econcz",
    "github_project": "pyconvertu",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pyconvertu"
}
        
Elapsed time: 0.47228s