Skip to content

t-strings/awesome-t-strings

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Awesome T-Strings Awesome License: CC0-1.0 PRs Welcome

A curated list of resources, tools, libraries, and examples for Python's Template Strings (t-strings) introduced in Python 3.14

Warning

Template strings are currently in beta as part of Python 3.14. The syntax and behavior may change before the final release. This feature is experimental and should not be used in production code yet.

Template strings (t-strings) are a powerful new Python feature defined in PEP 750 that extends f-strings with programmable string processing capabilities. They enable safer string interpolation, prevent injection attacks, and allow for custom domain-specific languages.

Contents

What are T-Strings?

Template strings (t-strings) are a new Python feature that provide programmable string interpolation. Unlike f-strings which immediately produce a string, t-strings return a structured template object that can be processed by custom functions. This enables:

  • Security: Prevent injection attacks through controlled processing
  • Flexibility: Create custom DSLs for any domain (SQL, HTML, logging, etc.)
  • Performance: Lazy evaluation and optimized string handling
  • Type Safety: Full static type checking support

Basic Examples (from PEP 750)

# Template strings use 't' prefix instead of 'f'
template: Template = t"Hello {name}"

# HTML auto-escaping example
evil = "<script>alert('evil')</script>"
template = t"<p>{evil}</p>"
assert html(template) == "<p>&lt;script&gt;alert('evil')&lt;/script&gt;</p>"

# HTML attributes from dictionary
attributes = {"src": "shrubbery.jpg", "alt": "looks nice"}
template = t"<img {attributes} />"
assert html(template) == '<img src="shrubbery.jpg" alt="looks nice" />'

# Accessing template components
name = "World"
template = t"Hello {name}"
assert template.strings == ("Hello ", "")
assert template.interpolations[0].value == "World"
assert template.interpolations[0].expression == "name"

Learn more in PEP 750.

Official Resources

Development Tools

Linting & Static Analysis

  • t-linter - Comprehensive linting tool for t-strings with IDE integrations

Type Checking

IDE Extensions

Environment & Installation

  • uv - Fast Python package manager with built-in Python version management
  • Python Docker Images - Official Python images (3.14-rc tags available)
  • CPython Source - Build Python 3.14 from source

Libraries & Frameworks

Database & SQL

  • sql-tstring - Safe SQL query building with t-strings, preventing SQL injection
    • PyPI Package - pip install sql-tstring
    • Features parameterized queries, type safety, and database adapter integration

Utilities

  • better-dedent - Enhanced string dedenting for cleaner template formatting

Learning Resources

Tutorials & Videos

Community Discussions

Getting Started

Installation

To start using t-strings, you'll need Python 3.14 or later:

# Using uv package manager
uv python install 3.14

# Using Docker
docker run -it python:3.14-rc

# Build from source
git clone https://github.com/python/cpython.git
cd cpython
git checkout v3.14.0b2
./configure --enable-optimizations
make -j4  # Or use $(nproc) on Linux, $(sysctl -n hw.ncpu) on macOS
sudo make altinstall

Related

Contributing

Contributions are welcome! Please read our Contributing Guidelines before submitting PRs.

How to Contribute

  1. Check for existing entries before adding new ones
  2. Test all code examples with Python 3.14+
  3. Verify all links are working
  4. Follow the established format
  5. Add meaningful descriptions

See CONTRIBUTING.md for detailed guidelines.

License

CC0

This work is licensed under a Creative Commons Zero v1.0 Universal License.

About

No description, website, or topics provided.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages