Getting Started¶
Installation¶
Install sqbooster from PyPI:
pip install sqbooster
Optional backends:
pip install sqbooster[postgresql] # PostgreSQL support
pip install sqbooster[redis] # Redis support
pip install sqbooster[mongodb] # MongoDB support
pip install sqbooster[all] # Everything
Quick Example¶
import sqbooster
# Create a database
db = sqbooster.sqlite("app.db")
# Tables are created automatically from the data you insert
db.add("users", {"name": "Alice", "age": 30, "email": "alice@example.com"})
db.add("users", {"name": "Bob", "age": 25, "email": "bob@example.com"})
# Query with filters
adults = db.find("users", age__gte=28, order_by="name")
# Returns: [{'id': 1, 'name': 'Alice', 'age': 30, ...}]
Concepts¶
Backends are the database drivers. sqbooster supports:
SQLiteBackend– local file-based, zero configPostgreSQLBackend– production SQLJSONFileDatabase– JSON filePickleFileDatabase– pickle fileRedisDatabase– Redis serverMongoDatabase– MongoDB server
Columns define table structure with typed columns:
from sqbooster.schema import Column
from sqbooster.types import Integer, Text, Float, Boolean, Blob, JSON
Queries are chainable builders:
results = (db.query("users")
.filter(age__gte=18, name__contains="a")
.order_by("-age")
.limit(10)
.offset(0)
.all())
Context Manager¶
All clients support the with statement:
import sqbooster
with sqbooster.sqlite("app.db") as db:
db.add("items", {"name": "Widget"})
# Connection is automatically closed