Records is a simple yet powerful Python library designed for making raw SQL queries to various relational databases with an elegant interface. It aims to reduce boilerplate code associated with common database tasks. The current version, 0.6.0, includes support for SQLAlchemy v2, making it compatible with modern database backends. Releases are infrequent but tend to include significant updates.
pip install recordsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to connect to a database (using an in-memory SQLite by default or a URL from an environment variable), execute a parameterized query, iterate through results, and access data from a `Record` object. It highlights basic CRUD operations and the importance of parameterized queries for security.
Upgrade your Python environment to 3.6+ and ensure SQLAlchemy is at version 2.x. Review SQLAlchemy's migration guides for any underlying changes that might impact your database setup or custom drivers.
Never concatenate user-provided or untrusted input directly into SQL queries. Always pass dynamic values as parameters to the `query` method, allowing the underlying database driver to safely handle the escaping.
Implement error handling around your first database query to catch potential connection issues early. Consider a simple `db.query('SELECT 1')` or similar lightweight query immediately after establishing the `Database` object in critical paths to confirm connectivity.For operations involving multiple SQL statements that must be treated as a single atomic unit, explicitly use `db.transaction()` as a context manager (e.g., `with db.transaction(): ...`) to ensure proper commit or rollback behavior.