A modular Python ORM with eager loading, migrations, caching, and multi-database adapters.
Project description
BlazeORM
Modular Python ORM with eager loading, migrations, security hardening, caching, performance tracking, and multi-database adapters (SQLite, PostgreSQL, MySQL).
Elevator Pitch
- Declarative models, typed fields, and relationships (FK/O2O/M2M) with forward/reverse accessors.
- Query builder + execution with
select_related/prefetch_related(nested, m2m-aware) to eliminate N+1 queries. - Persistence layer with transactions, unit-of-work, identity map, caching, hooks, and performance tracker.
- Strategy-based dialects and adapters with DSN parsing, redaction, parameter validation, and structured logging.
- Schema builder + migration engine with destructive-operation safeguards.
- Example app and comprehensive tests to guide usage.
Architecture
src/blazeorm/core: Models, fields, relations, registry, validation hooks.src/blazeorm/query:Qexpressions, SQL compiler,QuerySet, managers, eager loading.src/blazeorm/persistence:Session, identity map, UoW, transactions/savepoints, caching, hooks, m2m helpers.src/blazeorm/adapters: SQLite/Postgres/MySQL adapters,ConnectionConfig(DSN/env parsing, redaction).src/blazeorm/dialects: Quoting, limit/offset, placeholders per backend.src/blazeorm/schema: Schema builder, migration engine, destructive confirmations.src/blazeorm/security: DSN utilities and migration safety helpers.src/blazeorm/cache,src/blazeorm/hooks,src/blazeorm/utils: Caching backends, lifecycle hooks, logging, performance tracker.examples/: Blog app showing migrations, sessions, seeding, and querying.- Each subpackage has a README for deeper details.
Quickstart
from blazeorm.adapters import SQLiteAdapter, ConnectionConfig
from blazeorm.persistence import Session
from mymodels import User
session = Session(SQLiteAdapter(), connection_config=ConnectionConfig.from_dsn("sqlite:///app.db"))
with session:
users = list(session.query(User).prefetch_related("groups").order_by("id"))
for u in users:
print(u.id, u.name, [g.name for g in u.groups])
Defining Models
from blazeorm.core import Model, StringField, ForeignKey, ManyToManyField
class Author(Model):
name = StringField(nullable=False)
class Category(Model):
name = StringField(nullable=False)
class Article(Model):
title = StringField()
author = ForeignKey(Author, related_name="articles")
categories = ManyToManyField(Category, related_name="articles")
Schema & Migrations
from blazeorm.schema import SchemaBuilder, MigrationEngine, MigrationOperation
from blazeorm.dialects import SQLiteDialect
builder = SchemaBuilder(SQLiteDialect())
ops = [MigrationOperation(sql=builder.create_table_sql(Article))]
ops += [MigrationOperation(sql=stmt) for stmt in builder.create_many_to_many_sql(Article)]
engine = MigrationEngine(session.adapter, session.dialect)
engine.apply("blog", "0001", ops)
Eager Loading
select_related("author")for join-based eager loading of FK/O2O.prefetch_related("categories", "author__articles")for bulk loading m2m and nested relations.- Empty relations return empty lists; identity map/caches are reused during iteration.
Transactions, Hooks, and M2M Helpers
- Use
with session:orsession.transaction()for transactional scopes. - Hooks:
before/after_validate,before/after_save,before/after_delete,after_commitfired bySession. - Many-to-many helpers:
Session.add_m2m/remove_m2m/clear_m2mandModel.m2m_add/remove/clearmanage join rows and cache invalidation.
Security
- DSN parsing/redaction via
ConnectionConfig.from_dsn/from_env; credentials are redacted in logs. - Adapters validate placeholder counts; parameters are redacted when they appear sensitive.
- Migration engine logs destructive ops;
SchemaBuilder.drop_table_sqlwarns loudly.
Performance & Observability
- Structured logging with correlation IDs via
blazeorm.utils.logging.configure_logging. PerformanceTrackerrecords SQL timings and warns on N+1 patterns; inspect withSession.query_stats()orSession.export_query_stats(reset=...).- Slow-query logging uses a configurable threshold (
BLAZE_SLOW_QUERY_MSorSession(..., slow_query_ms=...)).
Example Blog App
- Located in
examples/blog_app. - Run
python -m examples.blog_app.demoor importbootstrap_session/seed_sample_data. - Additional library demo in
examples/library_appshowcasing many-to-many (writers/books/genres) with eager loading.
Installation
- From source:
pip install . - With optional extras:
pip install .[postgres]orpip install .[mysql]to pull driver dependencies. - From PyPI:
pip install blazeorm(published via tagged releases).
CI & Quality
- GitHub Actions run pytest plus ruff/black/isort/mypy checks.
- Note: mypy is currently configured to ignore type errors pending a full typing pass.
- Integration tests run in a dedicated CI job using Postgres/MySQL service containers with predefined DSNs.
- Build artifacts are validated in CI; publishing occurs on tag pushes matching
v*.
Testing
- Run the suite:
python -m pytest - Tests cover adapters, dialects, core models/relations, query compilation/execution, persistence, schema, security, caching, hooks, performance, and examples.
- Local integration tests: start containers with
docker compose -f docker-compose.integration.yml up -d, setBLAZE_POSTGRES_DSN=postgresql://blaze:blaze@localhost:5439/blazeormandBLAZE_MYSQL_DSN=mysql://blaze:blaze@localhost:3307/blazeorm, then runpython -m pytest tests/integration.
Further Reading
src/blazeorm/README.mdfor package overview.- Module READMEs under each subpackage for focused details (core, query, persistence, adapters, schema, security, cache, hooks, utils, examples).
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file blazeorm-0.1.0.tar.gz.
File metadata
- Download URL: blazeorm-0.1.0.tar.gz
- Upload date:
- Size: 42.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cd9507212f7ea78a8b71642d81dfaa8b716d10be5e0cdaff2d1da5f372f53f24
|
|
| MD5 |
d6cdbd81c7cb8f0e2abf0e4b35605fe7
|
|
| BLAKE2b-256 |
eb51d6fb16f6567dcd5b0609b0958eb2299e34fda0a2d15fcc24b410ec2b1522
|
Provenance
The following attestation bundles were made for blazeorm-0.1.0.tar.gz:
Publisher:
release.yml on KipianiNikoloz/BlazeORM
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
blazeorm-0.1.0.tar.gz -
Subject digest:
cd9507212f7ea78a8b71642d81dfaa8b716d10be5e0cdaff2d1da5f372f53f24 - Sigstore transparency entry: 868971871
- Sigstore integration time:
-
Permalink:
KipianiNikoloz/BlazeORM@de8abb721f32d2d244a051fd45e4bf88d1a77030 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/KipianiNikoloz
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@de8abb721f32d2d244a051fd45e4bf88d1a77030 -
Trigger Event:
push
-
Statement type:
File details
Details for the file blazeorm-0.1.0-py3-none-any.whl.
File metadata
- Download URL: blazeorm-0.1.0-py3-none-any.whl
- Upload date:
- Size: 55.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
901b382f30f2efb9ff7698da5a7269747f29375e14526aa8926a82826d9cc1c2
|
|
| MD5 |
7af960a6fd369460ae3f9396f39a682c
|
|
| BLAKE2b-256 |
13ede97e07281d5e0ce15caa835fab3caace85a512271e5f170c454f0dbb0364
|
Provenance
The following attestation bundles were made for blazeorm-0.1.0-py3-none-any.whl:
Publisher:
release.yml on KipianiNikoloz/BlazeORM
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
blazeorm-0.1.0-py3-none-any.whl -
Subject digest:
901b382f30f2efb9ff7698da5a7269747f29375e14526aa8926a82826d9cc1c2 - Sigstore transparency entry: 868971874
- Sigstore integration time:
-
Permalink:
KipianiNikoloz/BlazeORM@de8abb721f32d2d244a051fd45e4bf88d1a77030 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/KipianiNikoloz
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@de8abb721f32d2d244a051fd45e4bf88d1a77030 -
Trigger Event:
push
-
Statement type: