Knexpy
A query builder for SQLite3 based on Knexjs. Knexpy compiles chainable, parameterized SQL for you, so you never interpolate a value into a query string.
Features
- Fluent query building —
select,from_, aliases,distinct, everywhere_*variant,group_by/having,order_by(withNULLS FIRST/LAST),limit/offset, joins and subqueries. - Aggregates —
count,sum,avg,min,max. - Writes —
insert,insert_or_ignore,upsert,update,delete, and batchinsert_json(accepts dicts, dataclasses and pydantic models, with chunked transactions and amappinghook). - Type checking —
Knex(..., type_check=True)validates values against column types on insert/update. - Transactions — context-manager support, atomic batch inserts, and manual
begin/commit/rollback. - Typed row models —
db.select(...).as_(User).all()returnslist[User]from dataclasses orTypedDicts. - Pagination & inspection —
paginate()andexplain()/explain_query_plan(). - Schema & introspection — create/alter/drop tables and indexes,
tables,columns,foreign_keys, andbackup. - Migrations — a runner (
knexpy migrateCLI +Knex.run_migrations). - Hooks — observe or intercept operations (
before_*/after_*events). - Async facade —
AsyncKnexreuses the same builder overaiosqlite. - Connection factories —
from_connection,make_db, and query logging.
Installation
pip install knexpy
For the async facade, install the optional extra:
pip install "knexpy[async]"
Quick start
from Knexpy import Field, Knex
db = Knex(":memory:", type_check=True) # pass a path to persist to a file
db.table("users", [Field.varchar("name"), Field.integer("age", {"null": True})])
db.insert_json(
"users",
[
{"name": "Ada", "age": 36},
{"name": "Lin", "age": 45},
{"name": "Grace", "age": 40},
],
)
rows = db.select("id", "name").from_("users").order_by("name").query()
# [{"id": "...", "name": "Ada"}, ...]
When creating a table,
id,created_atandmodified_atare added automatically.idis a collision-resistant random hex string.
Examples
Runnable examples live in examples/ and cover the full feature
set:
| File | Shows |
|---|---|
quickstart.py |
connect, schema, insert, query, CRUD helpers |
query_building.py |
aliases, aggregates, grouping, nulls ordering, raw SQL |
joins_where.py |
joins and every where_* clause |
writes.py |
insert, upsert, chunked/mapped inserts, update/delete |
transactions.py |
context manager, atomic batches, manual control |
schema_introspection.py |
DDL, introspection, backup |
row_models.py |
typed rows via as_(Model) |
pagination_explain.py |
paginate, explain |
hooks.py |
observing and intercepting operations |
migrations.py |
versioned schema changes |
async_example.py |
the AsyncKnex facade |
connection_factory.py |
from_connection, make_db, logging |
You can report bugs and discuss features on the GitHub issues page. For the full API reference check Readthedocs.
Metadata
Release files for knexpy 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| knexpy-1.0.0.tar.gz | 681.4 kB | Without provenance | Details for knexpy-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| knexpy-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for knexpy-1.0.0-py3-none-any.whl |
Total release size: 735.3 kB
Release files / knexpy-1.0.0.tar.gz
| Download URL | knexpy-1.0.0.tar.gz |
|---|---|
| Size | 681.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6bdb3b6ab28c1cd90bd367f16b96283e45a303bbe2866cb56da232d72aa6ecef
|
|
BLAKE2b-256 checksum How to use checksums |
9d0e259e89cf5c7ace4fa3c9cd539b22eb3804f989a6abb0df5e5a8308b471b6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.16
|
Release files / knexpy-1.0.0-py3-none-any.whl
| Download URL | knexpy-1.0.0-py3-none-any.whl |
|---|---|
| Size | 53.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0019ced111ec45a6127450a0122670841f78febf1f71441792bc8b67812ff5a7
|
|
BLAKE2b-256 checksum How to use checksums |
ccb2823f9ebb6e0c00651f27315ceb5c09abc7c18b712aa11c301fd8fd84f816
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.16
|
Security for knexpy 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.