This is a wrapper for pycountry, to make said library more usable.
Go to file
2024-11-29 16:52:35 +01:00
.vscode added release script 2024-11-19 14:55:37 +01:00
pycountry_wrapper feat: added better typing 2024-11-29 16:52:35 +01:00
.gitignore Initial commit 2024-11-19 13:09:03 +00:00
LICENSE Initial commit 2024-11-19 13:09:03 +00:00
pyproject.toml initial commit 2024-11-19 14:51:55 +01:00
README.md started to use a simple value error 2024-11-20 12:34:04 +01:00
release autocommit bump 2024-11-19 15:08:16 +01:00

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 pycountry_wrapper.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 you want to use fuzzy search, you will have to use Country.from_fuzzy().

from pycountry_wrapper import Country

Country.from_fuzzy("Deutschland")

Accessing information

There are only a handful (readonly) attributes.

from pycountry_wrapper import Country

country = Country.from_alpha_2("DE")

country.name
country.alpha_2
country.alpha_3
country.official_name