This is a wrapper for pycountry, to make said library more usable.
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pycountry_wrapper-1.0.1.tar.gz.
File metadata
- Download URL: pycountry_wrapper-1.0.1.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6111b5bc178099741da11f96f478999f76cd5fe068633e94e17b98537c9c5a23
|
|
| MD5 |
fd6586cd459f4fecd998b88d5ead9085
|
|
| BLAKE2b-256 |
b6e2e1d51bfc83de83e5738b1ffde8641d678ebca6001712ba2bfa8f81837169
|
Provenance
The following attestation bundles were made for pycountry_wrapper-1.0.1.tar.gz:
Publisher:
python-publish.yml on hazel-noack/pycountry-wrapper
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pycountry_wrapper-1.0.1.tar.gz -
Subject digest:
6111b5bc178099741da11f96f478999f76cd5fe068633e94e17b98537c9c5a23 - Sigstore transparency entry: 336315804
- Sigstore integration time:
-
Permalink:
hazel-noack/pycountry-wrapper@458f6b91d94c8b2cede1c7bbd3e218e5d04f8f97 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/hazel-noack
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@458f6b91d94c8b2cede1c7bbd3e218e5d04f8f97 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pycountry_wrapper-1.0.1-py3-none-any.whl.
File metadata
- Download URL: pycountry_wrapper-1.0.1-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
19d97af4c86c8d55a9eb43f8939e5aaf2d72c7cec9c607927e9a95a8233cc520
|
|
| MD5 |
99d3335e525ab703dd7d64ce68c09b31
|
|
| BLAKE2b-256 |
b6a1164f412d2d7176f922de6fbc5508f70132439220ab844c25ad3f6353a0eb
|
Provenance
The following attestation bundles were made for pycountry_wrapper-1.0.1-py3-none-any.whl:
Publisher:
python-publish.yml on hazel-noack/pycountry-wrapper
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pycountry_wrapper-1.0.1-py3-none-any.whl -
Subject digest:
19d97af4c86c8d55a9eb43f8939e5aaf2d72c7cec9c607927e9a95a8233cc520 - Sigstore transparency entry: 336315817
- Sigstore integration time:
-
Permalink:
hazel-noack/pycountry-wrapper@458f6b91d94c8b2cede1c7bbd3e218e5d04f8f97 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/hazel-noack
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@458f6b91d94c8b2cede1c7bbd3e218e5d04f8f97 -
Trigger Event:
push
-
Statement type: