netsa.data.countries — Country and Region Codes

Definitions of country and region names and codes as defined by ISO 3166-1 and the UN Statistics Division. The information in this module is current as of September 2015.

netsa.data.countries.get_area_numeric(code : int or str) → int

Given a country or region code as one of the following:

  • String containing ISO 3166-1 alpha-2 code
  • String containing ISO 3166-1 alpha-3 code
  • String or integer containing ISO 3166-1 numeric code
  • String containing DNS top-level domain alpha-2 code
  • String or integer containing UN Statistics Division numeric region code

Returns the appropriate ISO 3166-1 or UN Statistics Division numeric code as an integer.

Note that some regions and other special items that are not defined by ISO 3166-1 or the UN Statistics Division are encoded as ISO 3166-1 user-assigned code elements.

Raises KeyError if the code is unrecognized.

netsa.data.countries.get_area_name(code : int or str) → str

Given a country or region code as a string or integer, returns the name for the country or region.

Raises KeyError if the country or region code is unrecognized.

netsa.data.countries.get_area_tlds(code : int or str) → str list

Given a country or region code as a string or integer, returns a list of zero or more DNS top-level domains for that country or region.

Raises KeyError if the country or region code is unrecognized.

netsa.data.countries.get_country_numeric(code : int or str) → int

Given a country code as a string or integer, returns the ISO 3166-1 numeric code for the country.

Raises KeyError if the country code is unrecognized.

netsa.data.countries.get_country_name(code : int or str) → str

Given a country code as a string or integer, returns the name for the country.

Raises KeyError if the country code is unrecognized.

netsa.data.countries.get_country_alpha2(code : int or str) → str

Given a country code as a string or integer, returns the ISO 3166-1 alpha-2 code for the country, or None if that is not possible.

Raises KeyError if the country code is unrecognized.

netsa.data.countries.get_country_alpha3(code : int or str) → str

Given a country code as a string or integer, returns the ISO 3166-1 alpha-3 code for the country, or None if that is not possible.

Raises KeyError if the country code is unrecognized.

netsa.data.countries.get_country_tlds(code : int or str) → str list

Given a country code as a string or integer, returns a list of zero or more DNS top-level domains for that country.

Raises KeyError if the country code is unrecognized.

netsa.data.countries.iter_countries() → int iter

Returns an iterator which yields all known ISO 3166-1 numeric country codes as integers, including user-assigned code elements in use.

netsa.data.countries.get_region_numeric(code : int or str) → int

Given a UN Statistics Division region code as a string or integer, returns the code as an integer.

Raises KeyError if the region code is unrecognized.

netsa.data.countries.get_region_name(code : int or str) → str

Given a region code as a string or integer, returns the name for the region.

Raises KeyError if the region code is unrecognized.

netsa.data.countries.get_region_tlds(code : int or str) → str list

Given a region code as a string or integer, returns a list of zero or more DNS top-level domains for that region.

Raises KeyError if the region code is unrecognized.

netsa.data.countries.iter_regions() → int iter

Returns an iterator which yields all top-level UN Statistics Division numeric region codes as integers. This includes Africa, the Americas, Asia, Europe, Oceania, and Other.

netsa.data.countries.iter_region_subregions(code : int or str) → int iter

Given the code for a containing region, returns an iterator which yields all second-level UN Statistics Division numeric region codes as integers.

Raises KeyError if the region code is unrecognized.

netsa.data.countries.iter_region_countries(code : int or str) → int iter

Given the code for a containing region, returns an iterator which yields as integers all ISO 3166-1 numeric country codes that are part of that region.