sqlrules-sqlite
SQLite backend provider for SQLRules. The package version follows the core 2.x line.
Install
pip install "sqlrules>=2,<3" "sqlrules-sqlite>=2,<3"
Use
from typing import Annotated, Any
from pydantic import Field
from sqlalchemy import Column, JSON, MetaData, String, Table, create_engine, event
from sqlrules import Compiler, JsonContains, RuleSchema, where
from sqlrules_sqlite import SQLitePlugin, register_sqlite_functions
rows = Table("rows", MetaData(), Column("name", String), Column("meta", JSON))
class RowRules(RuleSchema):
name: Annotated[str, Field(pattern=r"^A")]
meta: Annotated[dict[str, Any], JsonContains({"active": True})]
engine = create_engine("sqlite:///app.db")
event.listen(
engine,
"connect",
lambda dbapi_connection, _: register_sqlite_functions(dbapi_connection),
)
compiled = Compiler(plugins=[SQLitePlugin()]).compile(RowRules, rows)
statement = rows.select().where(*where(compiled))
Capabilities
- Runtime
typeof()checks for SQLite integer, real, and text storage classes - Lax text-to-int/float coercion and bool values stored as integer 0 or 1
- JSON1 helpers that treat malformed documents as non-matches
REGEXPpattern matching and Unicode-aware string length throughregister_sqlite_functions()
Strict bool, exact Decimal, and SQLAlchemy-emulated date/time/UUID values need
explicit storage adapters and raise CapabilityError. Text coercion, patterns,
and string length constraints require the registered SQLRules SQLite functions
on each connection. register_regexp() remains as a backward-compatible alias.
See the
type support matrix.
Pattern cost
register_sqlite_functions() runs Python's re.search for each regex row and
Python's len() for each length-checked string row. Untrusted patterns can
cause CPU denial of service through catastrophic backtracking. Prefer static
or allowlisted patterns. See the SQLRules
security notes.
Metadata
Release files for sqlrules-sqlite 2.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 | |
|---|---|---|---|
| sqlrules_sqlite-2.0.0.tar.gz | 6.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sqlrules_sqlite-2.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.5 kB
Release files / sqlrules_sqlite-2.0.0.tar.gz
| Download URL | sqlrules_sqlite-2.0.0.tar.gz |
|---|---|
| Size | 6.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4f754f96d8b7563dedad7cec78527bcd661fbe9571c152c89d1cefb4bb72115c
|
|
BLAKE2b-256 checksum How to use checksums |
6d63a2ebba88d238f3cb74b8ae89ea203100d9b0cec77094c77db0cd4955e29b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / sqlrules_sqlite-2.0.0-py3-none-any.whl
| Download URL | sqlrules_sqlite-2.0.0-py3-none-any.whl |
|---|---|
| Size | 8.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ac21051b3bae83d5fdeaef70ea32e6ff45ae886b9ab9e327883300b94108cd02
|
|
BLAKE2b-256 checksum How to use checksums |
5ee978e282720af98fed8c1f1bf834cdbfb812f2d7c9e05249fa8a1f7cfa5da7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|