Skip to content
AI News HubLIVE
Original source1 min read

TRE Python binding — ReDoS robustness demo

Summary

Simon Willison explores Ville Laurikari's TRE regex engine by building an experimental Python ctypes binding with Claude Code and testing it against malicious regex attacks. TRE, due to its lack of backtracking, handles 'evil patterns' and large inputs far better than Python's standard re module, scaling linearly instead of exponentially.

TRE Python binding — ReDoS robustness demo
Report an error

The correction channel is not available yet. You can copy the article reference below for later.

Correction instructions
Read article

Research: TRE Python binding — ReDoS robustness demo

Simon Willison’s Weblog

Subscribe

Sponsored by: MongoDB — Join MongoDB.local London 2026 on 7 May to learn how teams move AI from prototype to production.

4th May 2026

Research

TRE Python binding — ReDoS robustness demo — Demonstrating robust regex performance, this project offers a minimal Python ctypes binding to the TRE regex library, highlighting TRE’s immunity to regular expression denial-of-service (ReDoS) attacks that cripple Python's built-in re module. Key benchmarks show that TRE processes even notorious "evil" patterns on gigantic inputs (10 million characters) much faster than re on tiny ones, and scales linearly with input size instead of exponentially.

If it's good enough for antirez to add to Redis I figured Ville Laurikari's TRE regular expression engine was worth exploring in a little more detail.

I had Claude Code build an experimental Python binding (it used ctypes) and try some malicious regular expression attacks against the library. TRE handles those much better than Python's standard library implementation, thanks mainly to the lack of support for backtracking.

Posted 4th May 2026 at 5:52 pm

Recent articles

LLM 0.32a0 is a major backwards-compatible refactor - 29th April 2026

Tracking the history of the now-deceased OpenAI Microsoft AGI clause - 27th April 2026

DeepSeek V4 - almost on the frontier, a fraction of the price - 24th April 2026

This is a beat by Simon Willison, posted on 4th May 2026.

c 53

ctypes 9

python 1250

regular-expressions 37

security 600

Monthly briefing

Sponsor me for $10/month and get a curated email digest of the month's most important LLM developments.

Pay me to send you less!

Sponsor & subscribe

Disclosures

Colophon

©

2002

2003

2004

2005

2006

2007

2008

2009

2010

2011

2012

2013

2014

2015

2016

2017

2018

2019

2020

2021

2022

2023

2024

2025

2026

Key points and analysis

Article intelligence

EngineersAdvanced

Key points

  • TRE regex engine by Ville Laurikari, already adopted in Redis by antirez, is known for resistance to ReDoS attacks.
  • Simon Willison created a Python ctypes binding for TRE using Claude Code and tested it against malicious regex patterns.
  • Without backtracking support, TRE processes 10-million-character evil patterns faster than Python's re module handles tiny inputs, with linear scaling.
  • TRE offers a robust alternative to Python's re module, mitigating ReDoS vulnerabilities.

Highlights and analysis are generated automatically and may contain errors. Check the original source.