tstr


Nametstr JSON
Version 0.3.0 PyPI version JSON
download
home_pageNone
SummaryTemplate string utilities and backports
upload_time2025-09-01 12:19:59
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseNone
keywords backport pep 750 pep-750 pep750 string t-string template template string tstring utility
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # tstr - PEP 750 Template String Utilities & Backports

[![PyPI Version](https://img.shields.io/pypi/v/tstr)](https://pypi.org/project/tstr/)
[![Python Version](https://img.shields.io/pypi/pyversions/tstr)](https://pypi.org/project/tstr/)
[![License](https://img.shields.io/github/license/ilotoki0804/tstr)](https://github.com/ilotoki0804/tstr/blob/master/LICENSE)
[![Tests](https://github.com/ilotoki0804/tstr/workflows/testing/badge.svg)](https://github.com/ilotoki0804/tstr/actions)
[![Coverage Status](https://coveralls.io/repos/github/ilotoki0804/tstr/badge.svg?branch=main)](https://coveralls.io/github/ilotoki0804/tstr?branch=main)

`tstr` provides utilities for working with [PEP 750 template strings](https://peps.python.org/pep-0750/), along with robust backports for older Python versions.

This library streamlines template string usage by offering practical helpers and common processing patterns. For Python versions prior to 3.14, `tstr` seamlessly backports template string functionality.

## Installation

Install `tstr` via pip:

```bash
pip install tstr
```

## Features

- `render` (alias: `f`): Render a template to a string, mimicking f-string behavior.
- `generate_template` (alias: `t`): Create a Template object from a string and context.
    This function is especially useful on Python versions that do not support template strings natively.
- `bind`: Apply a function to all interpolations and join all the parts.
- `binder`: Decorator to create template processors from an interpolation processor.
- `normalize` / `normalize_str`: Apply conversion and format to value.
- `convert`: Apply conversion to a value.
- `template_eq`: Check if two templates are equivalent.
- `interpolation_replace`: Create a new `Interpolation` by selectively replacing attributes of an existing one.
- `dedent`: `textwrap.dedent` for template strings
- `template_from_parts`: Construct template strings from iterable

This library also provides several useful extensions where template strings can be effectively utilized.
These extensions are available in the `tstr.ext` submodule, and below is a list with brief descriptions:

- `ext._html`: Render templates with HTML escaping.
- `ext._sqlite`: Safely execute SQL with templates, preventing SQL injection attacks.
- `ext._logging`: Enable Python's logging module to accept template strings.

For more details, see the [API documentation](/docs/api.md).

## Compatibility

`tstr` automatically detects native template string support (PEP 750):

- Python 3.14+: Uses native template strings.
- Python 3.10–3.13: Uses a compatible backport.

Use the `TEMPLATE_STRING_SUPPORTED` constant to check if template strings are natively supported in your Python version.

For details on how the compatible backport of template string works and what similarities and differences it has with native template strings, see the [compatible template strings](/docs/compat.md) documentation.

# Contributing

This project welcomes contributions of all kinds from anyone willing to help improve it! Whether you're fixing a typo in documentation, reporting a bug, proposing a new feature, or implementing code changes - every contribution matters and is highly appreciated.

## Releases

* 0.3.0: Revamp various things
* 0.2.0: Rename html_render to render_html, add `_logging` module, fix various bugs and improve documentation
* 0.1.1.post1: Initial release

## License

This library is licensed under the Apache License 2.0.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "tstr",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "backport, pep 750, pep-750, pep750, string, t-string, template, template string, tstring, utility",
    "author": null,
    "author_email": "ilotoki0804 <ilotoki0804@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/63/75/2a4e4ee31cd5eef6415b33df2a6d06bc1f5818e335ab924555a42941f120/tstr-0.3.0.tar.gz",
    "platform": null,
    "description": "# tstr - PEP 750 Template String Utilities & Backports\n\n[![PyPI Version](https://img.shields.io/pypi/v/tstr)](https://pypi.org/project/tstr/)\n[![Python Version](https://img.shields.io/pypi/pyversions/tstr)](https://pypi.org/project/tstr/)\n[![License](https://img.shields.io/github/license/ilotoki0804/tstr)](https://github.com/ilotoki0804/tstr/blob/master/LICENSE)\n[![Tests](https://github.com/ilotoki0804/tstr/workflows/testing/badge.svg)](https://github.com/ilotoki0804/tstr/actions)\n[![Coverage Status](https://coveralls.io/repos/github/ilotoki0804/tstr/badge.svg?branch=main)](https://coveralls.io/github/ilotoki0804/tstr?branch=main)\n\n`tstr` provides utilities for working with [PEP 750 template strings](https://peps.python.org/pep-0750/), along with robust backports for older Python versions.\n\nThis library streamlines template string usage by offering practical helpers and common processing patterns. For Python versions prior to 3.14, `tstr` seamlessly backports template string functionality.\n\n## Installation\n\nInstall `tstr` via pip:\n\n```bash\npip install tstr\n```\n\n## Features\n\n- `render` (alias: `f`): Render a template to a string, mimicking f-string behavior.\n- `generate_template` (alias: `t`): Create a Template object from a string and context.\n    This function is especially useful on Python versions that do not support template strings natively.\n- `bind`: Apply a function to all interpolations and join all the parts.\n- `binder`: Decorator to create template processors from an interpolation processor.\n- `normalize` / `normalize_str`: Apply conversion and format to value.\n- `convert`: Apply conversion to a value.\n- `template_eq`: Check if two templates are equivalent.\n- `interpolation_replace`: Create a new `Interpolation` by selectively replacing attributes of an existing one.\n- `dedent`: `textwrap.dedent` for template strings\n- `template_from_parts`: Construct template strings from iterable\n\nThis library also provides several useful extensions where template strings can be effectively utilized.\nThese extensions are available in the `tstr.ext` submodule, and below is a list with brief descriptions:\n\n- `ext._html`: Render templates with HTML escaping.\n- `ext._sqlite`: Safely execute SQL with templates, preventing SQL injection attacks.\n- `ext._logging`: Enable Python's logging module to accept template strings.\n\nFor more details, see the [API documentation](/docs/api.md).\n\n## Compatibility\n\n`tstr` automatically detects native template string support (PEP 750):\n\n- Python 3.14+: Uses native template strings.\n- Python 3.10\u20133.13: Uses a compatible backport.\n\nUse the `TEMPLATE_STRING_SUPPORTED` constant to check if template strings are natively supported in your Python version.\n\nFor details on how the compatible backport of template string works and what similarities and differences it has with native template strings, see the [compatible template strings](/docs/compat.md) documentation.\n\n# Contributing\n\nThis project welcomes contributions of all kinds from anyone willing to help improve it! Whether you're fixing a typo in documentation, reporting a bug, proposing a new feature, or implementing code changes - every contribution matters and is highly appreciated.\n\n## Releases\n\n* 0.3.0: Revamp various things\n* 0.2.0: Rename html_render to render_html, add `_logging` module, fix various bugs and improve documentation\n* 0.1.1.post1: Initial release\n\n## License\n\nThis library is licensed under the Apache License 2.0.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Template string utilities and backports",
    "version": "0.3.0",
    "project_urls": {
        "Repository": "https://github.com/ilotoki0804/tstr"
    },
    "split_keywords": [
        "backport",
        " pep 750",
        " pep-750",
        " pep750",
        " string",
        " t-string",
        " template",
        " template string",
        " tstring",
        " utility"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "9d9865e7504951db1ade3f471c48843063338fc1407c80a3a2a85a83c0fa6172",
                "md5": "bfe3c68f90171ef14975dab102a6c9d2",
                "sha256": "a3add2d071469c5a9429239cf6501170c8c0611fc269d3f89f66dd351cfd4e4a"
            },
            "downloads": -1,
            "filename": "tstr-0.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "bfe3c68f90171ef14975dab102a6c9d2",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 19632,
            "upload_time": "2025-09-01T12:20:00",
            "upload_time_iso_8601": "2025-09-01T12:20:00.538392Z",
            "url": "https://files.pythonhosted.org/packages/9d/98/65e7504951db1ade3f471c48843063338fc1407c80a3a2a85a83c0fa6172/tstr-0.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "63752a4e4ee31cd5eef6415b33df2a6d06bc1f5818e335ab924555a42941f120",
                "md5": "6d2eda308ca01102b84193b764e1dc03",
                "sha256": "d674b6d065a1c4a19013e521175fc51d21cc1e1532e45d8b96268999d4ae6b10"
            },
            "downloads": -1,
            "filename": "tstr-0.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "6d2eda308ca01102b84193b764e1dc03",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 43718,
            "upload_time": "2025-09-01T12:19:59",
            "upload_time_iso_8601": "2025-09-01T12:19:59.402935Z",
            "url": "https://files.pythonhosted.org/packages/63/75/2a4e4ee31cd5eef6415b33df2a6d06bc1f5818e335ab924555a42941f120/tstr-0.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-09-01 12:19:59",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ilotoki0804",
    "github_project": "tstr",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "tstr"
}
        
Elapsed time: 1.10687s