countrynames
This library helps with the mapping of country names to their respective two or three letter codes. The idea is to incorporate common names for countries, and even some limited misspellings, as they occur in source data.
There is also support for fuzzy matching, which uses a heuristic based on levenshtein distance.
Usage
import countrynames
assert 'DE' == countrynames.to_code('Germany')
assert 'DE' == countrynames.to_code('Bundesrepublik Deutschland')
assert 'DE' == countrynames.to_code('Bundesrepublik Deutschlan', fuzzy=True)
assert 'DE' == countrynames.to_code('DE')
assert 'DEU' == countrynames.to_code_3('Germany')
Non-standard country codes
XKorXKX- KosovoEUorEUU- European Union
For some dissolved countries (e.g. SUHH for Soviet Union) and sub-regions
(e.g. GB-SCT for Scotland) special codes are defined and returned from both
to_code and to_code_3.
How to release
make test compile
git commit countrynames/data.py -m "update data.py"
bump2version --verbose patch
git push --tags && git push origin main
Release files for countrynames 1.17.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| countrynames-1.17.0-py3-none-any.whl | Python 3 | none | any | Details |
Release files / countrynames-1.17.0-py3-none-any.whl
| Download URL | countrynames-1.17.0-py3-none-any.whl |
|---|---|
| Size | 475.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1fbd01bb5024bd78bccc301251e8192812c2a66b5220cc391948d443d002cba7
|
|
BLAKE2b-256 checksum How to use checksums |
846585d5b33cc036d35e3010d7d76762bb5ed106647c328963a9e6d16743d239
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 13, 2026.
Transparency log