Code as Data: A Practical Introduction to Python’s Abstract Syntax Tree
2025-09-30 , Louis Armand 1 - Est

Peek under the hood of Python and unlock the power of its Abstract Syntax Tree! We'll demystify the AST and explore how it powers tools like pytest, linters, and refactoring - as well as some of your favorite data libraries.


What is the Python Abstract Syntax Tree and why should you care? In this talk, we'll demystify the Abstract Syntax Tree (AST) and show how it powers tools you probably already use - including some popular data libraries.

We'll take a close look at pytest assert rewrite as a motivating and empowering example of how AST transformations work.

ASTs (and their cousins, the Concrete Syntax Trees) drive many real-world applications, from linters to automatic refactoring. We'll mention some modern tools you might want to use.

Armed with our new knowledge, we'll look at how popular data libraries like pandas make use of the AST.

You'll leave this talk with a deeper understanding of Python's internals, and a good idea of when to reach for AST-based techniques yourself.

Who this talk is for/background knowledge: No prior AST knowledge is needed, Python users curious about how things work under the hood will benefit the most from this talk.

Outline:

  • Minutes 0-5: Primer on the AST
  • Minutes 5-17: pytest deep-dive
  • Minutes 17-21: ASTs show up everywhere
  • Minutes 21-27: AST usage examples in data tools
  • Minutes 27-30: Conclusion, Q&A

I'm a freelance web developer helping small teams ship reliable software. I've been working with Python for 10+ years and enjoy automating work for other developers.

These days I'm very interested in local-first software technologies.
I attended the Recurse Center (a programming retreat) in 2018.

GitHub profile
Blog