Python port of typopo — a multilingual typography fixer by Braňo Šandala.
This library is a complete Python port of the JavaScript typopo library. It automatically fixes common typography issues in text, with support for multiple languages and their specific typographic conventions.
The original typopo is a battle-tested tool used for fixing typography in various content management systems and text editors. This Python port brings the same functionality to Python developers, following the original's behavior as closely as possible.
- Use typopo's easily in Python projects with zero runtime dependencies (pure Python + regex)
- Same reliable fixes as the original JavaScript version
- Wanted to try how Claude Code would handle such task.
I use this in a serious Python project but I'm really not sure if I will keep maintaing this.
Not on pypi yet (may change in future).
# Install from GitHub
pip install git+https://github.com/benabraham/pytypopo.git
# Or with uv
uv add git+https://github.com/benabraham/pytypopo.gitfrom pytypopo import fix_typos
# Basic usage (defaults to English)
text = fix_typos('Hello "world"...')
# → Hello "world"…
# With locale
text = fix_typos('Ahoj "svete"...', locale='cs')
# → Ahoj „svete"…
# German
text = fix_typos('Er sagte "Hallo"', locale='de-de')
# → Er sagte „Hallo"
# With options
text = fix_typos(
text,
locale='en-us',
remove_lines=True, # Remove excessive empty lines
keep_markdown_code_blocks=True # Protect code blocks from changes
)def fix_typos(
text: str,
locale: str = 'en-us',
*,
remove_lines: bool = True,
keep_markdown_code_blocks: bool = True
) -> str:
"""
Fix typography issues in text.
Args:
text: Input text to fix
locale: Language locale (en-us, de-de, cs, sk, rue)
remove_lines: Remove excessive empty lines
keep_markdown_code_blocks: Protect markdown code blocks from changes
Returns:
Text with typography fixes applied
"""# Clone and setup
git clone https://github.com/benabraham/pytypopo.git
cd pytypopo
uv sync --dev
uv run pre-commit install # Setup git hooks
# Run tests
uv run pytest
# Run with coverage
uv run pytest --cov=src/pytypopo
# Lint
uv run ruff check src tests
uv run ruff format src testsPRs are welcome. If you're thinking about contributing something more than a simple fix please open an issue first.
This project tracks the upstream library's version using semantic versioning and appends a Python-specific local build suffix.
The format is: MAJOR.MINOR.PATCH+pyN
Where:
2.8.2matches the upstream version for compatibility reference+py1is the local Python port patch/revision number- The local suffix never implies changes to the upstream version itself
This port aims to match the original typopo behavior exactly. Minor differences may exist in edge cases. If you find any discrepancies, please open an issue.
This project includes a cross-test suite that runs the original JavaScript tests against the Python port to verify parity. See cross-test/README.md for details.