Dataset - databases for lazy people
Dataset is a Python library which is basically a wrapper around SQLAlchemy. It claims to be so easy to use that even lazy people like it.
Install dataset
as follows:
$ pip3 install dataset
Create a SQLite in-memory database and connect to it:
import dataset db = dataset.connect('sqlite:///:memory:')
Create a table called books
:
table = db["books"]
Actually, the table in the database isn't created yet, since we haven't specified any columns. We only created a related object. The table schema is created automatically from calls to the insert()
method. Give the insert()
method dictionaries with book titles:
table.insert(dict(, author='Ivan Idris')) table.insert(dict(, author='Ivan Idris')) table.insert(dict(, author='Ivan Idris'))
Print the rows from the table as follows:
for row in db['books']: print(row)
The following will be printed:
<dataset.persistence.util.ResultIter object at 0x10d4bf550> OrderedDict([('id', 1), ('title', "NumPy Beginner...