Skip to main content

pycountry provides the ISO databases for the standards:

639

Languages

3166

Countries

3166-2

Subdivisions of countries (NOT IMPLEMENTED YET)

4217

Currencies

15924

Scripts

The databases are imported from Debian’s pkg-isocodes and made accessible through a Python API.

Translation files for the various strings are included as well.

Countries (ISO 3166)

Countries are accessible through a database object that is already configured upon import of pycountry and works as an iterable:

>>> import pycountry
>>> len(pycountry.countries)
246
>>> list(pycountry.countries)[0]
<pycountry.db.Country object at 0x...>

Specific countries can be looked up by their various codes and provide the information included in the standard as attributes:

>>> germany = pycountry.countries.get(alpha2='DE')
>>> germany
<pycountry.db.Country object at 0x...>
>>> germany.alpha2
'DE'
>>> germany.alpha3
'DEU'
>>> germany.numeric
'276'
>>> germany.name
'Germany'
>>> germany.official_name
'Federal Republic of Germany'

Note that historic countries, defined by the ISO 3166-3 sub-standard are not included in this list.

Scripts (ISO 15924)

Scripts are available from a database similar to the countries:

>>> len(pycountry.scripts)
131
>>> list(pycountry.scripts)[0]
<pycountry.db.Script object at 0x...>
>>> latin = pycountry.scripts.get(name='Latin')
>>> latin
<pycountry.db.Script object at 0x...>
>>> latin.alpha4
'Latn'
>>> latin.name
'Latin'
>>> latin.numeric
'215'

Currencies (ISO 4217)

The currencies database is, again, similar to the ones before:

>>> len(pycountry.currencies)
183
>>> list(pycountry.currencies)[0]
<pycountry.db.Currency object at 0x...>
>>> argentine_peso = pycountry.currencies.get(letter='ARS')
>>> argentine_peso
<pycountry.db.Currency object at 0x...>
>>> argentine_peso.letter
'ARS'
>>> argentine_peso.name
'Argentine Peso'
>>> argentine_peso.numeric
'032'

Languages (ISO 639)

The languages database is similar too:

>>> len(pycountry.languages)
486
>>> list(pycountry.languages)[0]
<pycountry.db.Language object at 0x...>
>>> aragonese = pycountry.languages.get(alpha2='an')
>>> aragonese.alpha2
'an'
>>> aragonese.bibliographic
'arg'
>>> aragonese.terminology
'arg'
>>> aragonese.name
'Aragonese'

Locales

Locales are available in the pycountry.LOCALES_DIR subdirectory of this package. The translation domains are called isoXXX according to the standard they provide translations for. The directory is structured in a way compatible to Python’s gettext module.

Here is an example translating language names:

>>> import gettext
>>> german = gettext.translation('iso3166', pycountry.LOCALES_DIR,
...                              languages=['de'])
>>> german.install()
>>> _('Germany')
'Deutschland'

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pycountry-0.9.tar.gz (2.7 MB view details)

Uploaded Source

File details

Details for the file pycountry-0.9.tar.gz.

File metadata

  • Download URL: pycountry-0.9.tar.gz
  • Upload date:
  • Size: 2.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pycountry-0.9.tar.gz
Algorithm Hash digest
SHA256 5dd01fe5432cab39c62f4841963879d00d8e61555db907bb86440f2953b67f4a
MD5 2d5540a49b37a658f990dc46039b5191
BLAKE2b-256 b72b9da73d76d549e84d09e7002efc759563db0ff6d7d03f2130e1a4be503f02

See more details on using hashes here.

Release history Release notifications | RSS feed

26.2.16

2 files

24.6.1

2 files

23.12.11

2 files

23.12.7

2 files

22.3.5

1 file

22.1.10

1 file

20.7.3

1 file

20.7.2

1 file

19.8.18

1 file

19.7.15

1 file

18.12.8

2 files

18.5.26

3 files

18.5.20

2 files

18.2.23

1 file

17.9.23

1 file

17.5.14

1 file

17.1.8

1 file

17.1.2

1 file

16.11.27.1

1 file

16.11.27

1 file

16.11.8

1 file

1.20

1 file

1.19

1 file

1.18

1 file

1.17

1 file

1.16

1 file

1.15

1 file

1.14

1 file

1.13

1 file

1.12

1 file

1.11

1 file

1.10

1 file

1.9

1 file

1.8

1 file

1.7

1 file

1.6

1 file

1.5

1 file

1.4

1 file

1.3

1 file

1.2

1 file

1.1

1 file

1.0

1 file

0.19

1 file

0.18

1 file

0.17

1 file

0.16

1 file

0.15

1 file

0.14.8

1 file

0.14.7

1 file

0.14.6

1 file

0.14.5

1 file

0.14.4

1 file

0.14.3

1 file

0.14.2

1 file

0.14.1

1 file

0.14

1 file

0.12.1

1 file

0.12

1 file

0.11

1 file

0.10

1 file

This release

0.9 This release

1 file

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