AI & ML

Python's D-Strings Feature Could Replace textwrap.dedent() — April 2026 Roundup

· 5 min read

Python developers who've grown tired of wrapping multiline strings in textwrap.dedent() have a potential solution on the horizon. PEP 822 introduces d-strings, a new string prefix (d"""...""") that automatically removes leading indentation. The proposal addresses a common pain point with an elegant syntax addition. The PEP remains in draft status.

The month also brought Python 3.15.0 alpha 7, featuring testable lazy imports, alongside security updates for three maintenance branches. In the broader ecosystem, GPT-5.4 introduced tool search capabilities that impact agentic development patterns. The Python Insider blog completed a platform migration, successfully moving over 300 posts while maintaining URL integrity. Here's your comprehensive roundup of Python news from the past month.

Python Releases and PEP Highlights

The penultimate alpha release of Python 3.15 arrived in March with a highly anticipated feature for deferred imports. Three older branches received critical security patches, while a new PEP emerged that could streamline how you handle indented multiline strings.

Python 3.15.0 Alpha 7: Lazy Imports Land

Released March 10, Python 3.15.0a7 represents the next-to-last alpha before the beta freeze scheduled for May 5. The standout addition is PEP 810's explicit lazy imports, now available for testing. While the Steering Council approved PEP 810 last November, this marks the first alpha with a working implementation.

The mechanism is simple: add the lazy keyword before any import statement, and the module loads only when you first access one of its attributes:

Python
lazy import json
lazy from datetime import timedelta
# Modules remain unloaded, avoiding startup overhead
# First use triggers loading:
data = json.loads(payload) # Loads here

According to the PEP authors, 17 percent of standard library imports already live inside functions to defer loading costs. Projects like Django management commands, Click-based CLIs, and type-checking-heavy codebases frequently spend hundreds of milliseconds importing modules they may never use. Lazy imports provide a clean, explicit alternative to scattering imports throughout function bodies.

Security Releases: Python 3.12.13, 3.11.15, and 3.10.20

Thomas Wouters issued security-only updates for three older Python branches on March 3. These releases address multiple CVEs, including two XML parsing vulnerabilities (CVE-2026-24515 and CVE-2026-25210) resolved by upgrading the bundled libexpat to version 2.7.4. The patches also fix an XML memory amplification issue and strengthen validation by rejecting control characters in HTTP headers and URL parsing.

Production environments running Python 3.12 or earlier should apply these updates promptly. Note that Python 3.12 has entered security-fixes-only mode, meaning no binary installers are available—you'll need to build from source.

PEP 822: Dedented Multiline Strings (D-Strings)

Authored by Inada Naoki, PEP 822 proposes a d"""...""" string prefix that automatically strips leading indentation from multiline strings using the same logic as textwrap.dedent().

Developers who've written multiline SQL queries or help text inside functions know the indentation struggle well:

Python
import textwrap
# Current approach: manual dedent or wrapper function
def get_query():
return textwrap.dedent("""\
 SELECT name, email
 FROM users
 WHERE active = true
 """)
# With d-strings: cleaner syntax
def get_query():
return d"""
 SELECT name, email
 FROM users
 WHERE active = true
 """

The d prefix works alongside f, r, b, and the upcoming t (template strings) prefixes. Submitted to the Steering Council on March 9, PEP 822 targets Python 3.15, though no decision has been announced yet. This proposal deserves attention if you've wished Python would handle string indentation natively.

Other PEPs in Progress

Read the full article at https://realpython.com/python-news-april-2026/ »


[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]