liveBook · Manning

Psycopg

As explained in Designing AI Systems

psycopg2 is a Python adapter library for connecting to and communicating with PostgreSQL databases.

psycopg2 is the concrete Python adapter behind a PostgreSQL session-storage implementation. It accepts a connection string, opens cursors, executes SQL, and converts database rows into Python objects exposed through a SessionStorage interface. section 4.4.2

A production-oriented storage adapter uses psycopg2 to:

  • Retrieve or create sessions, including concurrent creation handled with PostgreSQL ON CONFLICT. section 4.4.2

How Designing AI Systems covers it

How deep it goes
Explains connections, cursors, parameterized queries, pagination, serialization, and row conversion without covering broader driver operations.
Examples
Uses session creation, batched message insertion, paginated retrieval, and row-to-object conversion as implementation examples.
What it assumes
Assumes Python classes, SQL, PostgreSQL tables, sessions, messages, and an existing SessionStorage interface.
What you can do after
Build it from scratch as a PostgreSQL session-storage adapter with connection handling, SQL operations, pagination, and object conversion.
How it connects
Connects PostgreSQL, SQL queries, database cursors, JSON serialization, UUIDs, and the SessionStorage interface.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Designing AI Systems. The section links point to the parts of the book it draws on.