🌐
Real Python
realpython.com › python-t-strings
Python 3.14: Template Strings (T-Strings) – Real Python
July 2, 2025 - Even though it’s possible to use Template as shown in this example, the most convenient way to create t-strings is using literals. As with any attribute, you can access .strings, .interpolations, and .values using the dot notation on an instance of Template: ... >>> name = "Pythonista" >>> site = "realpython.com" >>> template = t"Hello, {name}! Welcome to {site}!" >>> template.strings ('Hello, ', '! Welcome to ', '!') >>> template.interpolations ( Interpolation('Pythonista', 'name', None, ''), Interpolation('realpython.com', 'site', None, '') ) >>> template.values ('Pythonista', 'realpython.com')
🌐
Python Morsels
pythonmorsels.com › t-strings-in-python
T-strings: Python's Fifth String Formatting Technique? - Python Morsels
October 20, 2025 - Anytime you're designing a tool where you need to pre-process smaller input strings before combining them to a larger string, like escaping SQL, HTML, or regular expressions, you might want to use a t-string. Or, if you need to delay string interpolation for some other reason, like Python's logging module does, t-strings could come in handy in that case as well.
Discussions

How are Python 3.14 t-strings different than f-strings - Stack Overflow
Python 3.14 is introducing template strings, so-called t-strings. Can someone explain how these differ from f-strings? What new problems are t-strings helping developers solve? More on stackoverflow.com
🌐 stackoverflow.com
Python's new t-strings
When do we get the g-strings? More on reddit.com
🌐 r/programming
43
124
April 21, 2025
Python’s new t-strings
db.execute("QUERY WHERE name = ?", (name,)) with · db.execute(t"QUERY WHERE name = {name}") Does the benefit from this syntactic sugar outweigh the added complexity of a new language feature? I think it does in this case for two reasons: More on news.ycombinator.com
🌐 news.ycombinator.com
466
620
May 1, 2025
How to treat \t as a regular string in python - Stack Overflow
I need to remove \t from a string that is being written however when ever I do str(contents).replace('\t', ' ') it just removes all of the tabs. I understand this is because \t is how you write ta... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Davepeck
davepeck.org › 2025 › 04 › 11 › pythons-new-t-strings
Python's new t-strings | Dave Peck
April 11, 2025 - I’m excited about t-strings because they make string processing safer and more flexible. In this post, I’ll explain what t-strings are, why they were added to Python, and how you can use them.
🌐
Snarky
snarky.ca › unravelling-t-strings
Unravelling t-strings
May 16, 2025 - We parsed f"Hello, {name}! Conversions like {name!r} and format specs like {name:<6} work!" into Template("Hello, ", Interpolation(name, "name"), "! Conversions like ", Interpolation(name, "name", "r"), " and format specs like ", Interpolation(name, "name", format_spec="<6")," work!"). We were then able to use our f_yeah() function to convert the t-string into what an equivalent f-string would have looked like. The actual code to use to test this in Python 3.14 with an actual t-string is the following (PEP 750 has its own version of converting a t-string to an f-string which greatly inspired my example):
🌐
Python
docs.python.org › 3 › library › string.html
Common string operations — Python 3.14.5 documentation
A primary use case for template strings is for internationalization (i18n) since in that context, the simpler syntax and functionality makes it easier to translate than other built-in string formatting facilities in Python. As an example of a library built on template strings for i18n, see the flufl.i18n package.
🌐
GitHub
github.com › t-strings › awesome-t-strings
GitHub - t-strings/awesome-t-strings · GitHub
A curated list of resources, tools, libraries, and examples for Python's Template Strings (t-strings) introduced in Python 3.14
Starred by 68 users
Forked by 4 users
Languages   Python
🌐
Python
docs.python.org › 3 › library › string.templatelib.html
string.templatelib — Support for template string literals
If multiple strings are passed consecutively, they will be concatenated into a single value in the strings attribute. For example, the following code creates a Template with a single final string:
🌐
Talk Python To Me
talkpython.fm › episodes › show › 505 › t-strings-in-python-pep-750
Episode #505 - t-strings in Python (PEP 750) | Talk Python To Me Podcast
May 13, 2025 - 44:57 Well, we wanted to show some basic examples like, hey, t-strings have a syntax that looks a lot like f-strings. 45:03 How could you build f-strings on top of t-strings? 45:05 So there is an F paren-paren method that's implemented here that just kind of helps you understand, okay, I'm writing dynamic code to do the thing that f-strings would have done at compile time anyway. ... 45:20 And I'm excited about this, you know, structured logging that Python has shipped a logging cookbook for a long time since the Python 2.something era.
Find elsewhere
Top answer
1 of 2
22

The new t-strings ease the creation of strings meant to represent other languages, embedded in a Python program, while preserving information about the variables and expressions interpolated so that specialized glue/connection code to that other language can do things like syntax checking, character escaping, security auditing, and in general adding specific punctuation to those interpolated values. The full proposal is in PEP 750.

The important thing to have in mind is that a t-string by itself adds no value. Just when combined with a call to a consumer of that string, which might be a SQL connector, an HTML renderer, or even a regular expression template, the extra information - when compared with an f-string - present in the t-string will add value.

In other words, while an f-string is immediately rendered into an immutable, plain str instance when found, a t-string is converted into a Template object which preserves information about the individual interpolated values (and if needed, their original expressions). This template instance is then passed to a call which will act on the string, special casing these values. For example, a t-string aware SQL connector can automatically escape in a safe way all interpolated values, mitigating any possible SQL injection vulnerability.

For a simple usage example not in the docs, here is a simple interactive mode snippet which will wrap the templated values in a CSI ANSI code sequence to change the terminal color. I set up constant values with the color codes I am using for the example:


In [26]: from string import templatelib

In [27]: red = 31; reset=0; green = 32

In [28]: a = t"The next {red}text{reset} should be {green}in another color{reset}"

In [29]: for part in a:
    ...:     if isinstance(part, templatelib.Interpolation):
    ...:         part = f"\x1b[{part.value}m"
    ...:     # else: -> implies 'part' is a regular str object
    ...:     print(part, end="")
    ...: 

This prints some text colored according to the example in a functional terminal (not windows CMD).

Still in this summary, it is worth noting that t-strings, like f-strings are eagerly evaluated. This means the values for the variables in the interpolated expressions are used as they are when the line of code where the t-string is expressed is executed: even if the variable changes later on, the orignal value is saved in the template object. The converse behavior, having the values dynamically change with the values assigned to the variables in the expressions was reasoned out in the discussions leading to the feature. (check the rejected ideas session in PEP 750)

2 of 2
2

The What's New page has various examples, and some potential applications of template strings.

With this in place, developers can write template systems to sanitize SQL, make safe shell operations, improve logging, tackle modern ideas in web development (HTML, CSS, and so on), and implement lightweight, custom business DSLs.

from string.templatelib import Template, Interpolation

def lower_upper(template: Template) -> str:
    """Render static parts lowercased and interpolations uppercased."""
    parts: list[str] = []
    for item in template:
        if isinstance(item, Interpolation):
            parts.append(str(item.value).upper())
        else:
            parts.append(item.lower())
    return "".join(parts)

name = "world"
assert lower_upper(t"HELLO {name}") == "hello WORLD"

The main difference is the following:

Compared to using an f-string, the html function has access to template attributes containing the original information: static strings, interpolations, and values from the original scope.

🌐
YouTube
youtube.com › watch
Python 3.14: The NEW T-strings are Awesome - YouTube
In today's video we're going to learn about template strings in Python using the new T-string syntax introduced in Python 3.14!▶ Become job-ready with Python...
Published   September 16, 2025
🌐
Reddit
reddit.com › r/programming › python's new t-strings
r/programming on Reddit: Python's new t-strings
April 21, 2025 - A t-string expression constructs an object of type Template, containing all string fragments and evaluated values that formed the expression. Any further code can do with this Template whatever it wants. What is the primary use case, like if someone wrote some small library in python with a few functions, how do t-strings fit in there?
🌐
InfoWorld
infoworld.com › home › software development › programming languages › python
How to use template strings in Python 3.14 | InfoWorld
September 26, 2025 - If this were a conventional f-string, we could print(template) and get Hello, Davis as the output. But if we try printing a t-string, we don’t get a string. Instead, we get a Python object representation:
🌐
Python Snacks
pythonsnacks.com › p › python-3-14-presents-t-strings
An Introduction to t-strings in Python 3.14
July 27, 2025 - » t-strings currently don’t support mathematical operations, inline expressions, string operations and if-else logic, unlike f-strings and .format() Python 3.14 (Beta 4) introduces t-strings, a new secure string formatting feature.
🌐
Real Python
realpython.com › lessons › 314-introducing-t-strings
Introducing Python T-Strings (Video) – Real Python
In the previous lesson, I showed you the new functools placeholder feature when calling partial to create a function alias. In this lesson, I’ll demonstrate t-strings. The “t” in t-strings stands for “template” under the covers. A t-string uses the…
Published   October 7, 2025
🌐
Python
peps.python.org › pep-0750
PEP 750 – Template Strings - Python Enhancement Proposals
July 8, 2024 - Template strings address these problems by providing developers with access to the string and its interpolated values. For example, imagine we want to generate some HTML.
🌐
Real Python
realpython.com › lessons › python-t-strings-summary
Exploring Python T-Strings (Summary) (Video) – Real Python
In the previous lesson, I showed even more t-string handling techniques. In this lesson, I’ll summarize the course and point you at other resources. T-strings are f-string-like mechanisms with fine-grained control on how you process the parts of a…
Published   August 5, 2025
🌐
Hacker News
news.ycombinator.com › item
Python’s new t-strings | Hacker News
May 1, 2025 - db.execute("QUERY WHERE name = ?", (name,)) with · db.execute(t"QUERY WHERE name = {name}") Does the benefit from this syntactic sugar outweigh the added complexity of a new language feature? I think it does in this case for two reasons:
🌐
Django Forum
forum.djangoproject.com › django internals
Supporting t-strings from Python 3.14 - Django Internals - Django Forum
May 14, 2025 - t-strings have been merged into Python 3.14 for its beta 1 release (May 7). Since reading the PEP and its associated example repo, I’ve been noodling about how Django could use t-strings. I am sure others are eager to t…
🌐
Real Python
realpython.com › videos › introducing-t-strings
Introducing T-Strings (Video) – Real Python
02:32 This is our second interpolation. Note that the value is of the resulting type. So for the price field, it’s a float rather than a string. When Python processes a t-string, it returns a template object, and that object has attributes.
Published   August 5, 2025