Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

ZCore Logo

A pragmatic and complementary architectural layer built on top of FastAPI.
Standardize your structure, protect your data, and manage atomic transactions—without losing your development freedom.

PyPI License CI Documentation Python Versions


What is ZCore?

ZCore is not a framework that hides FastAPI — it is the chassis that stabilizes it.

While FastAPI provides a high-performance engine for HTTP, it leaves the architecture of medium-to-large applications entirely to the developer. ZCore fills that gap with:

  • 🔐 Context-Aware Data Masking — Write one schema; sensitive fields are automatically pruned per-user across validation, serialization, and OpenAPI specs.
  • 🔗 Atomic Unit of Work — Coordinate multi-repository operations into all-or-nothing transactions with deferred event dispatching.
  • ⚡ Scoped Dependency Injection — High-performance constructor auto-wiring for Singleton, Transient, and request-scoped dependencies.
  • 🏗️ Modular Plugin Architecture — Organize business domains into decoupled plugins with topological dependency ordering.
  • 🔍 Secure Dynamic Search Engine — Nested JSON filters, eager loading, cursor/offset pagination, and column-level access controls.
  • 📦 Zero-Boilerplate CLI — From pip install to running secure CRUD endpoints in under two minutes.

Why ZCore?

Concern Raw FastAPI With ZCore
Endpoint Scaffolding Manually write 7+ routes and handlers per model One BaseRouter class $\rightarrow$ 7 secure endpoints out-of-the-box
Data Leakage Multiple Pydantic models per role; manual conditionals Zchema auto-prunes restricted fields per active context
Database Transactions Scattered commit() / rollback() calls UnitOfWork guarantees atomicity + post-commit domain events
Dependency Wiring Deeply nested, verbose Depends() parameter chains Clean constructor auto-wiring via IoC container + Inject[T]
Search & Pagination Hand-crafted SQL parsing per endpoint Declarative JSON filters + keyset cursor and offset pagination
Project Layout No standard; every team reinvents the wheel zc init + zc startapp — decoupled domain modularity
Startup Orchestration Fragile @app.on_event chains Plugin protocol with dependency DAG $\rightarrow$ topological sorting

⚡ Quick Start

1. Install

pip install fastapi-zcore-framework[all]

2. Scaffold

zc init my_app && cd my_app
zc startapp tasks --template

3. Define

Open tasks/models.py:

import uuid
from zcore import Base
from sqlalchemy.orm import Mapped, mapped_column

class Task(Base):
    __tablename__ = "tasks"
    
    id: Mapped[uuid.UUID] = mapped_column(primary_key=True, default=uuid.uuid4)
    title: Mapped[str]
    is_completed: Mapped[bool] = mapped_column(default=False)

4. Run

zc run

Your API is live at http://127.0.0.1:8000 with 6 CRUD endpoints and dynamic search ready.

📖 Full walkthrough: Quick Start Guide


🏛️ Core Pillars

🔐 Context Shielding (Zchema)

Write a single schema. ZCore dynamically prunes input fields (preventing mass assignment) and output fields (preventing data leakage) based on the active user's permission scopes.

import uuid
from zcore import Zchema

class TaskResponse(Zchema):
    __model__ = "tasks"
    
    id: uuid.UUID
    title: str
    salary: float  # Automatically pruned if unauthorized

When an authenticated user lacks view permissions for tasks.salary, the field vanishes from both JSON serialization and the OpenAPI schema — with zero manual if statements.

🔗 Atomic Transactions (Unit of Work)

Group multiple repository operations into a single atomic unit. Events are buffered and dispatched only after a successful database commit. If any operation fails, the entire transaction rolls back and pending events are discarded.

from zcore import UnitOfWork

async with UnitOfWork(session, dispatcher) as uow:
    order = await order_repo.create(order_data)
    await inventory_repo.decrement_stock(product_id, quantity)
    
    # Queued safely: Dispatches ONLY after the DB commit succeeds!
    uow.register_event("order.completed", {"order_id": str(order.id)})
⚡ Scoped Dependency Injection

Inject services, repositories, and infrastructure dependencies via standard constructor type hints. ZCore's IoC container auto-wires them dynamically and purges request-scoped instances after each response.

from zcore import BaseService

class TaskService(BaseService[Task]):
    # Pure Python constructor: Auto-wired by ZCore's DI container
    def __init__(self, repository: TaskRepo):
        super().__init__(model=Task, repository=repository)
🏗️ Modular Plugin System

Each domain is an isolated Plugin conforming to a strict lifecycle contract. The Kernel resolves dependencies topologically using a Directed Acyclic Graph (DAG) to guarantee deterministic startup and shutdown sequences.

from fastapi import FastAPI
from zcore import Plugin
from .routers import router_instance

class TasksPlugin(Plugin):
    name = "tasks"
    version = "0.1.0"
    dependencies = ["auth"]  # Requires AuthPlugin to start first

    def setup(self, app: FastAPI) -> None:
        app.include_router(router_instance.router)

    async def on_startup(self) -> None:
        pass
🔍 Secure Dynamic Search Engine

A dynamic query builder that translates nested JSON filters into safe SQLAlchemy 2.0 AST queries — featuring relation eager-loading, keyset cursor pagination, and depth-limit protection against DoS attacks.

{
  "filters": [
    {
      "op": "and",
      "items": [
        { "field": "is_completed", "op": "eq", "value": false },
        { "field": "title", "op": "ilike", "value": "urgent" }
      ]
    }
  ],
  "include": ["assignee"],
  "sort": [
    { "field": "created_at", "order": "desc" }
  ],
  "page": 1,
  "size": 20
}
📦 CLI Scaffolding

Stop writing boilerplate. The zc CLI generates consistent, production-ready domain modules and environment templates with a single command.

Command Purpose
zc init <name> Create a new project with settings, .env, and main.py
zc startapp <name> Scaffold an empty domain module
zc startapp <name> --template Scaffold with full Model, Schema, Repo, Service, Router, and Plugin boilerplate
zc run Launch Uvicorn with auto-reload and environment-aware config
zc gensecret Generate a 64-character cryptographically secure secret key
zc genenv Introspect registered Settings classes and scaffold .env.example

📖 Documentation

Resource Description
🚀 Quick Start Build a complete Task Manager API from scratch
📚 10-Step Quick Learn Deep dive into each architectural layer step-by-step
🔧 How-To Guides Pagination, search, file uploads, caching, and testing
🏛️ Core Concepts Deep dive into DI, Kernel, Security, UoW, and Zchema
📜 API Reference Complete class and method specifications
🕒 Changelog Release notes, breaking changes, and migrations

🤝 Contributing

Contributions are welcome! Please read our guidelines before submitting a PR.

  • Issues: Bug reports and feature requests via GitHub Issues
  • PRs: Open a pull request with a clear description of the change
  • Local Setup: pip install -e ".[all]" and run hatch test to verify

📄 License

ZCore is licensed under the Apache License 2.0.
See LICENSE for details.


Built with ☕ and architectural rigor by Ali Alf Ostovar.

Metadata

Release files for fastapi-zcore-framework 0.1.0b7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastapi-zcore-framework 0.1.0b7
File Size Uploaded
fastapi_zcore_framework-0.1.0b7.tar.gz 115.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fastapi-zcore-framework 0.1.0b7
File Interpreter ABI Platform
fastapi_zcore_framework-0.1.0b7-py3-none-any.whl Python 3 none any Details

Total release size: 206.7 kB

Release files / fastapi_zcore_framework-0.1.0b7.tar.gz

Download URL fastapi_zcore_framework-0.1.0b7.tar.gz
Size 115.4 kB
Tags Source
SHA-256 checksum
How to use checksums
5c1778e9d23221c2b348357e400d6273daf3d06d483e131ea890b1a1a8ce5176
BLAKE2b-256 checksum
How to use checksums
f436d7e89b8f477d9039bd8e327b377df62bdaa2802ba08c8f92fe130b2eddcb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 16, 2026.

Transparency log

Release files / fastapi_zcore_framework-0.1.0b7-py3-none-any.whl

Download URL fastapi_zcore_framework-0.1.0b7-py3-none-any.whl
Size 91.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f5b54d622a5fdad1a8f8481b345b5c1061ed4b1d4cf15c50d6c0930ba8fdca6c
BLAKE2b-256 checksum
How to use checksums
39a0cd59c3d1d0e6c67513f5691e268ef540c3a1e21200718f0d64d5b2e2a7eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 16, 2026.

Transparency log
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page