Skip to main content

iso639-lang

iso639-lang is a simple library to handle the ISO 639 series of international standards for language codes.

>>> from iso639 import Lang
>>> Lang("fr")
Lang(name='French', pt1='fr', pt2b='fre', pt2t='fra', pt3='fra', pt5='')

iso639-lang allows you to switch from one language code to another easily. There’s no need to manually download or parse data files, just use the Lang class!

ISO 639-1, ISO 639-2, ISO 639-3 and ISO 639-5 parts are all supported.

Installing iso639-lang and Supported Versions

iso639-lang is available on PyPI:

$ pip install iso639-lang

iso639-lang supports Python 3.6+.

Usage

Handling language codes with iso639-lang is very simple.

Begin by importing the Lang class:

>>> from iso639 import Lang

Lang is instantiable with any ISO 639 language code or name. For example, let’s try to get the ISO 639 codes for French:

>>> lg = Lang("French")
>>> lg.name
'French'
>>> lg.pt1
'fr'
>>> lg.pt2b
'fre'
>>> lg.pt2t
'fra'
>>> lg.pt3
'fra'
>>> lg.pt5
''

An instance of Lang can be modified.

>>> lg.pt1 = 'de'
>>> lg.name
'German'

Lang instances are comparable to each other.

>>> other_lg = Lang("deu")
>>> lg == other_lg
True

You can easily get the macrolanguage of an individual language.

>>> lg = Lang("Wu Chinese")
>>> lg.macro()
Lang(name='Chinese', pt1='zh', pt2b='chi', pt2t='zho', pt3='zho', pt5='')

Conversely, you can also list all the individual languages that share a common macrolanguage.

>>> lg = Lang("Persian")
>>> lg.individuals()
[Lang(name='Iranian Persian', pt1='', pt2b='', pt2t='', pt3='pes', pt5=''), 
Lang(name='Dari', pt1='', pt2b='', pt2t='', pt3='prs', pt5='')]

When an invalid argument is passed to Lang, an InvalidLanguageValue exception is raised.

>>> from iso639.exceptions import InvalidLanguageValue
>>> try:
...     Lang("foobar")
... except InvalidLanguageValue as e:
...     e.msg
... 
"'foobar' not supported by ISO 639"

When an deprecated argument is passed to Lang, a DeprecatedLanguageValue exception is raised.

>>> from iso639.exceptions import DeprecatedLanguageValue
>>> try:
...     Lang("gsc")
... except DeprecatedLanguageValue as e:
...     lg = Lang(e.change_to)
...     f"{e.name} replaced by {lg.name}"
...
'Gascon replaced by Occitan (post 1500)'

Data included in iso639-lang

iso639-lang is based on the official code tables provided by the ISO 639 registration authorities.

Standard Name Registration Authority First edition Current
ISO 639-1 Part 1: Alpha-2 code Infoterm 1967 2002
ISO 639-2 Part 2: Alpha-3 code Library of Congress 1998 1998
ISO 639-3 Part 3: Alpha-3 code for comprehensive coverage of languages SIL International 2007 2007
ISO 639-4 Part 4: Implementation guidelines and general principles for language coding (not a list) ISO/TC 37/SC 2 2010 2010
ISO 639-5 Part 5: Alpha-3 code for language families and groups Library of Congress 2008 2013
ISO 639-6 Part 6: Alpha-4 representation for comprehensive coverage of language variants Geolang 2009 withdrawn

Download files

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

Source Distribution

iso639-lang-0.3.0.tar.gz (92.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

iso639_lang-0.3.0-py3-none-any.whl (92.6 kB view details)

Uploaded Python 3

File details

Details for the file iso639-lang-0.3.0.tar.gz.

File metadata

  • Download URL: iso639-lang-0.3.0.tar.gz
  • Upload date:
  • Size: 92.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for iso639-lang-0.3.0.tar.gz
Algorithm Hash digest
SHA256 9830c252fdc2cdeb8104d606012320c1eb86d17c9ebcddea26059aeba5b11c5e
MD5 792d9f4a9f68a47cf6b8d7def3b4b81a
BLAKE2b-256 62e8cb894ea60da15d6425f79f6d6f096db05c335a08732f87351a14c001f1b5

See more details on using hashes here.

File details

Details for the file iso639_lang-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: iso639_lang-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 92.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for iso639_lang-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f98be3344831e17c6a358a31796e5ab3b4ec843a8e53859d3169e396365b8b4b
MD5 78e2c39128c22bd39d2a1288155dd8c1
BLAKE2b-256 a047ebd9f69d8ed07cabe59394e27bc0446d08d32e2736b2a3e7ceb81e9eb1b0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page