Country Engine
A fast and efficient Python library for converting between various country code formats and names.
Features
- 🚀 Fast: Built on Polars for high-performance data operations
- 🔄 Comprehensive: Supports 50+ country code formats including ISO codes, regional classifications, and localized names
- 🎯 Smart: Automatic format detection and fuzzy name matching
- 💾 Efficient: LRU caching for optimal performance
- 📦 Easy to use: Simple API with just one main function
Installation
pip install country-engine
Quick Start
from country_engine import convert, Formats
# Convert country codes
convert("USA", to=Formats.ISO2C) # Returns: "US"
convert("US", to=Formats.ISO3C) # Returns: "USA"
convert("840", to=Formats.ISO3C) # Returns: "USA"
# Convert country names
convert("United States", to=Formats.ISO2C) # Returns: "US"
convert("France", to=Formats.ISO3N) # Returns: "250"
# Explicit source format (faster)
convert("US", to=Formats.ISO3C, from_format=Formats.ISO2C) # Returns: "USA"
# Multiple language support
convert("Deutschland", to=Formats.ISO2C) # Returns: "DE"
convert("Japon", to=Formats.ISO3C) # Returns: "JPN"
Supported Formats
The library supports a wide range of country code formats:
ISO Standards
Formats.ISO2C- ISO 3166-1 alpha-2 (e.g., "US")Formats.ISO3C- ISO 3166-1 alpha-3 (e.g., "USA")Formats.ISO3N- ISO 3166-1 numeric (e.g., "840")
Country Names
Formats.Country.Name.EN- English namesFormats.Country.Name.FR- French namesFormats.Country.Name.DE- German namesFormats.Country.Name.IT- Italian names
Regional Classifications
Formats.CONTINENT- Continent namesFormats.REGION- UN regionsFormats.EU28- EU28 membership
International Organizations
Formats.UN- United Nations codesFormats.WB- World Bank codesFormats.IMF- International Monetary Fund codesFormats.FAO- Food and Agriculture Organization codes
And many more...
- CLDR localized names in 200+ languages/locales
- Currency codes (ISO 4217)
- Top-level domains
- IOC Olympic codes
- FIPS codes
- And 40+ additional formats
API Reference
convert(value, to, from_format=None)
Convert a country code or name to a specific target format.
Parameters:
value(str | int): The input country code or nameto(str): The target format identifier (fromFormatsclass)from_format(str, optional): Explicit format of the input. If None, the function attempts to infer it.
Returns:
str | None: The converted value as a string, or None if conversion failed
Example:
# Auto-detect input format
result = convert("USA", to=Formats.ISO2C)
# Specify input format for better performance
result = convert("USA", to=Formats.ISO2C, from_format=Formats.ISO3C)
Performance
Country Engine is designed for high performance:
- Lazy loading: Data files are only loaded when needed
- Caching: LRU caching for frequently used conversions
- Efficient data structures: Polars DataFrames for fast lookups
- Pre-built search index: Fast format inference
Development
Install for development
git clone https://github.com/EledoneAi/country-engine.git
cd country-engine
pip install -e .
Data Sources
The library uses data compiled from multiple authoritative sources:
- ISO 3166-1 standard
- Unicode CLDR project
- United Nations statistics
- World Bank data
- And other international organizations
The country data is sourced from pycountrycode by Vincent Arel-Bundock, which provides a comprehensive compilation of country codes and classifications.
License
MIT License - see LICENSE file for details
Acknowledgments
- Built with Polars for high-performance data operations
- Country data sourced from pycountrycode by Vincent Arel-Bundock
- Country data compiled from various international standards and organizations
Metadata
Release files for country-engine 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| country_engine-0.1.0.tar.gz | 1.8 MB | Without provenance | Details for country_engine-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| country_engine-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for country_engine-0.1.0-py3-none-any.whl |
Total release size: 3.5 MB
Release files / country_engine-0.1.0.tar.gz
| Download URL | country_engine-0.1.0.tar.gz |
|---|---|
| Size | 1.8 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1da59290b73524da0e3d07686c478b83b3ea899c1fa531b99626a23c3c263a4a
|
|
BLAKE2b-256 checksum How to use checksums |
a9e57a0c64475dc23c17dfa24b7f5e9c1e5fad74082a7741e3ae3831f8c8e03c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.0
|
Release files / country_engine-0.1.0-py3-none-any.whl
| Download URL | country_engine-0.1.0-py3-none-any.whl |
|---|---|
| Size | 1.7 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ddf3289c38acab34e15820020d22d56ce01bd16e08a18d45185d938361bfb626
|
|
BLAKE2b-256 checksum How to use checksums |
d9a4aea153537ecc1e36ba0b70c254fd9931dae58fa50d578fc555612aa6b2df
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.0
|
Security for country-engine 0.1.0
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.