Skip to content

Country Object

The Country object is an enumeration (enum) of countries using ISO 3166-1 alpha-3 codes. It provides a type-safe way to work with country codes throughout the macro_data package and the broader model.

Features

  • Enum values are standard 3-letter ISO country codes (e.g., 'FRA', 'DEU').
  • Includes all recognized countries and a special ROW (Rest of World) designation.
  • Provides EU membership status via the is_eu_country property.
  • Utilities for converting between 2-letter and 3-letter codes.
  • String representation matches the country code or name.

Example Usage

from macro_data.configuration.countries import Country

# Create a country instance
france = Country.FRA

# Check if it's an EU country
is_eu = france.is_eu_country  # True

# Convert codes
two_letter = france.to_two_letter_code()  # 'FR'
three_letter = Country.convert_two_letter_to_three('FR')  # 'FRA'

API Reference

macro_data.configuration.countries.Country

Enumeration of countries using ISO 3166-1 alpha-3 codes.

This class provides a type-safe way to work with country codes in the model. It includes all recognized countries and a special ROW (Rest of World) designation. The enum values are the standard 3-letter ISO country codes.

Special features: - Includes EU membership status checking via is_eu_country property - Provides conversion between 2-letter and 3-letter codes - String representation matches the country code

Example
country = Country.FRANCE
print(country)  # 'FRA'
print(country.is_eu_country)  # True
print(country.to_two_letter_code())  # 'FR'
is_eu_country property

Check if the country is a member of the European Union.

Returns:

Name Type Description
bool

True if the country is an EU member, False otherwise

to_two_letter_code()

Convert the country's 3-letter code to its corresponding 2-letter code.

Returns:

Name Type Description
str

The ISO 3166-1 alpha-2 country code

Raises:

Type Description
KeyError

If the country code mapping is not found

convert_two_letter_to_three(two_letter_code: str) staticmethod

Convert a 2-letter country code to its corresponding 3-letter code.

Parameters:

Name Type Description Default
two_letter_code str

The ISO 3166-1 alpha-2 country code

required

Returns:

Name Type Description
str

The corresponding ISO 3166-1 alpha-3 country code

Raises:

Type Description
KeyError

If the country code mapping is not found