Skip to main content

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

Project description

commondata-countries

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/library.

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.1.5.tar.gz (23.4 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.1.5-py3-none-any.whl (23.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: commondata_countries-2.1.5.tar.gz
  • Upload date:
  • Size: 23.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.13.2 Darwin/24.3.0

File hashes

Hashes for commondata_countries-2.1.5.tar.gz
Algorithm Hash digest
SHA256 edff6642ac44d01e03bb64439767550c07fddcf6327f3ad63dc334f5ac74f782
MD5 a4a3e93342a47abcebc59c19eeefb2b4
BLAKE2b-256 c47167960bc653b652741d7e360bcd232f1082e6834e8299da24919f347e0bd2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for commondata_countries-2.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 1ae87a54f93b1c67cb5cfbc0b8e1c65cf02937a91ff0357511c638ab37b4dc7d
MD5 56d95ece80ce639a1520bd89ba3ad7f2
BLAKE2b-256 cceb96393e699fb0897a0f18a4fe5a8d6d85e89fd3140e2a0c76e5a92c714ba5

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