Unified database operations
Project description
Opyra
The "Buttery Smooth" Registry-Based ORM for Python.
Opyraa next-generation data layer built on top of msgspec. It unifies SQL (Postgres, SQLite) and NoSQL (MongoDB) under a single, ultra-fast, type-safe API using the Registry Pattern.
It eliminates "Global State" and "Boilerplate Fatigue" by using explicit Opyration registries and "Bound Instances" ("The Base").
🚀 Why Opyra
- Registry Pattern: Explicitly register schemas with an
Opyrationengine. No magic globals. - Bound Instances: Objects know where they belong.
user.save()just works because the user carries "The Base" (the engine reference). - Dirty Tracking: Automatic change detection. Calling
.save()only updates what changed (efficientUPDATEvsINSERT). - Universal API: Switch from SQLite to Postgres to Mongo without rewriting your model logic.
- Blazing Fast: Built on
msgspec(faster than Pydantic/JSON) and native async drivers (asyncpg,motor).
📦 Installation
pip install opyra
# Install drivers as needed:
pip install opyra[postgres] # installs asyncpg
pip install opyra[mongo] # installs motor
pip install opyra[sqlite] # installs aiosqlite
⚡ Quickstart
1. Define your Schema
Inherit from Table (SQL) or Document (NoSQL). These are pure data structures (msgspec.Struct).
from opyra import Table, Document
class User(Table):
id: int
name: str
email: str
2. Initialize the Opyration
Create an engine and register your models. This is your "Database Context".
from opyra import Opyration
op = Opyration("postgres://user:pass@localhost:5432/mydb")
op.register(User)
# Now available as 'op.user' (snake_case automation)
3. Use it!
Factory Access (Creating Data):
Use op.user(...) to create a "Bound Instance".
# Create alice attached to this engine
alice = op.user(name="Alice", email="alice@example.com")
# Save detects this is a NEW record (no ID) -> INSERT
await alice.save()
print(alice.id) # ID is auto-populated
Repository Access (Querying Data):
Use op.user.find(...) to search.
# Find by ID
user = await op.user.find(1)
# Find by Template (Fluent API)
users = await op.user(name="Alice").find()
Dirty Tracking (Updating Data): Modify fields naturally. Opyracks changes.
user.name = "Alice Wonder"
# Save detects EXISTING record + Dirty Fields -> UPDATE users SET name='Alice Wonder' WHERE id=1
await user.save()
🏗️ Web Framework Integration
Opyradesigned for dependency injection.
# app.py
op = Opyration(os.getenv("DATABASE_URL"))
op.register(User)
op.register(Post)
# Inject into your app
app.keep('op', op)
# handling request
async def get_user(req, res, ctx):
op = ctx.peek('op')
user = await op.user.find(int(req.params['id']))
res.body = user
License
MIT
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
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 opyra-0.0.6.tar.gz.
File metadata
- Download URL: opyra-0.0.6.tar.gz
- Upload date:
- Size: 19.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.12.3 Linux/6.14.0-37-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8a7dfc1ee9e90fe77298e5c87487a1064a87d8b59049ef212172a04d9e4ee6b6
|
|
| MD5 |
e744e1cca1c3c5f681b13e5b0fdbe2c6
|
|
| BLAKE2b-256 |
2cedbc27883b6f7cb84d1ec97b60618e945ffa5db5adff462e9d128758592d94
|
File details
Details for the file opyra-0.0.6-py3-none-any.whl.
File metadata
- Download URL: opyra-0.0.6-py3-none-any.whl
- Upload date:
- Size: 22.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.12.3 Linux/6.14.0-37-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
773325409b561c80664d54408ed4bd9103558878550ebc9df24c112834dff0a4
|
|
| MD5 |
353c0ba298b7369ad0f5184f1271991a
|
|
| BLAKE2b-256 |
05d9c8373423fab7c45419d38eb71b4932dc61a28f897f97afa975942726ad03
|