Skip to main content

Country Regex Package

countre is a package with functions to get standardised names or codes from country names, as well as additional country information. Country names often differ between data sources, therefore having standardised codes for each country makes it easy to merge data from multiple sources.

The countries included are those defined by the International Organization for Standardization. The list can be found here. The sources of the country data can be found here.


Installation

countre can be installed via pip from PyPi:

pip install countre

Functions

countre.country_info(countries, attributes, no_match='no_match')

     Parameters:
          countries : iterable
              Country names, ISO 3166-1 alpha-2 codes, or ISO 3166-1 alpha-3 codes.
          variables : countre.enums.Attribute | list{countre.enums.Attribute}
              Specify either a single attribute or a list containing multiple attributes.
          no_match : str, default 'no match'
              String returned for a country if no match is found.
    Returns:
          A list of values if only one attribute is given. A dictionary if more than
          one variable is given. The dictionary keys are the attribute names and the
          values are lists of values.         

Note: The country_info function finds data via regex pattern matching for each unique country in the countries iterable and then returns the respective value for each element of countries. This means there is relatively little difference in performace between a list of unique countries and that same list repeated multiple times.


countre.member_countries(organisation, attribute=countre.enums.Attribute.COUNTRY)

     Parameters:
          organisation : countre.enums.Organisation
              Specify the organisation to get members of. Select from EU, EU_EEA, OECD, and OPEC.
          attrribute : countre.enums.Attribute
              To get member country names or ISO codes, specify COUNTRY, COUNTRY_SHORT, ISO2 or ISO3.
    Returns:
          List of either country names, ISO 3166-1 alpha-2 codes or ISO 3166-1 alpha-3
          codes for the members of the specified organisation.


Examples

>>> import countre
>>> from countre.enums import Attribute, Organisation
>>>
>>> countries = ['Australia', 'Germany', 'Sweden']
>>> attributes = [Attribute.ISO3, Attribute.CAPITAL, Attribute.CURRENCY_NAME]

Get a single attribute for a list of countries

>>> countre.country_info(countries=countries, attributes=Attribute.ISO3)

['AUS', 'DEU', 'SWE']

Get multiple attributes for a list of countries

>>> countre.country_info(countries=countries, attributes=attributes)

{
    'iso3': ['AUS', 'DEU', 'SWE'],
    'capital_city': ['Canberra', 'Berlin', 'Stockholm'],
    'currency_name': ['Australian dollar', 'Euro', 'Swedish krona']
}

When using multiple attributes, the output can easily be converted to a Pandas DataFrame

>>> import pandas as pd
>>> pd.DataFrame(countre.country_info(countries, attributes))

   iso3   country     capital_city
0  AUS    Australia   Canberra
1  DEU    Germany     Berlin
2  SWE    Sweden      Stockholm

Get organisation member countries. Not specifying an attribute will return the country names.

>>> countre.member_countries(Organisation.EU)

['Austria', 'Belgium', 'Bulgaria', 'Croatia', 'Cyprus', ...

Get organisation member countries with attribute specification

>>> countre.member_countries(Organisation.EU, Attribute.ISO3)

['AUT', 'BEL', 'BGR', 'HRV', 'CYP', ...

Metadata

Release files for countre 0.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for countre 0.0.5
File Size Uploaded
countre-0.0.5.tar.gz 3.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for countre 0.0.5
File Interpreter ABI Platform
countre-0.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 7.1 kB

Release files / countre-0.0.5.tar.gz

Download URL countre-0.0.5.tar.gz
Size 3.7 kB
Tags Source
SHA-256 checksum
How to use checksums
8685af51d74c7e5712825b3e21680959162a7253788484adb274abca4e947b23
BLAKE2b-256 checksum
How to use checksums
6a44a853edb982fa2d6ab347e86c4f4f7ab144674fb783c875df768d1e64ba46
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.4

Release files / countre-0.0.5-py3-none-any.whl

Download URL countre-0.0.5-py3-none-any.whl
Size 3.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d5efdc8de332e5f875f70cb8bf4fd5f45b4273226431bdb91d4715c39748ba6f
BLAKE2b-256 checksum
How to use checksums
9a562a24bd4ffd598238c9be0850f5bed69a984dd07adc985f4c2e8ef0da1b94
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.4

Release history Release notifications | RSS feed

This release

0.0.5 This release

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page