Skip to main content

Country Input Component

The Country class is a special type of string object. It behaves and evaluates like a string, but is extended with input validators and output formatters. Use this class for functions with a 'country' parameter, or to convert two and three-letter country codes, display labels, and names. All countries are spelled with English letters and exclude UTF characters such as umlauts.

Import

from openbb_core.provider.utils.country_utils import Country

Usage

The __repr__ of class instance will be the 2-letter country code.

>>> Country("United States")
'US'
>>> Country("gb").name
'United Kingdom'
>>> Country("hk").alpha_3
'HKG'
>>> Country("United States") == 'US'
True
>>> c = Country("united_states")
>>> isinstance(c, str)
True
>>> c.alpha_2
'US'
>>> c.alpha_3
'USA'
>>> c.name
'United States'
>>> c.groups
['G7', 'G20', 'NATO', 'OECD']
>>> c.is_member_of("G7")
True

Properties

  • alpha_2 : str - ISO 3166-1 alpha-2 code.
  • alpha_3 : str - ISO 3166-1 alpha-3 code.
  • name : str - The country's display name, in English.
  • numeric: str - ISO 3166-1 numeric code.
  • groups: list[str] - List of membership groups the country belongs to.

Methods

  • is_member_of(self, group: str) -> bool: Check if a country is a member of a specific group.

Updating Definitions

If the definitions have become stale, you can refresh them in the environment with the update script.

pip install pycountry
python -m openbb_core.provider.utils.update_country_data

Sources