Self-contained ISO 3166-1 country definitions.
Project Links
Meta
Author: Mike Spindel
Requires Python: >=3.6
Classifiers
Development Status
- 5 - Production/Stable
Intended Audience
- Developers
Natural Language
- English
Programming Language
- Python
- Python :: 3
- Python :: 3 :: Only
- Python :: 3.6
- Python :: 3.7
- Python :: 3.8
- Python :: 3.9
- Python :: 3.10
- Python :: 3.11
- Python :: 3.12
- Python :: 3.13
- Python :: 3.14
- Version:
- 3.0.0
ISO 3166-1 defines two-letter, three-letter, and three-digit country codes. python-iso3166 is a self-contained module that converts between these codes and the corresponding country name.
Installation
$ pip install iso3166
Usage
Country details
>>> from iso3166 import countries
>>>
>>> countries.get('us')
Country(name='United States', alpha2='US', alpha3='USA', numeric='840')
>>> countries.get('ala')
Country(name='Åland Islands', alpha2='AX', alpha3='ALA', numeric='248')
>>> countries.get(8)
Country(name='Albania', alpha2='AL', alpha3='ALB', numeric='008')
Country lists and indexes
>>> from iso3166 import countries
>>> for c in countries:
print(c)
>>> Country(name='Afghanistan', alpha2='AF', alpha3='AFG', numeric='004')
Country(name='Åland Islands', alpha2='AX', alpha3='ALA', numeric='248')
Country(name='Albania', alpha2='AL', alpha3='ALB', numeric='008')
Country(name='Algeria', alpha2='DZ', alpha3='DZA', numeric='012')
>>> import iso3166
>>> iso3166.countries_by_name
>>> {'AFGHANISTAN': Country(name='Afghanistan', alpha2='AF', alpha3='AFG', numeric='004'),
'ALBANIA': Country(name='Albania', alpha2='AL', alpha3='ALB', numeric='008'),
'ALGERIA': Country(name='Algeria', alpha2='DZ', alpha3='DZA', numeric='012'),
...
>>> iso3166.countries_by_numeric
>>> {'004': Country(name='Afghanistan', alpha2='AF', alpha3='AFG', numeric='004'),
'008': Country(name='Albania', alpha2='AL', alpha3='ALB', numeric='008'),
'010': Country(name='Antarctica', alpha2='AQ', alpha3='ATA', numeric='010'),
...
>>> iso3166.countries_by_alpha2
>>> {'AD': Country(name='Andorra', alpha2='AD', alpha3='AND', numeric='020'),
'AE': Country(name='United Arab Emirates', alpha2='AE', alpha3='ARE', numeric='784'),
'AF': Country(name='Afghanistan', alpha2='AF', alpha3='AFG', numeric='004'),
...
>>> iso3166.countries_by_alpha3
>>> {'ABW': Country(name='Aruba', alpha2='AW', alpha3='ABW', numeric='533'),
'AFG': Country(name='Afghanistan', alpha2='AF', alpha3='AFG', numeric='004'),
'AGO': Country(name='Angola', alpha2='AO', alpha3='AGO', numeric='024'),
...
3.0.0
Sep 03, 2026
2.1.1
Jul 12, 2022
2.1.0
Jul 12, 2022
2.0.2
Sep 20, 2021
2.0.1
Sep 15, 2021
2.0.0
Sep 15, 2021
1.0.1
Dec 13, 2019
1.0
Mar 19, 2019
0.9
Jul 21, 2018
0.8
Feb 05, 2017
0.7
Feb 13, 2015
0.6
Sep 29, 2014
0.5
Feb 13, 2014
0.4
Feb 14, 2013
0.3
Sep 04, 2012
0.2
Mar 26, 2012
0.1
Dec 14, 2010
Wheel compatibility matrix
Files in release
No dependencies