{"id":6473,"library":"titlecase","title":"titlecase","description":"The `titlecase` library is a Python port of John Gruber's `titlecase.pl` script (version 2.4.1). It provides a more intelligent and stylistically correct title-casing function than Python's built-in `str.title()` method. It applies rules from the New York Times Manual of Style, handling 'small words' (like articles, conjunctions, and prepositions) and employing heuristics for abbreviations, aiming for publication-ready titles. The library maintains an active status with updates occurring as needed for bug fixes or minor enhancements.","status":"active","version":"2.4.1","language":"en","source_language":"en","source_url":"https://github.com/ppannuto/python-titlecase","tags":["text-processing","string-manipulation","titlecase","formatting","natural-language-processing"],"install":[{"cmd":"pip install titlecase","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"The primary functionality is exposed directly as the 'titlecase' function from the module.","wrong":"import titlecase","symbol":"titlecase","correct":"from titlecase import titlecase"}],"quickstart":{"code":"from titlecase import titlecase\n\n# Basic usage\ntext_input = \"the quick brown fox jumps over the lazy dog\"\ntitle_cased_text = titlecase(text_input)\nprint(f\"Original: '{text_input}'\")\nprint(f\"Title cased: '{title_cased_text}'\")\n\n# With a custom callback for abbreviations\ndef custom_abbreviations(word, **kwargs):\n    if word.upper() in ('TCP', 'UDP'):\n        return word.upper()\n    return None # Return None to let titlecase process normally\n\ntech_phrase = 'a simple tcp and udp wrapper'\nformatted_tech_phrase = titlecase(tech_phrase, callback=custom_abbreviations)\nprint(f\"Original (tech): '{tech_phrase}'\")\nprint(f\"Formatted (tech): '{formatted_tech_phrase}'\")","lang":"python","description":"Demonstrates basic title-casing and how to use a custom callback function to handle specific abbreviations or words that should not be automatically title-cased."},"warnings":[{"fix":"Always import and use the `titlecase` function from this library for grammatically correct title casing, especially for headlines and titles.","message":"Do not confuse with Python's built-in `str.title()` method. The built-in method capitalizes the first letter of *every* word, including small words (e.g., 'a', 'an', 'the', 'of') and incorrectly handles apostrophes (e.g., 'it's' becomes 'It'S'). The `titlecase` library is designed to address these common stylistic inaccuracies for proper title casing.","severity":"gotcha","affected_versions":"All versions"},{"fix":"For highly specific formatting needs, consider using the `callback` argument to define custom rules for particular words or abbreviations, or pre-process text that falls outside American English conventions.","message":"The library's title-casing rules are primarily based on American English (New York Times Manual of Style) and use regex heuristics. This means it might not perfectly handle complex linguistic nuances, non-standard abbreviations, or phrases in other languages or specific non-American English contexts.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z"}