Skip to main content

A unified, multi-engine async ORM for Python (MongoDB, PostgreSQL, MySQL, SQLite)

Project description

TabernacleORM 2.1.2 🐍⚡

The Async, Pydantic-powered ORM for Python.

TabernacleORM is a modern, lightweight, and fully async Object-Relational Mapper (ORM) designed for FastAPI and modern Python applications. It supports PostgreSQL, MySQL, SQLite, and MongoDB with a unified, expressive API.

Features

  • Pydantic V2 Native: Models are Pydantic models. Automatic validation, JSON serialization, and OpenAPI schema generation.
  • Fully Async: Built from the ground up for asyncio. No blocking IO.
  • Unified API: Switch between SQL and NoSQL databases without changing your business logic.
  • Relationships: OneToMany, ManyToMany, ForeignKey with lazy loading.
  • Fluent Query Builder: Write expressive queries like User.filter(User.age > 18).
  • Lifecycle Hooks: before_save, after_create, etc., for powerful automation.
  • Stateless Sessions: Thread-safe and concurrency-safe session management.
  • Read/Write Splitting: Native support for replicas and high availability.

Installation

pip install tabernacleorm
# For specific engines:
pip install tabernacleorm[postgresql]
pip install tabernacleorm[mysql]
pip install tabernacleorm[mongodb]

Quickstart

1. Define your Models

Since Tabernacle models are Pydantic models, defining schemas is intuitive:

from typing import Optional
from tabernacleorm import Model, connect
from tabernacleorm.fields import StringField, IntegerField, ForeignKey, OneToMany

# Connect to DB (Postgres, MySQL, or SQLite)
connect("sqlite:///:memory:")

class User(Model):
    name: str = StringField(max_length=50)
    age: int = IntegerField(default=18)
    
    # Relationships
    posts: list["Post"] = OneToMany("Post", back_populates="author_id")

    # Lifecycle Hooks
    async def before_save(self):
        self.name = self.name.capitalize()

class Post(Model):
    title: str = StringField()
    content: str = StringField()
    author_id: int = ForeignKey("User")

2. Create and Query

import asyncio

async def main():
    # Create Tables
    await User.get_engine().executeRaw(User.get_create_table_sql())
    await Post.get_engine().executeRaw(Post.get_create_table_sql())

    # Create Records
    user = await User.create(name="alice", age=30)
    await Post.create(title="Hello World", content="My first post", author_id=user.id)

    # Fluent Querying (Async)
    users = await User.filter(User.age > 20).all()
    
    # Eager Loading (New!)
    # Fetch users with their 'posts' in one go
    users_with_posts = await User.filter(User.age > 20).include("posts").all()

    # Lazy Loading (New!)
    my_posts = await user.fetch_related("posts")

    # Complex Filtering
    posts = await Post.filter(Post.title.startswith("Hello")).limit(5).all()

asyncio.run(main())

Documentation

  • FEATURES.md - Detailed guide on Mongoose-style features, advanced populate/include, and complex query operators.
  • REPLICA_QUICKSTART.md - Guide for using Read Replicas.

Advanced Features

Transactions

Use the session context manager for safe transactions:

engine = User.get_engine()
async with engine.transaction() as session:
    user = await User.create(name="Bob", age=25)
    # Pass session to save() to participate in transaction
    await Post.create(title="Intro", content="...", author_id=user.id, session=session)

Hooks

Available hooks:

  • before_save / after_save
  • before_create / after_create
  • before_delete / after_delete
class user(Model):
    password: str
    
    async def before_save(self):
        if not self.password.startswith("hash:"):
            self.password = f"hash:{self.password}"

Relationships

Define relationships using OneToMany, ManyToMany, or standard ForeignKey. Use await instance.fetch_related("field_name") to load them efficiently.


Built with ❤️ by the Tabernacle Team.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tabernacleorm-2.1.2.tar.gz (49.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tabernacleorm-2.1.2-py3-none-any.whl (63.1 kB view details)

Uploaded Python 3

File details

Details for the file tabernacleorm-2.1.2.tar.gz.

File metadata

  • Download URL: tabernacleorm-2.1.2.tar.gz
  • Upload date:
  • Size: 49.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for tabernacleorm-2.1.2.tar.gz
Algorithm Hash digest
SHA256 d9c45e825c4ce767011f75e8bbdb46a291744d22835229154398adb29b0feb45
MD5 aa29ead6b42ed2538c4ae15de8622e4b
BLAKE2b-256 0d9673722133479ceafa70592cd5447bcf4c477f0ee78b2540d7e2cc8f320658

See more details on using hashes here.

File details

Details for the file tabernacleorm-2.1.2-py3-none-any.whl.

File metadata

  • Download URL: tabernacleorm-2.1.2-py3-none-any.whl
  • Upload date:
  • Size: 63.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for tabernacleorm-2.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1bc8003fe534154f5edc8b2b27d1b5be877602f9e501be777a7b8259af38ed24
MD5 c5f6ef151a70b8ce21880a06b1df1c04
BLAKE2b-256 bdac39b5184313153265572d8ed6a0b69be760de1fe4d1c68813808f5f14cba8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page