pytils
raw JSON → 0.4.4 verified Fri May 01 auth: no python maintenance
Python library for Russian-specific string utilities, including numeral, date, and transliteration helpers. Current version 0.4.4 (released June 2021), with infrequent updates; considered in maintenance mode.
pip install pytils Common errors
error ModuleNotFoundError: No module named 'pytils.numeral' ↓
cause Trying to import pytils.numeral as a subpackage instead of module.
fix
Use 'from pytils import numeral'.
error AttributeError: module 'pytils' has no attribute 'numeral' ↓
cause Using 'import pytils' then accessing 'pytils.numeral' but the module is not imported.
fix
Use 'from pytils import numeral' explicitly.
Warnings
deprecated pytils.numeral.choose_plural is deprecated; use get_plural instead. ↓
fix Replace numeral.choose_plural(...) with numeral.get_plural(...).
gotcha Import paths are confusing: do NOT use pytils.numeral, pytils.dt, etc. as dotted subpackages. Import directly as 'from pytils import numeral'. ↓
fix Use 'from pytils import numeral' instead of 'import pytils.numeral'.
Imports
- numeral wrong
import pytils.numeralcorrectfrom pytils import numeral - dt wrong
import pytils.dtcorrectfrom pytils import dt - translit wrong
from pytils.translit import to_latincorrectfrom pytils import translit
Quickstart
from pytils import numeral, dt, translit
# Numeral: sum in words (Russian)
print(numeral.get_plural(21, "копейка", "копейки", "копеек")) # 21 копейка
# Date: distance of time in Russian
print(dt.distance_of_time_in_words(3600)) # около 1 часа
# Transliteration: Russian to Latin
print(translit.to_latin("Привет, мир!")) # Privet, mir!
# Transliteration: Latin to Russian
print(translit.to_cyrillic("Privet, mir!")) # Привет, мир!