Hacking the Python AST

Suhas SG (~jargnar)





Computer languages are a remarkable feat of human scientific engineering. In this talk, we'll look at the innards of Python, and specifically learn how to modify Abstract Syntax Trees (for world peace).

Rough agenda

  • [ 05 mins ] --- A brief intro to languages and compilers
  • [ 05 mins ] --- CPython
  • [ 10 mins ] --- Everything about Python ASTs
  • [ 15 mins ] --- Let's write a flake8 plugin (to understand ASTs better)
  • [ 05 mins ] --- Metaprogramming, code as data, possibilities and more!

What we'll learn

  • We'll learn the life of a python code, and how the CPython process works.
  • We'll understand and be able to participate in conversations that include words like LL(1) parser
  • We'll make our devious minds work towards hacking into source code and modifying it with the help of ast.NodeTransformer
  • We'll learn to write a Flake8 plugin
  • A treasure map to dive into deeper waters


  • Basics of Python, must be comfortable with lists, functions, classes
  • Basic idea / understanding of data structures
  • A mischievous mind to get hands dirty for intercepting source code and parsing ASTs
  • A bottle of water to keep yourself hydrated

Content URLs:

  • Teaser video: https://youtu.be/Lvy_DcZnYOE
  • Github repo: https://github.com/jargnar/hacking-python

Speaker Info:

Suhas is a data scientist, a speaker, and a design hacker from Bangalore, India. He has designed and built big data solutions for some of the Fortune 500 companies with Gramener.

He runs the Bangalore chapter of Internet Society, dealing with Internet-related, social and policy issues, in addition to running a data visualization and art museum called LifeWithData.

Section: Core Python
Type: Talks
Target Audience: Advanced
Last Updated: