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.0rc1

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

Built distribution (wheel)

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

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

Download URL countrycodes-0.1.0rc1-py3-none-any.whl
Size 22.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d383584777f85c099989ba4829e4fe72dd9bb705615a844b9ae389a76cf39860
BLAKE2b-256 checksum
How to use checksums
b0f0a1e97046c580be25eb051cba33fbc25cda39b5f322921b15e86ff404a434
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.0rc1

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