How smorokin/fassung works
Fassung is an async Python interface to PostgreSQL that combines asyncpg, PEP 750 template strings, and Pydantic mapping. A caller obtains a pooled connection, opens a transaction, submits a composable template query, and receives typed results or streams rows through a cursor. Connections assemble templates into parameterized SQL before delegating database operations; typed result parsing is a shared internal layer. The README also describes nested query composition and listener support. Connection internals are partially excerpted, so uncertain wiring is omitted.
Main entry points: connection.py Connection · pool.py Pool · type_parser.py Type Parser · cursor.py Cursor Factory
Components 15
Connection Access
- Pool
src/fassung/pool.py - Connection
src/fassung/connection.py - Transaction
src/fassung/connection.py - Errors
src/fassung/exceptions.py
Query Execution
- Query Assembler
src/fassung/query_assembler.py - asyncpg
- Cursor Factory
src/fassung/cursor.py - Cursor
src/fassung/cursor.py - Cursor Iterator
src/fassung/cursor.py
Typed Results
- Type Parser
src/fassung/type_parser.py - Mapped Record
src/fassung/record.py - Pydantic
Database Events
- Listener API
src/fassung/types.py
Other components
- Application
- PostgreSQL
Connections 25
- Application → Pool: creates
- Application → Pool: acquires
- Pool → asyncpg: creates pool
- Pool → Connection: yields
- Application → Connection: runs queries
- Connection → Transaction: starts
- Transaction → Connection: proxies queries
- Connection → Query Assembler: assembles templates
- Connection → asyncpg: executes SQL
- asyncpg → PostgreSQL: queries
- Connection → Cursor Factory: creates cursor
- Cursor Factory → asyncpg: wraps cursor factory
- Cursor Factory → Cursor: awaits into
- Cursor Factory → Cursor Iterator: iterates as
- Cursor → Type Parser: parses rows
- Cursor Iterator → Type Parser: parses rows
- Connection → Type Parser: parses results
- Type Parser → Pydantic: validates with
- Pool → Mapped Record: configures records
- Connection → Listener API: accepts callbacks
- Connection → Type Parser: parses payloads
- Connection → asyncpg: registers listeners
- Connection → asyncpg: removes listeners
- Connection → Errors: raises on closed transaction
- Query Assembler → Errors: rejects plain strings