Skip to main content

From/to Classification Converter

Project description

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.

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

pyconvertu-1.1.0.tar.gz (18.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyconvertu-1.1.0-py3-none-any.whl (18.2 kB view details)

Uploaded Python 3

File details

Details for the file pyconvertu-1.1.0.tar.gz.

File metadata

  • Download URL: pyconvertu-1.1.0.tar.gz
  • Upload date:
  • Size: 18.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for pyconvertu-1.1.0.tar.gz
Algorithm Hash digest
SHA256 5f4fe43ea9bdbdedb860e60a42b31a0cc14d3158b069b25d6e4a286e54e2c096
MD5 2c1887cc8fd67447c31f7b449f05f29e
BLAKE2b-256 f824c2b23d7d7b1117f837e55b5dc8f39d749edb7f2e35bc28f0d22288eac801

See more details on using hashes here.

File details

Details for the file pyconvertu-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: pyconvertu-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 18.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for pyconvertu-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0720056d06a4cfc59ff80d8fd5933f848058b68fd339214db9bfb4fda0a40691
MD5 6eb5aa7da1722d51963282defef28ed1
BLAKE2b-256 fc6c5ef548c11b5aeb9a77385204694eae5e72ca95762ef909c71f54483f5cb7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page