Skip to main content

CONVERTU - From/to Classification Converter

Tools for creating and converting between classification systems.

Installation

pip install pyconvertu

Quick example

python:

from convertu import cconv

print(cconv(to="iso3", text=["Czech Republic", "Slovakia"]))

bash:

cconv -t iso3 'Czech Republic' 'Slovakia'
echo -e "Czech Republic\nSlovakia" | cconv -t iso3

User Reference

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 file.

Metadata

Release files for pyconvertu 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyconvertu 1.1.0
File Size Uploaded
pyconvertu-1.1.0.tar.gz 18.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyconvertu 1.1.0
File Interpreter ABI Platform
pyconvertu-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 36.9 kB

Release files / pyconvertu-1.1.0.tar.gz

Download URL pyconvertu-1.1.0.tar.gz
Size 18.8 kB
Tags Source
SHA-256 checksum
How to use checksums
5f4fe43ea9bdbdedb860e60a42b31a0cc14d3158b069b25d6e4a286e54e2c096
BLAKE2b-256 checksum
How to use checksums
f824c2b23d7d7b1117f837e55b5dc8f39d749edb7f2e35bc28f0d22288eac801
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release files / pyconvertu-1.1.0-py3-none-any.whl

Download URL pyconvertu-1.1.0-py3-none-any.whl
Size 18.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0720056d06a4cfc59ff80d8fd5933f848058b68fd339214db9bfb4fda0a40691
BLAKE2b-256 checksum
How to use checksums
fc6c5ef548c11b5aeb9a77385204694eae5e72ca95762ef909c71f54483f5cb7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.4.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page