Skip to main content

IANA-BCP47

iana-bcp47 validates language tags using the grammar from RFC 5646 and the bundled IANA Language Subtag Registry. Validation is local and does not require a network connection.

Features

  • Case-insensitive RFC 5646 syntax and ordering validation.
  • Registered language, extlang, script, region, and variant subtags.
  • Grandfathered and redundant tags.
  • Extensions and private-use tags, including IANA private-use ranges.
  • Deprecated subtags remain valid and include replacement guidance when IANA provides it.
  • Python 3.11 through 3.14.

Extension payloads are checked against the generic RFC 5646 grammar. This package does not interpret extension-specific standards such as Unicode locale extension semantics. Registry Prefix values are retained as metadata and guidance; RFC 5646 does not make them a validity requirement.

Installation

pip install iana-bcp47

Usage

from iana_bcp47 import validate_bcp47

for tag in ["en-US", "EN-us", "zh-Hant-CN", "i-klingon", "x-private"]:
    valid, message = validate_bcp47(tag)
    print(tag, valid, message)

validate_bcp47(tag) returns (valid, message). Invalid input returns False and an error message; passing a non-string raises TypeError. The wording of descriptions and errors may evolve as the IANA registry changes.

The legacy dictionaries remain available from iana_bcp47.bcp47 and from the package root:

from iana_bcp47 import language_codes, region_codes

Data maintenance

The packaged registry date can be read from iana_bcp47._registry.get_registry().file_date. A scheduled GitHub Actions workflow checks IANA every Monday. When the snapshot changes, it updates the data, increments the package patch version, runs validation, and opens or refreshes an automation/iana-registry pull request. A maintainer reviews and merges that PR; a successful main CI run then publishes the new version through PyPI Trusted Publishing.

To inspect an update locally without modifying files:

python -m pip install -e ".[dev]"
python tools/update_registry.py --dry-run

Run the maintenance checks with:

ruff check .
ruff format --check .
pytest
python -m build
twine check dist/*
check-wheel-contents dist/*.whl

License

MIT. See LICENSE.

Download files

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

Source Distribution

iana_bcp47-0.2.0.tar.gz (108.9 kB view details)

Uploaded Source

Built Distribution

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

iana_bcp47-0.2.0-py3-none-any.whl (112.3 kB view details)

Uploaded Python 3

File details

Details for the file iana_bcp47-0.2.0.tar.gz.

File metadata

  • Download URL: iana_bcp47-0.2.0.tar.gz
  • Upload date:
  • Size: 108.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for iana_bcp47-0.2.0.tar.gz
Algorithm Hash digest
SHA256 98765d71ce661dd70e0e7b21ecb1f89859e7187bdd9691a53c8b6b3ea585b409
MD5 735a1b43b01ef051d73ba4b42459a15c
BLAKE2b-256 f7e31d874db000ede4cc265f074b11d30a48ed18333991ca8693a5dddbe08451

See more details on using hashes here.

Provenance

The following attestation bundles were made for iana_bcp47-0.2.0.tar.gz:

Publisher: release.yml on Masterain98/IANA-BCP47

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file iana_bcp47-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: iana_bcp47-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 112.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for iana_bcp47-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 56e552fb9d696e1e5f3355da2d6b878dd885efdb2f79e6a90e007c943554c7d3
MD5 5ca4bf120bd44c4d344a0303d447c880
BLAKE2b-256 a45358218ebf0b184c010c54ca97ce08ab76470ac0e6eb8ff800f8b0b18d4082

See more details on using hashes here.

Provenance

The following attestation bundles were made for iana_bcp47-0.2.0-py3-none-any.whl:

Publisher: release.yml on Masterain98/IANA-BCP47

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 files

0.1.2

2 files

0.1.1

2 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