Skip to main content

A library to map country names to 2-letter ISO codes.

Project description

countrynames

build

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

  • XK or XKX - Kosovo
  • EU or EUU - 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

countrynames-1.17.0-py3-none-any.whl (475.0 kB view details)

Uploaded Python 3

File details

Details for the file countrynames-1.17.0-py3-none-any.whl.

File metadata

  • Download URL: countrynames-1.17.0-py3-none-any.whl
  • Upload date:
  • Size: 475.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for countrynames-1.17.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1fbd01bb5024bd78bccc301251e8192812c2a66b5220cc391948d443d002cba7
MD5 105bbcbab73913d931f1f1ed67466a6e
BLAKE2b-256 846585d5b33cc036d35e3010d7d76762bb5ed106647c328963a9e6d16743d239

See more details on using hashes here.

Provenance

The following attestation bundles were made for countrynames-1.17.0-py3-none-any.whl:

Publisher: build.yml on opensanctions/countrynames

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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