Talks

Supercharge your Python library using AST parsing

Saturday, May 17th, 2025 2:30 p.m.–3 p.m. in Hall C

Presented by

Adam Glustein

Experience Level:

Advance experience

Description

The primary goal of developers using the Python/C API is to increase the performance of their Python code. Often, this is done by executing a C function which has been compiled into machine code to bypass the Python interpreter. However, between a user’s Python code and the invocation of the C function, we can squeeze out even more performance. How, you ask?

We can leverage AST parsing with Python’s standard library “ast” module to modify the syntax of the code. In this talk, we show some tricks to transform the Python AST for optimized runtime performance using the C API. These aren’t just theoretical, either! Each example is taken from CSP, an open-source computation graph library which heavily uses the Python/C API.

This talk is meant for an advanced audience which has familiarity with the Python “ast” module as well as the Python/C API.

Search