The Python 'dataset' library (version 1.6.2) is a lightweight toolkit for simplified Python-based database access, abstracting away much of the direct SQL interaction. It enables reading and writing data in SQL data stores with an API designed to feel as straightforward as working with JSON files, offering features like implicit table and column creation, upserts, and convenient query helpers. Built on SQLAlchemy, it ensures compatibility with major databases such as SQLite, PostgreSQL, and MySQL. The library maintains a steady release cadence with bug fixes and feature enhancements.
pip install datasetVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to connect to a database (using an in-memory SQLite for simplicity), create a table implicitly, insert and update data, and query records using the `dataset` library.
Upgrade Python to 3.9+ and SQLAlchemy to a compatible version (>=1.4.0, preferably 2.0+). Consult the official Changelog and migration guides.
Install `datafreeze` separately (`pip install datafreeze`) and adjust code to use its API for data export functionality.
Install the required database driver using `pip install <driver_package_name>` (e.g., `pip install psycopg2-binary` for PostgreSQL, `pip install mysqlclient` for MySQL), or use the optional installation syntax like `pip install "dataset[postgresql]"`.
For production, use environment variables or a configuration management system to securely inject database credentials. For local development, pass the URL explicitly or ensure the environment variable is set safely.
Ensure you install the correct library using pip: `pip install dataset`.
Verify the table name is correct. If expecting implicit creation, ensure you perform an `insert()` operation first, or explicitly create it if working with an existing schema.
Consult the 'dataset' library documentation for the correct methods and attributes available on `Table` objects. For example, to find a record, use `table.find_one()` or `table.find()`, not a custom 'get' method.
Ensure transaction operations are correctly nested within `db.begin()` and `db.commit()` or `db.rollback()` calls. For example: `with db as tx: tx['mytable'].insert({'key': 'value'})` or manually: `db.begin(); db['mytable'].insert({'key': 'value'}); db.commit()`.