An improved Python interface to SQLite
Project description
isqlite is an improved Python interface to SQLite. It has a more convenient API, support for database migrations, and a command-line interface.
WARNING: isqlite is in beta. Not all features described here have been implemented yet. If you want to try it out, back up your data first.
from isqlite import Database
with Database(":memory:") as db:
# Create the tables defined in the database. This only needs to be done once.
db.create_table("teams", "id INTEGER NOT NULL PRIMARY KEY", "name TEXT NOT NULL")
db.create_table(
"employees",
"id INTEGER NOT NULL PRIMARY KEY",
"name TEXT NOT NULL",
"age INTEGER",
"team INTEGER REFERENCES teams",
)
# Create a new row in the database.
pk = db.create("employees", {"name": "John Doe", "age": 30})
# Retrieve the row as an OrderedDict.
person = db.get_by_rowid("employees", pk)
print(person["name"], person["age"])
# Update the row.
db.update_by_rowid("employees", pk, {"age": 35})
# Delete the row.
db.delete_by_rowid("employees", pk)
# Filter rows with a query.
employees = db.list(
"employees",
where="name LIKE :name_pattern AND age > 40",
values={"name_pattern": "John%"},
)
# 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.,
- Automated database migrations: adding, removing, altering and reordering columns.
- Support for
decimal.Decimal
,datetime.time
andbool
database columns. - A command-line interface.
isqlite is highly suitable for applications that use SQLite as an application file format, and for ad hoc operations and migrations on existing SQLite databases. It is less suitable for circumstances in which traditional database engines are used (e.g., web applications), 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.
Compared to SQLAlchemy
SQLAlchemy is a Python SQL toolkit and ORM and one of the most popular standalone SQL libraries for Python.
- isqlite aims to be a replacement for Python's sqlite3 standard library, not a general-purpose database wrapper like SQLAlchemy. It does not support and will never support any database engine other than SQLite.
- isqlite has a small and easy-to-understand API.
- isqlite supports database migrations out of the box, while SQLAlchemy requires using an extension like Alembic.
- isqlite is not an object relational mapper (ORM). It does not map database row to native Python objects. It just returns them as regular ordered dictionaries.
- Note that SQLAlchemy includes an ORM but does not require that you use it.
- isqlite comes with a command-line interface.
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
Built Distribution
File details
Details for the file isqlite-0.4.4.tar.gz
.
File metadata
- Download URL: isqlite-0.4.4.tar.gz
- Upload date:
- Size: 9.6 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 | dd0c9f055abcca02c3090528735e77891ff0d68e64b65396cafdb021b00df625 |
|
MD5 | 9433c876700ef3473a7c055950b3854a |
|
BLAKE2b-256 | 17c83c6dd81281f418a8200bc4111f9eeccfb8c56151f3bd89e0322352ff0637 |
File details
Details for the file isqlite-0.4.4-py3-none-any.whl
.
File metadata
- Download URL: isqlite-0.4.4-py3-none-any.whl
- Upload date:
- Size: 15.0 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 | 2d9e3e1e82b502c3882f9a87939ec518a7a7213ae01117a38ee76f4159278c43 |
|
MD5 | bcecc56ca610504ee48b40f55a88fd64 |
|
BLAKE2b-256 | d4767572691e801e78187c06395747340ab133fcad844799d22eb5a66fa8bb20 |