Records runs SQL against relational databases and returns rows you can slice, iterate, or export. It sits on SQLAlchemy and Tablib with a small, direct API.
Overview
Records is a Python library for sending raw SQL to relational databases without an ORM layer. You write SQL strings or load query files, execute them, and work with results as row objects that support attribute, mapping, and index access—including column names with spaces.
Supported database backends named in the documentation include Postgres, MySQL, SQLite, Oracle, MS-SQL, and RedShift, with drivers supplied separately. Results can be fetched one row at a time, iterated, materialized with all(), or reduced with first() when you expect a single row. Helpers expose asdict() for structured output.
The library adds parameterized queries, transactions, bulk query helpers, optional DATABASE_URL from the environment, and a convenience method to list table names. Iterated row sets are cached for reuse. A command-line records tool can export query output.
Through Tablib integration, result sets export to CSV, JSON, YAML, HTML tables, Excel, and Pandas DataFrames in one step, which supports reporting and sharing tabular data.
Key features
- Raw SQL without ORM overhead
- SQLAlchemy-powered connections
- Row access by name or index
- Parameterized queries
- Transactions and bulk queries
- Query from strings or files
- Tablib export formats
- CLI export tool
Use cases
- Ad hoc analytics queries
- Reporting and data export
- Scripted database inspection
- Lightweight ETL from SQL
- Teaching SQL-first workflows