coddpiece is a Python library that teaches relational algebra by letting you build expressions via method chaining, then compiles them to real SQL and runs them on any DB-API 2.0 connection. The core value is the side-by-side view: every expression can call .explain() to show the algebra notation, expression tree, compiled SQL, and plain-English reading simultaneously. This makes abstract concepts like relational division — which compiles to a notoriously ugly double-negation NOT EXISTS/EXCEPT pattern — suddenly click. The library enforces set semantics with DISTINCT by default (matching the relational model), offers a .bags() mode to expose the SQL/theory gap, and ships with the classic suppliers-and-parts dataset. It supports SQLite, PostgreSQL, and MySQL, though only the SQLite path is CI-tested against a live database. Install via pip, requires Python 3.10+, MIT licensed.

3m read timeFrom postgr.es
Post cover image
Table of contents
The whole point is the side-by-sideA couple of deliberate choicesBackends, honestly
5.1K Impressions