Putting Python in PostgreSQL

PyCon 2012

PostgreSQL is pretty powerful all on its own, but did you know you can use Python as a stored procedure language? Not only does using a familiar language make development easier, but you get the power of the standard library and PyPi to boot. Come learn the ins and outs of putting Python in your DB.

This conference talk from March 2012 presents "Putting Python in PostgreSQL" by Frank Wiles, exploring how to use PostgreSQL's PL/Python extension to write database functions and triggers in Python instead of PL/pgSQL. The presentation covers the installation and setup process, demonstrates basic Python functions within PostgreSQL, explains datatype mappings between PostgreSQL and Python, and showcases practical applications including database triggers for data validation, Redis integration for real-time counters, and credit card validation. While Wiles acknowledges the performance overhead and debugging challenges inherent in this approach, he positions PL/Python as a valuable tool for specific use cases such as data aggregation, constraint enforcement across development teams, retrofitting features into existing systems without modifying application code, and leveraging Python's extensive library ecosystem for tasks like external API calls, email notifications, and cache management directly within the database layer.