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.2.tar.gz (24.0 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.2-py3-none-any.whl (24.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: commondata_countries-2.2.2.tar.gz
  • Upload date:
  • Size: 24.0 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.2.tar.gz
Algorithm Hash digest
SHA256 cce6aeb9b32eee67ddbfafd8c2a3fe70a0a7c83e6031d0962a61957022c1054a
MD5 014ea3927b6fcdc08984db90cf47a487
BLAKE2b-256 4ee07efd84f4eca2c4e9838bedcde6b40f6372cbe1ab60a7035385689c4e6aa1

See more details on using hashes here.

Provenance

The following attestation bundles were made for commondata_countries-2.2.2.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.2-py3-none-any.whl.

File metadata

File hashes

Hashes for commondata_countries-2.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1f5c9452116e9656a795620a270f68ad9a89583ce048a951cef9030ae216469e
MD5 2af31e153f3a4bff9d3b4be4507412fd
BLAKE2b-256 b4433c8a9aa2376def3ee8034eaefc228a72cbf74b8f9fc82c494967c76f36ce

See more details on using hashes here.

Provenance

The following attestation bundles were made for commondata_countries-2.2.2-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