Pycountry-Wrapper
This is a wrapper for pycountry, to make said library more usable.
Installation
You can install the library by using pip:
pip install pycountry-wrapper
Usage
from pycountry_wrapper import Country
germany = Country.from_alpha_2("DE")
print(germany)
print(germany.name)
try:
does_not_exist = Country.from_alpha_2("EN")
except ValueError:
# if the country wasn't found, a ValueError is raised
pass
Creating country class
You can call create an instance of Country in multiple slightly different ways.
The ISO 3166-1 standart can either use 2 or 3 letters (alpha_2 or alpha_3).
from pycountry_wrapper import Country
# auto detects if alpha_2 or alpha_3
Country("DE")
Country("DEU")
# you can specify what to use, if required.
Country.from_alpha_2("DE")
Country.from_alpha_3("DEU")
If the country can't be found it will raise a EmptyCountryException or use the fallback defined in config.fallback_country.
Alternatively you can get an instance of Country by using Country.search. This will return None if no country was found.
I also implemented a null-object pattern of Country, meaning you can get an EmptyCountry object. If you create a country from this object you'll get an instance of Country if it was found, and an instance of EmptyCountry if it wasn't.
empty = EmptyCountry("InvalidCountry")
print(type(empty)) # <class 'pycountry_wrapper.country.EmptyCountry'>
found = EmptyCountry("US")
print(type(found)) # <class 'pycountry_wrapper.country.Country'>
Accessing information
There are only a handful (readonly) attributes.
from pycountry_wrapper import Country
country = Country("DE")
country.name
country.alpha_2
country.alpha_3
country.official_name
If you have an EmptyCountry these attributes will all be None.
Configuring behavior
If you want to set a fallback country or disable fuzzy search you can do that with the config module.
from pycountry_wrapper import config
config.fallback_country = "US"
config.allow_fuzzy_search = False
Metadata
Release files for pycountry-wrapper 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pycountry_wrapper-1.0.1.tar.gz | 5.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pycountry_wrapper-1.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.9 kB
Release files / pycountry_wrapper-1.0.1.tar.gz
| Download URL | pycountry_wrapper-1.0.1.tar.gz |
|---|---|
| Size | 5.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6111b5bc178099741da11f96f478999f76cd5fe068633e94e17b98537c9c5a23
|
|
BLAKE2b-256 checksum How to use checksums |
b6e2e1d51bfc83de83e5738b1ffde8641d678ebca6001712ba2bfa8f81837169
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 31, 2025.
Transparency logRelease files / pycountry_wrapper-1.0.1-py3-none-any.whl
| Download URL | pycountry_wrapper-1.0.1-py3-none-any.whl |
|---|---|
| Size | 6.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
19d97af4c86c8d55a9eb43f8939e5aaf2d72c7cec9c607927e9a95a8233cc520
|
|
BLAKE2b-256 checksum How to use checksums |
b6a1164f412d2d7176f922de6fbc5508f70132439220ab844c25ad3f6353a0eb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 31, 2025.
Transparency log