countrydata

countrydata.interface

class countrydata.Country(*args, **kwargs)[source]

Represents a country and exposes his data. Their initialization is very flexible, allowing to construct it using any field of the data that refers to a country. This possibilities that any data field can be used as reference and this class acts as a country data factory.

Can be initialized explicitly by optional arguments (safer) or implicitly, delegating to the library the inference process of discover what field of the data you are using.

Implicitly, the class can be initalized defining a country value of any type of data as first positional argument. For example, let’s try to initialize the United States using ISO-3361-1 Alpha2 codes implicitly:

>>> country = Country("US")
>>> country.a3
'USA'
>>> country.num
840

Explicitly, the class can be initialized using one of the supported field names. This way is faster and safer. United States can be initialized by his ISO-3361-1 Numeric3 number:

>>> country = Country(num=840)
>>> country.a3
'USA'
property a2

Returns ISO-3361-1 Alpha2.

property a3

Returns ISO-3361-1 Alpha3.

property num

Returns ISO-3361-1 Numeric3.

property codes

Returns ISO-3361-1 Alpha2, ISO-3361-1 Alpha3 and ISO-3361-1 Numeric3.