larzsql
An injection-safe SQL query builder. Pure Python, zero dependencies.
Concatenating SQL is how injection happens. larzsql builds SELECT/INSERT/UPDATE/
DELETE where every value becomes a bound parameter (never interpolated) and
every table/column name is validated as a plain identifier - so a value or a name
can't smuggle in SQL. You get back (sql, params) ready for your DB-API driver.
from larzsql import select, insert, update, delete
select("id", "name").from_("users").where(active=True, age__gte=18) \
.order_by("-created").limit(10).build()
# ('SELECT id, name FROM users WHERE active = ? AND age >= ? ORDER BY created DESC LIMIT 10',
# [True, 18])
insert("users").values(name="Ada", email="a@b.com").build()
# ('INSERT INTO users (name, email) VALUES (?, ?)', ['Ada', 'a@b.com'])
Why
- Injection-safe by construction. Values are always bound parameters - even a
"1; DROP TABLE users; --"value ends up inparams, never in the SQL text - and identifiers are validated against a strict pattern, sofrom_("users; DROP ...")raises instead of executing. - Fluent and complete.
wherewith Django-style lookups (age__gte,id__in,deleted__isnull) or raw fragments,join/left_join,order_by(-colfor DESC),limit/offset, plus INSERT/UPDATE/DELETE. - Driver-agnostic.
build(paramstyle="?")for sqlite or"%s"for psycopg2/MySQL. - Not an ORM. It builds strings + params; you run them. Zero dependencies, pairs with larzdb / larzmigrate.
Install
pip install larzsql
Usage
from larzsql import select, insert, update, delete
select("*").from_("orders").where(status__in=["paid", "shipped"]).build()
select("u.id", "o.total").from_("users").left_join("orders", "orders.user_id = users.id").build()
update("users").set(active=False).where(id=5).build()
delete("sessions").where(expires__lt=now).build()
sql, params = select("*").from_("t").where(id=1).build(paramstyle="%s")
cursor.execute(sql, params)
Tests
python -m unittest discover -s tests -v # 17 tests incl. injection safety
The Larz stack
One of 30+ pure-Python, zero-dependency libraries at github.com/larz-scripter.
License
MIT (c) larz-scripter
Metadata
Release files for larzsql 0.1.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 | |
|---|---|---|---|---|
| larzsql-0.1.0.tar.gz | 6.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| larzsql-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.2 kB
Release files / larzsql-0.1.0.tar.gz
| Download URL | larzsql-0.1.0.tar.gz |
|---|---|
| Size | 6.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fd8723b3af217a33b5820627c00c8e85fb6e976c4ef6681eced0072b183337e4
|
|
BLAKE2b-256 checksum How to use checksums |
cd65f1f2b100cb13d1d71b15df3aa4370e28315f42475cb2c5effe7b226a783c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Release files / larzsql-0.1.0-py3-none-any.whl
| Download URL | larzsql-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
66cf0f2d4be06d18eb48ac073ff185845ed359fa2154f3f10c4ce33de9ad066f
|
|
BLAKE2b-256 checksum How to use checksums |
351ca3a019dbb68ef6ce4a3f40c69b28d9839f596a1decf8a7af50d5c2cacb13
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Security for larzsql 0.1.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.