Skip to main content

alifbo for Python

Python port of alifbo: Uzbek transliteration between Cyrillic, the previous Latin alphabet, and the Latin alphabet approved by Uzbekistan's Senate on 10 September 2026. The amending law still awaits the president's signature and is not yet in force.

The port has zero runtime dependencies, supports Python 3.9+, ships type hints (py.typed), and is tested against a fixture of more than 13,000 cases generated from the TypeScript build to produce identical output.

Install

pip install alifbo

Usage

from alifbo import fold_search_key, from_cyrillic, to_cyrillic, to_new_latin, to_old_latin

to_new_latin("O'zbekiston shaharlari")
# ConversionResult(text='Özbekiston şaharlari', warnings=())

to_old_latin("Özbekiston şaharlari").text
# 'Oʻzbekiston shaharlari'

result = from_cyrillic("Елена")
result.text
# 'Yelena'
result.warnings[0]
# Warning(index=0, length=1, rule='cyrillic.e.positional',
#         message='Cyrillic е can represent e or ye; a positional rule was applied.',
#         alternatives=('e', 'ye'))

to_cyrillic("Şavkat").text
# 'Шавкат'

fold_search_key("Шавкат") == fold_search_key("Shavkat")
# True

to_new_latin("MyShop shahar", protected_terms=["MyShop"]).text
# 'MyShop şahar'

API

Conversion functions return a frozen ConversionResult(text, warnings), where warnings is a tuple of frozen Warning(index, length, rule, message, alternatives) objects:

  • to_new_latin(text, **options): previous Latin to new Latin.
  • to_old_latin(text, **options): new Latin to previous Latin.
  • from_cyrillic(text, **options): Cyrillic to new Latin, with ambiguity warnings.
  • to_cyrillic(text, **options): new Latin to Cyrillic, with ambiguity warnings.

Their keyword-only options mirror the TypeScript ConversionOptions:

Python TypeScript Default
protect_spans protectSpans True
protected_terms protectedTerms None
exceptions exceptions None
ng_as_digraph ngAsDigraph True

The other functions take only text:

  • fold_search_key(text): canonical new-Latin, NFC, locale-independent lowercase key.
  • fold_search_key_loose(text): also strips diacritics. It can merge distinct words, so never use it as a unique key.
  • normalize_apostrophes(text): folds apostrophe-like characters to U+02BB after o/g and to U+02BC elsewhere.
  • normalize_confusables(text): NFC-normalizes text and folds known confusables such as U+0219 to U+015F.
  • detect_alphabet(text): returns AlphabetDetection(alphabet, confidence). alphabet is one of 'cyrillic', 'old-latin', 'new-latin', 'mixed', or 'unknown'.

Differences from the TypeScript package

  • Warning offsets are Python string indexes (code points). The TypeScript package reports UTF-16 code-unit offsets. The two are equal unless the text contains characters outside the Basic Multilingual Plane, such as emoji. For example, from_cyrillic("😀 Елена") reports warnings at indexes [2, 4] in Python and [3, 5] in JavaScript. Offsets point into the text you passed in, before NFC normalization, exceptions, or (for to_cyrillic) the old-to-new Latin pre-pass, just as they do in TypeScript.
  • Names are snake_case, options are keyword arguments, and results are immutable dataclasses with tuples instead of arrays.
  • An empty string used as an exceptions key is ignored. The TypeScript package can loop forever on one.
  • Unicode character properties come from the running Python's unicodedata module. Characters added in newer Unicode versions may be classified differently than they are by your JavaScript engine.

Casing never uses Python's built-in string case methods. It uses the same explicit Latin and Cyrillic tables as the TypeScript package, so the Turkish İ/ı problem cannot occur.

Rules

The conversion pipeline, apostrophe handling, the sʼh boundary, Cyrillic ambiguity rules, and the open ng question are documented in the main README.

Development

From the repository root:

npm ci && npm run build && node scripts/gen-python-parity.mjs
cd python
uv run --with pytest pytest
uv run --with ruff ruff check . && uv run --with ruff ruff format --check .

Released under the MIT License.

Download files

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

Source Distribution

alifbo-0.2.0.tar.gz (13.8 kB view details)

Uploaded Source

Built Distribution

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

alifbo-0.2.0-py3-none-any.whl (18.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for alifbo-0.2.0.tar.gz
Algorithm Hash digest
SHA256 34f0a9f77f72e1916c5de9518c103cdde6ca9fa27d9cee323d8330a1dae4ca34
MD5 64c473349d5ced2517f02a3177bb066e
BLAKE2b-256 be2cfe5dcda41243d773b509aea96da21afc2434ab922e4f3093df0d6f57e7a5

See more details on using hashes here.

Provenance

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

Publisher: publish.yml on azakapro/alifbo

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

File details

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

File metadata

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

File hashes

Hashes for alifbo-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d2264ac39837f66f09f31970dbc6c5d23d97e268a2044735a04c4e4f2f09065c
MD5 d64277e01dd244c3bca8f030a180983a
BLAKE2b-256 a7d6c0d94f80710c98b22ef8df12a584520718eee53e293f1053875036eb0b8a

See more details on using hashes here.

Provenance

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

Publisher: publish.yml on azakapro/alifbo

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

Release history Release notifications | RSS feed

0.3.0

2 files

This release

0.2.0 This release

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