Skip to main content

Work with ISO 3166-1 alpha2, alpha3 and numeric standard country data

Project description

commondata-countries

PyPI - License PyPI - Python Version

Work with ISO 3166-1 alpha2, alpha3 and numeric standard country data.

List, lookup with fuzzy search, and synonyms.

Installation

pip install commondata-countries

Usage

Iterate over all countries:

from commondata_countries import CountryData

countries = CountryData()

for country in countries:
    print(country.name)

List all countries:

from commondata_countries import CountryData

countries = CountryData()

print(countries.all())

Lookup a country

from commondata_countries import CountryData

countries = CountryData()

# Lookup by name (case insensitive, fuzzy search)
country = countries["Untied States of America"]

# Lookup by ISO Alpha-2
country = countries["US"]

# Lookup by ISO Alpha-3
country = countries["USA"]

# Lookup by ISO Numeric
country = countries[840]

# Lookup by synonym
country = countries["United States"]

# Look up with fuzzy search
country = countries["United Stat"]

print(country)
> Country(name='United States of America', iso_alpha2='US', iso_alpha3='USA', iso_numeric=840)

Use CLI to lookup a country

python -m commondata-countries United States

Load countries data into pandas dataframe

import pandas as pd

from commondata_countries.data import countries

df = pd.DataFrame(countries)

Other Formats and Datasets

Download CSV, XLSX, JSON and YAML files from commondata.net/countries.

commondata.net maintains a collection of essential datasets in a variety of formats, including python bindings. Check out the full library here: commondata.net/library.

Contributing

Contributions are welcome! Please open an issue or submit a pull request here.

License

This project is licensed under GPLv3. See the LICENSE file for details.

Support

For feedback, feature requests, or support, please email support@commondata.net.

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

commondata_countries-2.2.0.tar.gz (23.5 kB view details)

Uploaded Source

Built Distribution

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

commondata_countries-2.2.0-py3-none-any.whl (23.8 kB view details)

Uploaded Python 3

File details

Details for the file commondata_countries-2.2.0.tar.gz.

File metadata

  • Download URL: commondata_countries-2.2.0.tar.gz
  • Upload date:
  • Size: 23.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for commondata_countries-2.2.0.tar.gz
Algorithm Hash digest
SHA256 c39d1718a933e5dcf2cd73b5fa6ea675ecd204404f87812abf58ae2a1046c553
MD5 be2d7b790a952ca98687be07c1ad2206
BLAKE2b-256 3c982b14e3f0b0acdad5351277bd98f2b1034cb0ce661b3be537fa7ceb200d4f

See more details on using hashes here.

Provenance

The following attestation bundles were made for commondata_countries-2.2.0.tar.gz:

Publisher: create-release.yaml on commondata-net/commondata-countries-python

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

File details

Details for the file commondata_countries-2.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for commondata_countries-2.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 76ba59036580084ba70df46e6e0a8a8cd984ade3558af67a50ec4c695431bf30
MD5 6579403f2785d575baffb4b0aed14cef
BLAKE2b-256 a1efc6d4b20055253588f8984919cbf6725cfbcf29b4bf31d2495dca6ec51a51

See more details on using hashes here.

Provenance

The following attestation bundles were made for commondata_countries-2.2.0-py3-none-any.whl:

Publisher: create-release.yaml on commondata-net/commondata-countries-python

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