Skip to main content

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 fork of the original jefftune/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.

However, the upstream repository has seen no pushes since April 2023 and still reflects an older Python packaging and CI ecosystem. This fork exists to keep that functionality usable in modern projects without unnecessarily rewriting the core conversion logic.

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
pc.convert_country_alpha2_to_continent("DE")
# "Europe"

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

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

# Country name -> ISO alpha-2
pc.convert_country_name_to_country_alpha2("Germany")
# "DE"

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

alpha2 = pc.convert_country_alpha3_to_country_alpha2("DEU")
continent = pc.convert_country_alpha2_to_continent(alpha2)

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.0.tar.gz (16.1 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.0-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pycountry_convert_ng-2026.9.0.tar.gz
  • Upload date:
  • Size: 16.1 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.0.tar.gz
Algorithm Hash digest
SHA256 92962e2b973e67ce9ba521f85b595596b6afa8a44e7128c76cb9699531bd8bf1
MD5 b7701ef2d70029dbf7c3ec3658de99e9
BLAKE2b-256 6eb64ca8a64313e9ccb69af63498c31a90daa45eb2ff4bba8eb447d6c2470581

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycountry_convert_ng-2026.9.0.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.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pycountry_convert_ng-2026.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0b44662306fdd36ef4a1724618757bac326d8228502ae49381a62d4d22d16780
MD5 ad15617fb410b99399a6435bab9c6982
BLAKE2b-256 50bc6fb34d0f09f24863a032b47156b72c236f40393f7954c613568b9cb8fa46

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycountry_convert_ng-2026.9.0-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

2026.9.3

2 files

2026.9.2

2 files

This release

2026.9.0 This release

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