Backport of tstrings to python <3.14, and full-syntax fstrings to python <3.12
Project description
future-tstrings
A backport of tstrings to python<3.14
Also serves as a backport of full-syntax fstrings (PEP701-style) to python <3.12.
Does nothing on 3.14 or higher.
Requires python >= 3.8
Installation
pip install future-tstrings
Usage
Include the following magic line at the top of the file (before regular imports)
# future-tstrings
And then write python 3.14 tstring and fstring code as usual!
- example.py
from string.templatelib import Template # or, future_tstrings.templatelib
thing = "world"
template: Template = t"hello {thing}"
print(repr(template))
# t"hello {'world'}"
assert template.strings[0] == "hello "
assert template.interpolations[0].value == "world"
$ python -m example
t"hello {'world'}"
Showing compiled source
future-tstrings also includes a cli to show transformed source.
$ future-tstrings example.py
Integrating with template processing tools
Libraries that consume template strings (html parsers, etc) do not need to do anything extra to support future-tstrings, except:
They should NOT disable this behavior on python<3.14. To implicitly support future-tstrings without listing it as a dependency, use the following:
try:
from string.templatelib import Template
except ImportError:
class Template:
pass
How does this work?
future-tstrings has two parts:
-
An
importerwhich transpiles t-strings and f-strings to code understood by older versions of python -
A
.pthfile which registers the importer on interpreter startup.
Alternative python environments
In environments (such as aws lambda) where packages are not installed via pip, the .pth magic will not work, so you'll need to manually initialize future-tstrings
in a wrapper python module. For instance:
from future_tstrings import install
install()
from actual_main import main
if __name__ == '__main__':
main()
Additionally, for zipped or frozen packages, the importer will not work. In such environments, you will need to use the future-tstrings command-line compiler before the code is zipped, frozen, etc.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file future_tstrings-1.0.1.tar.gz.
File metadata
- Download URL: future_tstrings-1.0.1.tar.gz
- Upload date:
- Size: 36.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9dd8bf64f6d00a0a503831f720f0dec2876524707a0f8eca5c8a95cc2630d21a
|
|
| MD5 |
575c13d5fed8843c6bd02f29b8757a03
|
|
| BLAKE2b-256 |
1361ac517514abe2fd5ff7f9b66d9469bcaeb6d831f2f7dd9f4530ced5737618
|
Provenance
The following attestation bundles were made for future_tstrings-1.0.1.tar.gz:
Publisher:
python-publish.yml on mkzeender/future-tstrings
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
future_tstrings-1.0.1.tar.gz -
Subject digest:
9dd8bf64f6d00a0a503831f720f0dec2876524707a0f8eca5c8a95cc2630d21a - Sigstore transparency entry: 962529277
- Sigstore integration time:
-
Permalink:
mkzeender/future-tstrings@84c7ca8d1ac52ef41d4886326c4a5e3e4bc2d2f4 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/mkzeender
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@84c7ca8d1ac52ef41d4886326c4a5e3e4bc2d2f4 -
Trigger Event:
release
-
Statement type:
File details
Details for the file future_tstrings-1.0.1-py3-none-any.whl.
File metadata
- Download URL: future_tstrings-1.0.1-py3-none-any.whl
- Upload date:
- Size: 25.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2bc55c331e42ba72896a25a24a891aca30267cd5ac0f57e960b53db318780a8e
|
|
| MD5 |
59526b40a2ea421b24cfe5d0ab752188
|
|
| BLAKE2b-256 |
0c27a28ec6e1ad79b17356acfa9e5955a2e7d0f5df6d7e65762e524c889f093f
|
Provenance
The following attestation bundles were made for future_tstrings-1.0.1-py3-none-any.whl:
Publisher:
python-publish.yml on mkzeender/future-tstrings
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
future_tstrings-1.0.1-py3-none-any.whl -
Subject digest:
2bc55c331e42ba72896a25a24a891aca30267cd5ac0f57e960b53db318780a8e - Sigstore transparency entry: 962529278
- Sigstore integration time:
-
Permalink:
mkzeender/future-tstrings@84c7ca8d1ac52ef41d4886326c4a5e3e4bc2d2f4 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/mkzeender
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@84c7ca8d1ac52ef41d4886326c4a5e3e4bc2d2f4 -
Trigger Event:
release
-
Statement type: