Skip to main content

pycountry-convert-ng logo

PyCountry Convert Next Generation v2026.9.0

Fast country, ISO code, and continent conversion utilities.

IntroductionWhy This Fork?Quick StartInstallationAPIDevelopment

PyPI CI Validate Release Metadata Deployment Version Increment

Introduction

pycountry-convert-ng is a lightweight Python package for converting between country names, ISO 3166-1 alpha-2 and alpha-3 country codes, and continents.

It is a maintained continuation of the original pycountry-convert project. The package keeps the familiar Python import name and public conversion API:

import pycountry_convert as pc

while the maintained distribution is published as:

pycountry-convert-ng

The goal is deliberately small: keep the original package fast and useful, while bringing its packaging, testing, Python support, CI, and release infrastructure up to date.

Why this fork?

The original pycountry-convert package is compact and efficient, and it provides a particularly useful capability that is surprisingly inconvenient to find in many alternatives: mapping ISO country codes to continents without requiring a large geospatial dependency stack.

This repository was initially forked from jefftune/pycountry-convert, but that repository contains older code and does not match the pycountry-convert package published on PyPI. PyPI identifies TuneLab/pycountry-convert as the repository for its 0.7.2 source code, but that repository is no longer available and currently returns a 404.

To recover the actual published code, the 0.7.2 source distribution was downloaded from PyPI and used to update this package. That published source now serves as the baseline for this maintained fork, with modern packaging, testing, Python support, CI, and release infrastructure added around it.

pycountry-convert-ng therefore focuses on:

  • continued maintenance for current Python versions
  • modern packaging through pyproject.toml and a src/ layout
  • automated testing on Python 3.11, 3.12, 3.13, and 3.14
  • automated releases through GitHub Actions and PyPI Trusted Publishing
  • minimal runtime overhead with static in-memory conversion tables
  • backward-compatible imports through pycountry_convert
  • preserving the original conversion behavior unless a change is explicitly reviewed and tested

The distribution name was changed to pycountry-convert-ng so that the maintained fork can be released independently without taking over or conflicting with the original PyPI project.

Quick Start

import pycountry_convert as pc

# ISO alpha-2 -> continent code
continent_code = pc.country_alpha2_to_continent_code("DE")
# "EU"

# Continent code -> continent name
pc.convert_continent_code_to_continent_name(continent_code)
# "Europe"

# ISO alpha-2 -> country name
pc.country_alpha2_to_country_name("DE")
# "Germany"

# ISO alpha-3 -> ISO alpha-2
pc.country_alpha3_to_country_alpha2("DEU")
# "DE"

# Country name -> ISO alpha-2 and alpha-3
pc.country_name_to_country_alpha2("Germany")
# "DE"

pc.country_name_to_country_alpha3("Germany")
# "DEU"

For an alpha-3 code, continent lookup can be composed directly from the public API:

alpha2 = pc.country_alpha3_to_country_alpha2("DEU")
continent_code = pc.country_alpha2_to_continent_code(alpha2)
continent = pc.convert_continent_code_to_continent_name(continent_code)

print(continent)
# Europe

Installation

Install the maintained package from PyPI:

> pip install pycountry-convert-ng

The import remains unchanged:

import pycountry_convert

You can also install directly from GitHub:

> pip install https://github.com/Haight3/pycountry-convert/archive/master.zip

To install an in-development branch, replace master with the desired branch name.

API

The public conversion functions are:

Function Conversion
convert_country_alpha2_to_continent() ISO alpha-2 -> continent
convert_country_alpha2_to_country_name() ISO alpha-2 -> country name
convert_country_alpha3_to_country_alpha2() ISO alpha-3 -> ISO alpha-2
convert_country_name_to_country_alpha2() country name -> ISO alpha-2

Unknown values retain the legacy behavior of the original implementation and may raise KeyError where applicable.

Package naming

The PyPI distribution and Python import intentionally have different names:

PyPI distribution:  pycountry-convert-ng
Python import:       pycountry_convert

This allows existing code to continue using the original import API while installing the maintained fork.

Project Structure

.
├── .github/
│   └── workflows/
├── resources/
│   ├── data/
│   ├── examples/
│   └── images/
├── src/
│   ├── .info/
│   └── pycountry_convert/
├── tests/
├── pyproject.toml
└── README.md

The conversion package itself lives under src/pycountry_convert/. Historical/supporting data and examples are kept under resources/.

Development

Install the project in editable mode with the development dependencies:

> pip install -e .[dev]

Run the test suite:

> pytest

Run the tests with coverage:

> pytest --cov=pycountry_convert --cov-report=term-missing

Run Ruff:

> ruff check src tests

Build and validate the distributions locally:

> python -m build
> python -m twine check dist/*

Pre-commit hooks can be installed with:

> pre-commit install

Release & PyPI

The project follows the same automated release model used by other Haight Python projects:

feature / development
        ↓
release-candidate
        ↓
automatic version increment + CI
        ↓
pull request to master
        ↓
release metadata validation + CI
        ↓
master
        ↓
build wheel + source distribution
        ↓
installation verification
        ↓
PyPI Trusted Publishing
        ↓
GitHub tag + GitHub Release

Versions use the calendar-based pattern:

YYYY.MM.PATCH

For example:

2026.9.0
2026.9.1
2026.9.2

Publishing to PyPI uses OpenID Connect through PyPI Trusted Publishing. No long-lived PyPI API token is stored in the repository.

Attribution

This repository is a fork of jefftune/pycountry-convert, originally developed by TUNE / TuneLab contributors.

The original copyright and attribution are preserved. The modernized fork is maintained by Haight Labs.

License

MIT. See LICENSE for the complete license and original attribution.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pycountry_convert_ng-2026.9.3.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

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

pycountry_convert_ng-2026.9.3-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

Details for the file pycountry_convert_ng-2026.9.3.tar.gz.

File metadata

  • Download URL: pycountry_convert_ng-2026.9.3.tar.gz
  • Upload date:
  • Size: 17.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pycountry_convert_ng-2026.9.3.tar.gz
Algorithm Hash digest
SHA256 bc3f08c929a47dbfc3017f1affa9bbebf993844a599e2ed63aae5fb6b0a8e6f1
MD5 69a851b7089aa006bea785088bcd6b0f
BLAKE2b-256 b49b7a81e8bbd706cc0d64b359cc62e893814880dc8747b77c1aace8888ef9dd

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycountry_convert_ng-2026.9.3.tar.gz:

Publisher: deploy.yml on Haight3/pycountry-convert

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

File details

Details for the file pycountry_convert_ng-2026.9.3-py3-none-any.whl.

File metadata

File hashes

Hashes for pycountry_convert_ng-2026.9.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c9b9c8b8ea0e6bcffad9b3dd7b4f94ea70c0510d43599996341af662f7a599d3
MD5 13912d032fe61e4aae4c62ee1a1e00b2
BLAKE2b-256 9e8fa1ab7a5f5d97ef2f4d0b8f884e93629f7f0a5aa47e26417f901bc151c3a2

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycountry_convert_ng-2026.9.3-py3-none-any.whl:

Publisher: deploy.yml on Haight3/pycountry-convert

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

Release history Release notifications | RSS feed

This release

2026.9.3 This release

2 files

2026.9.2

2 files

2026.9.0

2 files

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