{"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":"python","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,"search_vec":"'2.4.1':16 'abbrevi':60 'activ':71 'aim':61 'appli':38 'articl':52 'bug':79 'built':33 'built-in':32 'case':27 'conjunct':53 'correct':24 'employ':57 'enhanc':83 'fix':80 'format':91 'function':28 'gruber':11 'handl':48 'heurist':58 'intellig':21 'john':10 'languag':94 'librari':4,68 'like':51 'maintain':69 'manipul':89 'manual':45 'method':36 'minor':82 'natur':93 'natural-language-process':92 'need':77 'new':42 'occur':75 'port':8 'preposit':55 'process':86,95 'provid':18 'public':64 'publication-readi':63 'python':7,30 'readi':65 'rule':39 'script':14 'small':49 'status':72 'str.title':35 'string':88 'string-manipul':87 'style':47 'stylist':23 'text':85 'text-process':84 'time':44 'titl':26,66 'title-cas':25 'titlecas':1,3,90 'titlecase.pl':13 'updat':74 'version':15 'word':50 'york':43","created_at":"2026-04-15T05:38:50.381323+00:00","updated_at":"2026-04-16T22:59:23.034564+00:00","problems":[{"fix":"pip install titlecase","cause":"The `titlecase` library has not been installed in the active Python environment.","error":"ModuleNotFoundError: No module named 'titlecase'"},{"fix":"import titlecase\ntitlecase.titlecase(\"your string here\")","cause":"The primary function for title-casing in the `titlecase` library is named `titlecase`, not `title`.","error":"AttributeError: module 'titlecase' has no attribute 'title'"},{"fix":"import titlecase\ntitlecase.titlecase(\"Your string here\")","cause":"The `titlecase.titlecase()` function requires the string to be processed as its first argument.","error":"TypeError: titlecase() missing 1 required positional argument: 'text'"},{"fix":"from titlecase import titlecase","cause":"The main title-casing function in the `titlecase` library is named `titlecase`, not `title`.","error":"ImportError: cannot import name 'title' from 'titlecase'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"2.4.1","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/ppannuto/python-titlecase","docs":null,"changelog":null,"pypi":"https://pypi.org/project/titlecase/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-28","install_tag":null}}