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:

I'm looking forward to this. Good job @jargnar

Sumith (~Sumith1896)

I'm not able to attend PyCon this year. I'm gone through your proposal i feel its quite interesting to me. I study and execute the example you gave in the proposal. I have a few questions:

1) I need few real time examples and real time scenarios. 2) Where can i implement this ast module ?

seenureddy (~seenureddy)

This is the new informations for me. the python hacks related informations included here.as a software developer.this include informations are very much useful for me.this article help me to understand some new informations.i am erp developer, for more informations about include the website ERP Development Company Dubai


Login to add a new comment.