titlecase
Python Port of John Gruber's titlecase.pl
What it is and what it does
Titlecase is a text formatting library that converts strings to title case while intelligently preserving small words (a, an, the, and, or, etc.) in lowercase based on New York Times style conventions. It also attempts to detect and preserve acronyms and abbreviations that are already in all caps. The library provides both a Python API and a command-line tool, making it useful for one-off conversions or integration into larger text-processing pipelines.
The package has no runtime dependencies and supports Python 3.7, 3.8, 3.9, and 3.10. It uses regex-based heuristics to handle edge cases, though it acknowledges limitations with contextual awareness (e.g., distinguishing 'us' the pronoun from 'US' the country) and non-English text. The library is a modern port of John Gruber's original titlecase.pl Perl script, maintained on GitHub with a stable user base.
Use it for:
- Format user-generated titles or headlines in web applications before display or storage.
- Batch-process document titles or CSV headers from the command line using the titlecase utility.
- Normalize book, article, or product names in data pipelines while preserving common acronyms via callback functions.
- Convert all-caps or mixed-case text to consistent title formatting in content management systems.
- Implement custom capitalization rules for domain-specific acronyms by providing a callback function.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Converts text to title case with intelligent handling of small words (a, an, the) based on New York Times style rules, plus a command-line utility for batch processing.
Yes, if you need reliable title-case conversion with sensible English-language defaults and don't require frequent updates. The high install friction (source-only distribution) and aging maintenance status are acceptable trade-offs for a stable, single-purpose utility with no dependencies. Not recommended if you need active bug fixes or compatibility guarantees beyond Python 3.10.
Install
titlecase on PyPI
pip
pip install titlecaseuv
uv add titlecasepoetry
poetry add titlecaseInstalling titlecase
Before you install
High install friction due to source-only distribution (no wheels). The package is in aging maintenance status—last release was 2023-09-23, over a year ago—though the repository remains active and the code is marked Production/Stable. Suitable for stable, non-critical text processing tasks where you don't expect frequent updates.
License in practice
MIT license (permissive) means you can use, modify, and distribute this package freely in commercial and private projects with minimal restrictions, provided you include the license notice.
Quickstart
pip install titlecase
from titlecase import titlecase
result = titlecase('a thing')
print(result) # 'A Thing'
# With callback for custom handling:
def abbreviations(word, **kwargs):
if word.upper() in ('TCP', 'UDP'):
return word.upper()
result = titlecase('a simple tcp and udp wrapper', callback=abbreviations)
print(result) # 'A Simple TCP and UDP Wrapper'
Requires Python 3.7 or later. Source distribution only (no wheels), so installation requires a working C compiler and development headers if your environment lacks pre-built packages.
Verify before relying
- Whether the aging maintenance status poses a risk for Python 3.11+ compatibility or future standard library changes.
- Performance characteristics on very large texts or in high-throughput scenarios.
- Whether Unicode handling beyond basic accented characters (e.g., non-Latin scripts) is sufficient for your use case.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.7) |
| Install friction | high — source build required |
| Runtime dependencies | none |
| Maintenance | aging — 1,056 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 691,206/month — #5,326 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: titlecase-2.4.1.tar.gz
Tags
More Filters packages
Pygments is a syntax highlighter that colorizes…
permissive · top 100 on PyPI
MarkdownConverts Markdown text to HTML using a Python…
permissive · top 1,000 on PyPI
nltkNLTK is a Python library for natural language…
permissive · top 1,000 on PyPI
pandocfiltersProvides Python utilities for writing pandoc…
permissive · top 1,000 on PyPI
UnidecodeConverts Unicode text to ASCII-safe…
copyleft · top 1,000 on PyPI
pymdown-extensionsPymdown Extensions provides a collection of…
permissive · top 1,000 on PyPI
case-converterConverts strings between different naming…
permissive · top 15,000 on PyPI
case-conversionConverts strings between any case format…
permissive · top 15,000 on PyPI
reporters-dbProvides a comprehensive database of U.S. court…
permissive · top 15,000 on PyPI
english-wordsProvides curated sets of English words from…
permissive · top 15,000 on PyPI
indic-nlp-libraryIndic NLP Library provides text processing and…
permissive · top 15,000 on PyPI
redlinesRedlines compares two strings or text documents…
permissive · top 15,000 on PyPI
wordninjaSplits concatenated words into their…
unclear · top 5,000 on PyPI
pluralizerConverts English words between singular and…
permissive · top 15,000 on PyPI
textcaseConverts strings between different text case…
permissive · top 15,000 on PyPI
codespellCodespell finds and fixes common misspellings…
copyleft · top 5,000 on PyPI