Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

countrycodes

GitHub PyPI License CI

countrycodes is a dependency-free Python library for looking up all 249 ISO 3166-1 countries and territories, including a continent assignment for each.

Installation

pip install countrycodes

Requires Python 3.11 or newer.

Usage

from countrycodes import CountryNotFoundError, find_country, get_country, list_countries

united_states = get_country("us")
print(united_states.alpha3)  # USA
print(united_states.numeric)  # 840

united_kingdom = find_country("United Kingdom")
print(united_kingdom.alpha2)  # GB

print(len(list_countries()))  # 249

try:
    get_country("Atlantis")
except CountryNotFoundError:
    print("No matching country")

Lookups accept alpha-2, alpha-3, and numeric codes, as well as country names. Matching is case-insensitive and ignores surrounding or repeated whitespace. find_country returns None when there is no match; get_country raises CountryNotFoundError.

Data and licenses

The bundled country registry is an adapted subset of ISO 3166-1 data from the iso-codes project. Continent assignments are from GeoNames, using GeoNames' single-continent mapping for each country or territory. The registry data is licensed under LGPL-2.1-or-later, continent assignments under CC BY 4.0, and the library code under BSD 3-Clause. See the data notice, LGPL license text, and BSD license.

Metadata

Release files for countrycodes 0.1.0rc2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for countrycodes 0.1.0rc2
File Size Uploaded Provenance Actions
countrycodes-0.1.0rc2.tar.gz 21.4 kB Without provenance Details for countrycodes-0.1.0rc2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for countrycodes 0.1.0rc2
File Interpreter ABI Platform Actions
countrycodes-0.1.0rc2-py3-none-any.whl Python 3 none any Details for countrycodes-0.1.0rc2-py3-none-any.whl

Total release size: 43.7 kB

Release files / countrycodes-0.1.0rc2.tar.gz

Download URL countrycodes-0.1.0rc2.tar.gz
Size 21.4 kB
Tags Source
SHA-256 checksum
How to use checksums
9f6fea79ec6c9bde77979d3210c48be7d9da85b623a11f9d68b6951e902d7862
BLAKE2b-256 checksum
How to use checksums
44c18af89532787152d01a7ebadbb5df9dd11e46c477df2dc675ce06402c029f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / countrycodes-0.1.0rc2-py3-none-any.whl

Download URL countrycodes-0.1.0rc2-py3-none-any.whl
Size 22.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b61c97aab20fc9055672a964c1d8dc06d355cffb451ec8039fb91aff7a4dc315
BLAKE2b-256 checksum
How to use checksums
ef00f20eb919fee560204f88909712ba295b4e366d4a91c81c9ac9aee8e1c849
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for countrycodes 0.1.0rc2

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page