teritorio: ISO codes for countries and currencies
teritorio
two iterable singletons that Countries
and Currencies
, that contain all the
relevant ISO information about countries and currencies, respectively.
In a nutshell
Installation
The easiest way is to use poetry to manage your dependencies and add teritorio to them. It requires Python 3.7.0+ to run.
[tool.poetry.dependencies]
teritorio = "*"
It is advised to always use the latest release, so that you’ll get the latest ISO codes
Usage
There are two iterable singletons that can be imported from teritorio
: Countries
and Currencies
.
from teritorio import Countries
from teritorio import Currencies
Versioning
The project project adheres to Calendar Versioning. The reason is that the data are dominated by political decisions, making semantic versioning largely irrelevant.
Links
Installation
The easiest way is to use poetry to manage your dependencies and add teritorio to them.
[tool.poetry.dependencies]
teritorio = "*"
It is advised to always use the latest release, so that you’ll get the latest ISO codes
Usage
teritorio
has two iterable singletons: Countries
and Currencies
, and two dataclasses:
Country
and Currency
, that represent a specific country or currency. Countries
and Currencies
are importable from teritorio.
Countries
and Currencies
, as they are singletons, can be instantiated more than once with
negligible performance penalty.
Countries
- class teritorio.main.Countries
An iterable of all countries
- XYZ
The country with 3-letter code XYZ. The same country is accessible via square brackets Countries()[“XYZ”]
- class teritorio.main.Country
A representation of a specific country.
- english_name: str
The official name of the country in English
- french_name: str
The official name of the country in French
- alpha_2_code: str
The 2 letter code of the country
- alpha_3_code: str
The 3 letter code of the country
- numeric_code: int
The numeric code of the country
Example usage of the Countries
class.
from teritorio import Countries
# list all countries
for country in Countries():
print(country)
# get a specific country
countries = Countries()
# access the country as an attribute
print(countries.DEU) # Country(english_name='Germany', french_name="Allemagne (l')", alpha_2_code='DE', alpha_3_code='DEU', numeric_code=276)
# access the country with square brackets
print(countries["DEU"]) # Country(english_name='Germany', french_name="Allemagne (l')", alpha_2_code='DE', alpha_3_code='DEU', numeric_code=276)
Currencies
- class teritorio.main.Currencies
An iterable of all currencies
- XYZ
The currency with 3-letter code XYZ. The same currency is accessible via square brackets Currencies()[“XYZ”]
- class teritorio.main.Currency
A representation of a specific currency.
- code: str
The 3 letter code of the currency
- name: str
The name of the currency
- entities: tuple[str, ...]
The list of entities (countries) that use this currency
- numeric_code: int
The numeric code of the currency
- minor_units: int | None
The number of decimal digits of this currency, if applicable
Example usage of the Currencies
class.
from teritorio import Currencies
# list all currencies
for currency in Currencies():
print(currency)
# get a specific currency
currencies = Currencies()
# access the currency as an attribute
print(currencies.GBP) # Currency(code='GBP', name='Pound Sterling', entities=('GUERNSEY', 'ISLE OF MAN', 'JERSEY', 'UNITED KINGDOM OF GREAT BRITAIN AND NORTHERN IRELAND (THE)'), numeric_code=826, minor_units=2)
# access the currency with square brackets
print(currencies["GBP"]) # Currency(code='GBP', name='Pound Sterling', entities=('GUERNSEY', 'ISLE OF MAN', 'JERSEY', 'UNITED KINGDOM OF GREAT BRITAIN AND NORTHERN IRELAND (THE)'), numeric_code=826, minor_units=2)
Changelog
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Calendar Versioning.
Unreleased
2023.06.16
Added
Add a .pyi file to contain type hints for countries and currencies
2023.06.13
Changed
Change entities in currency from list to tuple
2023.04.28
Changed
Rename the Netherlands to Kingdom of the Netherlands
2023.02.01
Changed
Change Croatia’s currency to Euro
2022.10.10
Added
Add Leone currency
Changed
Change North Macedonia’s name
Change Turkiye’s name
Removed
Removed changelog from the published wheel
2022.01.05
Removed
Dropped python36 support
2021.10.22
Added
Added python310 support
Added VED
Changed
Changed versioning scheme to calendar versioning
1.1.0 - 2020-08-31
Added
Add support for python 3.6
1.0.1 - 2019-11-21
Fixed
Fixed some typos
1.0.0 - 2019-11-14
Added
Added currency ISO codes (ISO-4217)
Added country ISO codes (ISO-3166)