Use pycountry.countries.lookup

>>> pycountry.countries.lookup('Bolivia')
Country(alpha_2='BO', alpha_3='BOL', common_name='Bolivia', name='Bolivia, Plurinational State of', numeric='068', official_name='Plurinational State of Bolivia')
Answer from pacholik on Stack Overflow
🌐
PyPI
pypi.org › project › pycountry
pycountry · PyPI
No changes to the data will be accepted into pycountry. This is a pure wrapper around the ISO standard using the pkg-isocodes database from Debian as is.
Help
The Python Package Index (PyPI) is a repository of software for the Python programming language.
Sponsors
The Python Package Index (PyPI) is a repository of software for the Python programming language.
Register
The Python Package Index (PyPI) is a repository of software for the Python programming language.
Log in
The Python Package Index (PyPI) is a repository of software for the Python programming language.
🌐
GitHub
github.com › pycountry
pycountry · GitHub
pycountry has one repository available. Follow their code on GitHub.
Discussions

python - Using pycountry to check for name/common_name/official_name - Stack Overflow
I have a dataframe where the column 'Country' contains names of countries that I'm trying to convert to the alpha_3 country code (in a new column labelled 'Code'). I'm using pycountry for this, but... More on stackoverflow.com
🌐 stackoverflow.com
How to convert country names to ISO 3166-1 alpha-2 values, using python - Stack Overflow
I've not used it thoroughly but it seems more coherent (in pycountry, some countries have both a name (e.g. "Italy") and an official_name (e.g. "Italian Republic"), but others only have a name which seems to correspond to the official name (e.g. More on stackoverflow.com
🌐 stackoverflow.com
isocodes: A python library that provides you access to lists of various ISO standards (e.g. country, language, language scripts, and currency names).
Isn't all of this already covered by pycountry? Worst case scenario use pycountry + py-moneyed. pycountries seems dead and data is outdated at this point What do you mean by this? Show me an example of outdated datapoints in pycountry. Pycountry is nothing more than a pretty wrapper around Debian's pkg-isocodes database, which is literally the same library you have linked. More on reddit.com
🌐 r/Python
4
13
December 13, 2021
The DRC in Pycountry
I'm not sure what you mean by "ISO-3". If you mean ISO 3166-1 alpha-3, then as shown here it is COD. More on reddit.com
🌐 r/learnpython
5
2
December 29, 2024
🌐
Medium
medium.com › @HeCanThink › pycountry-your-passport-to-iso-country-codes-names-and-more-2c39ef6668c0
PyCountry: Your Passport to ISO Country Codes, Names and More 🛂 | by Manoj Das | Medium
August 11, 2023 - PyCountry is a Python library that provides functionalities related to ISO country codes and other country-related data.
Top answer
1 of 4
4

Use pycountry.countries.lookup

>>> pycountry.countries.lookup('Bolivia')
Country(alpha_2='BO', alpha_3='BOL', common_name='Bolivia', name='Bolivia, Plurinational State of', numeric='068', official_name='Plurinational State of Bolivia')
2 of 4
1

This, albeit not being elegant at all, worked for me:

def country_code_converter(input_countries):
    """
    :param input_countries: list containing the name of the countries (can be numpy array)
    :return: list with the ISO alpha 3 codes for the given input ('Unknown Country' if no match found)
    """
    countries = {}
    countries_official = {}
    countries_common = {}

    #loops over all of the countries contained in the pycountry library and populates dictionary
    for country in pycountry.countries:
        countries[country.name] = country.alpha_3

    #loops over the alpha_3 codes from the countries dictionary
    #populates dictionary containing official names and codes
    for alpha_3 in list(countries.values()):
        try:
            countries_official[pycountry.countries.get(alpha_3 = alpha_3).official_name] = alpha_3
        except:
            None
    #same for common names
    for alpha_3 in list(countries.values()):
        try:
            countries_common[pycountry.countries.get(alpha_3 = alpha_3).common_name] = alpha_3
        except:
            None

    codes = []
    # appends ISO codes for all matches by trying different country name types
    # appends Unknown Country if no match found
    for i in input_countries:
        if i in countries.keys():
            codes.append(countries.get(i))

        elif i in countries_official.keys():
            codes.append(countries_official.get(i))

        elif i in countries_common.keys():
            codes.append(countries_common.get(i))

        else:
            codes.append('Unknown Country')
    return codes
🌐
GitHub
github.com › jefftune › pycountry-convert
GitHub - jefftune/pycountry-convert: Python conversion functions between ISO country codes, countries, and continents. · GitHub
Python conversion functions between ISO country codes, countries, and continents. - jefftune/pycountry-convert
Starred by 22 users
Forked by 28 users
Languages   Python 82.0% | Makefile 18.0%
🌐
Pycountry
pycountry.com
PyCountry – My WordPress Blog
Pycountry is a Python library that provides access to standardized ISO reference data for countries, subdivisions, languages, currencies, and scripts.
Find elsewhere
🌐
Parseltongue
parseltongue.co.in › exploring-countries-with-the-pycountry-module-in-python
ParselTongue - Exploring Countries with the pycountry Module in Python
September 1, 2023 - import pycountry country_name = "India" country = pycountry.countries.get(name=country_name) print(country)
🌐
GitHub
github.com › flyingcircusio › pycountry › blob › master › src › pycountry › __init__.py
pycountry/src/pycountry/__init__.py at main · pycountry/pycountry
A Python library to access ISO country, subdivision, language, currency and script definitions and their translations. - pycountry/pycountry
Author   pycountry
🌐
PyPI
pypi.org › project › pycountry-convert
pycountry-convert · PyPI
Extension of Python package pycountry providing conversion functions.
      » pip install pycountry-convert
    
Published   Feb 18, 2018
Version   0.7.2
🌐
Reddit
reddit.com › r/python › isocodes: a python library that provides you access to lists of various iso standards (e.g. country, language, language scripts, and currency names).
r/Python on Reddit: isocodes: A python library that provides you access to lists of various ISO standards (e.g. country, language, language scripts, and currency names).
December 13, 2021 -

Hi,

For a Django project, I wanted to get a list of all countries.
I went using pytz because I did not wanted to use django-countries but since now pytz is removed from Django, I had to find an alternative.

I quickly looked and found pycountries that not only provides countries but also languages and currencies which I also need in my project.

Problem, pycountries seems dead and data is outdated at this point.

So I decided to start a new library and isocodes is born.
The data is coming from https://salsa.debian.org/iso-codes-team/iso-codes, many thanks to them.
It has support for all the databases of iso-codes as well as the translations and a few methods to extract the data or sort it.

I would say that it's usable, please report any issue you would find !

Github: https://github.com/Atem18/isocodes

Pypi: https://pypi.org/project/isocodes/

🌐
GitLab
code.officialstatistics.org › rhui › pycountry › repository
Files · 83c38348a1e76f0a68c3a262c6fc0e8beda8b706 · rhui / pycountry · GitLab
A Python library to access ISO country, subdivision, language, currency and script definitions and their translations.
🌐
Reddit
reddit.com › r/learnpython › the drc in pycountry
r/learnpython on Reddit: The DRC in Pycountry
December 29, 2024 -

Hey, I am trying to change country names to ones that are recognised by pycountry so that I can get their ISO-3 codes, does anyone know what it is for the DRC (Democratic Republic of the Congo)?

Wikipedia says: 'Congo, Democratic Republic of the' but it is not working for me

Edit: its 'Congo, The Democratic Republic of the' if anyone cares

🌐
Anaconda.org
anaconda.org › conda-forge › pycountry
pycountry - conda-forge | Anaconda.org
Install pycountry with Anaconda.org. pycountry provides the ISO databases for the standards
🌐
Iiasa
docs.ece.iiasa.ac.at › standards › countries.html
A common list of country names — ece-docs documentation
The nomenclature package (read the docs) builds on the pycountry package to provide a standardized list of country names based on the ISO 3166-1 standard.
🌐
CloudDefense.ai
clouddefense.ai › code › python › example › pycountry
Top 10 Examples of <!-- -->pycountry<!-- --> code in Python | CloudDefense.AI
def __determine_iso_639_3_key(): """ Determine the key needed for accessing ISO 639-3 language codes using pycountry. """ # Different version of pycountry seem to use different keys.
🌐
GitHub
github.com › deepin-community › pycountry
GitHub - deepin-community/pycountry · GitHub
No changes to the data will be accepted into pycountry. This is a pure wrapper around the ISO standard using the pkg-isocodes database from Debian as is.
Author   deepin-community
🌐
RugbyPass
rugbypass.com › home › players › federico torre
Federico Torre Rugby Bio | News, Stats, Age, Height & Team | RugbyPass
Get Federico Torre stats, ratings, news, & video on the world's largest rugby player & team database. Click here to get the latest news on Federico Torre
🌐
RugbyPass
rugbypass.com › home › players › benjamin ordiz
Benjamin Ordiz Rugby Bio | News, Stats, Age, Height & Team | RugbyPass
Get Benjamin Ordiz stats, ratings, news, & video on the world's largest rugby player & team database. Click here to get the latest news on Benjamin Ordiz