TRE Python binding — ReDoS robustness demo

Simon Willison's Blog Tools

Summary

A minimal Python ctypes binding to the TRE regex library demonstrates robust performance against ReDoS attacks, processing evil patterns on 10M-character inputs much faster than Python's re module.

No content available
Original Article
View Cached Full Text

Cached at: 05/08/26, 06:43 AM

# Research: TRE Python binding — ReDoS robustness demo Source: [https://simonwillison.net/2026/May/4/tre-python-binding/](https://simonwillison.net/2026/May/4/tre-python-binding/) Research[TRE Python binding — ReDoS robustness demo](https://github.com/simonw/research/tree/main/tre-python-binding#readme)— 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](https://simonwillison.net/2026/May/4/redis-array/)to add to Redis I figured Ville Laurikari's[TRE](https://github.com/laurikari/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\.

Similar Articles

DOOM running on a regex engine

Lobsters Hottest

A developer demonstrates running the game DOOM using a regex engine as a computational substrate, performing millions of substitutions per frame.

TREX: An AI code reviewer that runs your code

Hacker News Top

Greptile introduces TREX, an AI code reviewer that executes code and detects runtime bugs, going beyond static analysis by spinning up parallel agents to investigate issues and generate artifacts like screenshots.