An improved Python interface to SQLite
Project description
isqlite is a wrapper around Python's SQLite library.
WARNING: isqlite is in beta. Make sure to back up your data before using it with isqlite.
from isqlite import Database, Table, columns
# Note that in addition to the columns declared explicitly, isqlite will automatically
# create `id`, `created_at` and `last_updated_at` columns.
schema = [
Table("teams", [
columns.Text("name", required=True),
]),
Table("employees", [
columns.Text("name", required=True),
columns.Integer("age", required=False),
columns.ForeignKey("team", "teams", required=False),
]),
]
with Database(schema, "db.sqlite3") as db:
# Create a new row in the database.
pk = db.create("people", {"name": "John Doe", "age": 30})
# Retrieve the row as an OrderedDict.
person = db.get("people", pk)
print(person["name"], person["age"])
# Update the row.
db.update("people", pk, {"age": 35})
# Delete the row.
db.delete("people", pk)
# Filter rows with a query.
people = db.list("people", q.Like("name", "John%") and q.GreaterThan("age", 40))
# Use raw SQL if necessary.
pairs = db.sql(
"""
SELECT
teams.name, employees.name
FROM
employees
INNER JOIN
teams
ON
employees.team = teams.id
"""
)
Features
- A more convenient API.
- e.g.,
db.create("people", {"name": "John Doe"})
instead ofcursor.execute("INSERT INTO people VALUES ('John Doe')")
- Rows are returned as
OrderedDict
objects instead of tuples. - Helper methods to simplify common patterns, e.g.
get_or_create
.
- e.g.,
- Easy schema changes: adding, removing, altering and reordering columns.
- Support for
decimal.Decimal
,datetime.time
andbool
database columns. - A command-line interface.
What isqlite is not
- isqlite is not an ORM. It does not map database rows to native objects. It just returns them as ordered dictionaries.
- isqlite is not a high-performance database engine. If you need maximal SQLite performance, you should use Python's built-in
sqlite3
library instead as isqlite imposes some overhead on top of it. - isqlite is not a generic database wrapper. It only supports and will only ever support SQLite as the underlying database engine.
isqlite is highly suitable for applications that use SQLite as an application file format. It is less suitable for circumstances in which traditional database engines are used, because if you eventually decide that you need to migrate from SQLite to a full-scale RDMS like MySQL or Postgres, you will have to rewrite all the code that uses isqlite.
API documentation
TODO
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
isqlite-0.1.tar.gz
(6.4 kB
view details)
Built Distribution
isqlite-0.1-py3-none-any.whl
(7.1 kB
view details)
File details
Details for the file isqlite-0.1.tar.gz
.
File metadata
- Download URL: isqlite-0.1.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.22.0 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 647b6a3f342d707abff877c94c9a03da311107feaead3445435650d154f4db97 |
|
MD5 | 3ca02e42ce939c10f105bac28bd27b86 |
|
BLAKE2b-256 | 90c0c4c2843e5676a0317a4f68ae9955e87e47ebabbfca55bbc4b884688923c3 |
File details
Details for the file isqlite-0.1-py3-none-any.whl
.
File metadata
- Download URL: isqlite-0.1-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.22.0 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 941b15f11dd4a596e81413fbb03fb5adf62387ec0b0ecaea350e2ba836804708 |
|
MD5 | 0567e508f44dea9c5bbd76035112736e |
|
BLAKE2b-256 | 217c2aae8ade9d9c6922456036002d974fb90a5c2fc99711d8b91fbfe37da689 |