Metadata-Version: 2.4
Name: future-tstrings
Version: 1.0.1
Summary: Backport of tstrings to python <3.14, and full-syntax fstrings to python <3.12
Author-email: Marckie Zeender <mkzeender@gmail.com>
License-File: LICENSE
Requires-Python: >=3.8
Requires-Dist: parso==0.8.4; python_version < '3.14'
Description-Content-Type: text/markdown


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)

```python
# future-tstrings
```

And then write python 3.14 tstring and fstring code as usual!


```python
- 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"

```

```console
$ python -m example
t"hello {'world'}"
```

## Showing compiled source

`future-tstrings` also includes a cli to show transformed source.

```console
$ 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:

```python
try:
    from string.templatelib import Template
except ImportError:
    class Template:
        pass
```

## How does this work?

`future-tstrings` has two parts:
1. An `importer` which transpiles t-strings and f-strings to code understood by older versions of python

1. A `.pth` file 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:

```python
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.
