tstr - PEP 750 Template String Utilities & Backports
tstr provides utilities for working with PEP 750 template strings, 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:
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 newInterpolationby selectively replacing attributes of an existing one.dedent:textwrap.dedentfor 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 (coming soon) or docstrings.
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 (coming soon) 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.4.0: Support debug specifier on
t(), use new build script, improve docs - 0.3.0: Revamp various things
- 0.2.0: Rename html_render to render_html, add
_loggingmodule, fix various bugs and improve documentation - 0.1.1.post1: Initial release
License
This library is licensed under the Apache License 2.0.
Metadata
Release files for tstr 0.4.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| tstr-0.4.1.tar.gz | 47.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tstr-0.4.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 67.0 kB
Release files / tstr-0.4.1.tar.gz
| Download URL | tstr-0.4.1.tar.gz |
|---|---|
| Size | 47.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bad326e07fe239eb4c63635964a6de9d55ff40ab223b04c6361b01c3b709523d
|
|
BLAKE2b-256 checksum How to use checksums |
664088e526174c65fe84552c5b920b0b7ec0787c52148106932cb72020561080
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.0.1 CPython/3.12.8
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 11, 2026.
Transparency logRelease files / tstr-0.4.1-py3-none-any.whl
| Download URL | tstr-0.4.1-py3-none-any.whl |
|---|---|
| Size | 19.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2a7b387855fddb24e57edaaf347c37f6bde5c2673fbc851e576ee802d56c6bd3
|
|
BLAKE2b-256 checksum How to use checksums |
119307444ed2e23e5378da5e0468e26626955508a587bcfb2ffa95d1398582e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.0.1 CPython/3.12.8
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 11, 2026.
Transparency log