titlecase


Nametitlecase JSON
Version 2.4.1 PyPI version JSON
download
home_pagehttps://github.com/ppannuto/python-titlecase
SummaryPython Port of John Gruber's titlecase.pl
upload_time2023-09-23 05:03:46
maintainerPat Pannuto
docs_urlNone
authorStuart Colville
requires_python>=3.7
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Titlecase
=========

.. image:: https://codecov.io/gh/ppannuto/python-titlecase/branch/main/graph/badge.svg?token=J1Li8uhB8q
    :target: https://codecov.io/gh/ppannuto/python-titlecase

This filter changes a given text to Title Caps, and attempts to be clever
about SMALL words like a/an/the in the input.
The list of "SMALL words" which are not capped comes from the New York
Times Manual of Style, plus some others like 'vs' and 'v'.

The filter employs some heuristics to guess abbreviations that don't need conversion.

+------------------+----------------+
| Original         | Conversion     |
+==================+================+
| this is a test   | This Is a Test |
+------------------+----------------+
| THIS IS A TEST   | This Is a Test |
+------------------+----------------+
| this is a TEST   | This Is a TEST |
+------------------+----------------+

More examples and expected behavior for corner cases are available in the
`package test suite <https://github.com/ppannuto/python-titlecase/blob/main/titlecase/tests.py>`__.

This library is a resurrection of `Stuart Colville's
titlecase.py <https://muffinresearch.co.uk/titlecasepy-titlecase-in-python/>`__,
which was in turn a port of `John Gruber's
titlecase.pl <http://daringfireball.net/2008/05/title_case>`__.

Issues, updates, pull requests, etc should be directed
`to github <https://github.com/ppannuto/python-titlecase>`__.


Installation
------------

The easiest method is to simply use pip:

::

    (sudo) pip install titlecase


Usage
-----

Titlecase provides only one function, simply:

.. code-block:: python

    >>> from titlecase import titlecase
    >>> titlecase('a thing')
    'A Thing'

A callback function may also be supplied, which will be called for every word:

.. code-block:: python

    >>> def abbreviations(word, **kwargs):
    ...   if word.upper() in ('TCP', 'UDP'):
    ...     return word.upper()
    ...
    >>> titlecase.titlecase('a simple tcp and udp wrapper', callback=abbreviations)
    'A Simple TCP and UDP Wrapper'

The callback function is supplied with an ``all_caps`` keyword argument, indicating
whether the entire line of text was entirely capitalized. Returning ``None`` from
the callback function will allow titlecase to process the word as normal.


Command Line Usage
------------------

Titlecase also provides a command line utility ``titlecase``:

::

    $ titlecase make me a title
    Make Me a Title
    $ echo "Can pipe and/or whatever else" | titlecase
    Can Pipe and/or Whatever Else
    # Or read/write files:
    $ titlecase -f infile -o outfile

In addition, commonly used acronyms can be kept in a local file
at `~/.titlecase.txt`. This file contains one acronym per line.
The acronym will be maintained in the title as it is provided.
Once there is e.g. one line saying `TCP`, then it will be automatically
used when used from the command line.

::

    $ titlecase I LOVE TCP
    I Love TCP


Limitations
-----------

This is a best-effort library that uses regexes to try to do intelligent
things, but will have limitations. For example, it does not have the contextual
awareness to distinguish acronyms from words: us (we) versus US (United States).

The regexes and titlecasing rules were written for American English. While
there is basic support for Unicode characters, such that something like
"El NiƱo" will work, it is likely that accents or non-English phrases will
not be handled correctly.

If anyone has concrete solutions to improve these or other shortcomings of the
library, pull requests are very welcome!

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ppannuto/python-titlecase",
    "name": "titlecase",
    "maintainer": "Pat Pannuto",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "pat.pannuto+titlecase@gmail.com",
    "keywords": "",
    "author": "Stuart Colville",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/63/17/04d2d3e30e2bc5a3eefa1060b08e3fb628510440f938eaecabbe08976a26/titlecase-2.4.1.tar.gz",
    "platform": null,
    "description": "Titlecase\n=========\n\n.. image:: https://codecov.io/gh/ppannuto/python-titlecase/branch/main/graph/badge.svg?token=J1Li8uhB8q\n    :target: https://codecov.io/gh/ppannuto/python-titlecase\n\nThis filter changes a given text to Title Caps, and attempts to be clever\nabout SMALL words like a/an/the in the input.\nThe list of \"SMALL words\" which are not capped comes from the New York\nTimes Manual of Style, plus some others like 'vs' and 'v'.\n\nThe filter employs some heuristics to guess abbreviations that don't need conversion.\n\n+------------------+----------------+\n| Original         | Conversion     |\n+==================+================+\n| this is a test   | This Is a Test |\n+------------------+----------------+\n| THIS IS A TEST   | This Is a Test |\n+------------------+----------------+\n| this is a TEST   | This Is a TEST |\n+------------------+----------------+\n\nMore examples and expected behavior for corner cases are available in the\n`package test suite <https://github.com/ppannuto/python-titlecase/blob/main/titlecase/tests.py>`__.\n\nThis library is a resurrection of `Stuart Colville's\ntitlecase.py <https://muffinresearch.co.uk/titlecasepy-titlecase-in-python/>`__,\nwhich was in turn a port of `John Gruber's\ntitlecase.pl <http://daringfireball.net/2008/05/title_case>`__.\n\nIssues, updates, pull requests, etc should be directed\n`to github <https://github.com/ppannuto/python-titlecase>`__.\n\n\nInstallation\n------------\n\nThe easiest method is to simply use pip:\n\n::\n\n    (sudo) pip install titlecase\n\n\nUsage\n-----\n\nTitlecase provides only one function, simply:\n\n.. code-block:: python\n\n    >>> from titlecase import titlecase\n    >>> titlecase('a thing')\n    'A Thing'\n\nA callback function may also be supplied, which will be called for every word:\n\n.. code-block:: python\n\n    >>> def abbreviations(word, **kwargs):\n    ...   if word.upper() in ('TCP', 'UDP'):\n    ...     return word.upper()\n    ...\n    >>> titlecase.titlecase('a simple tcp and udp wrapper', callback=abbreviations)\n    'A Simple TCP and UDP Wrapper'\n\nThe callback function is supplied with an ``all_caps`` keyword argument, indicating\nwhether the entire line of text was entirely capitalized. Returning ``None`` from\nthe callback function will allow titlecase to process the word as normal.\n\n\nCommand Line Usage\n------------------\n\nTitlecase also provides a command line utility ``titlecase``:\n\n::\n\n    $ titlecase make me a title\n    Make Me a Title\n    $ echo \"Can pipe and/or whatever else\" | titlecase\n    Can Pipe and/or Whatever Else\n    # Or read/write files:\n    $ titlecase -f infile -o outfile\n\nIn addition, commonly used acronyms can be kept in a local file\nat `~/.titlecase.txt`. This file contains one acronym per line.\nThe acronym will be maintained in the title as it is provided.\nOnce there is e.g. one line saying `TCP`, then it will be automatically\nused when used from the command line.\n\n::\n\n    $ titlecase I LOVE TCP\n    I Love TCP\n\n\nLimitations\n-----------\n\nThis is a best-effort library that uses regexes to try to do intelligent\nthings, but will have limitations. For example, it does not have the contextual\nawareness to distinguish acronyms from words: us (we) versus US (United States).\n\nThe regexes and titlecasing rules were written for American English. While\nthere is basic support for Unicode characters, such that something like\n\"El Ni\u00f1o\" will work, it is likely that accents or non-English phrases will\nnot be handled correctly.\n\nIf anyone has concrete solutions to improve these or other shortcomings of the\nlibrary, pull requests are very welcome!\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Python Port of John Gruber's titlecase.pl",
    "version": "2.4.1",
    "project_urls": {
        "Bug Tracker": "https://github.com/ppannuto/python-titlecase/issues",
        "Homepage": "https://github.com/ppannuto/python-titlecase",
        "PyPI": "https://pypi.org/project/titlecase/",
        "Source Code": "https://github.com/ppannuto/python-titlecase",
        "conda-forge": "https://anaconda.org/conda-forge/titlecase"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "631704d2d3e30e2bc5a3eefa1060b08e3fb628510440f938eaecabbe08976a26",
                "md5": "f7b8a85bdd22e06b8a3b1cdbc0e5ddfc",
                "sha256": "7d83a277ccbbda11a2944e78a63e5ccaf3d32f828c594312e4862f9a07f635f5"
            },
            "downloads": -1,
            "filename": "titlecase-2.4.1.tar.gz",
            "has_sig": false,
            "md5_digest": "f7b8a85bdd22e06b8a3b1cdbc0e5ddfc",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 14434,
            "upload_time": "2023-09-23T05:03:46",
            "upload_time_iso_8601": "2023-09-23T05:03:46.389332Z",
            "url": "https://files.pythonhosted.org/packages/63/17/04d2d3e30e2bc5a3eefa1060b08e3fb628510440f938eaecabbe08976a26/titlecase-2.4.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-23 05:03:46",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ppannuto",
    "github_project": "python-titlecase",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "titlecase"
}
        
Elapsed time: 0.11955s