Skip to main content

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 Operation registries and "Bound Instances" ("The Bloodline").

PyPI version Python 3.10+ License: MIT


🚀 Why Opyra

  • Registry Pattern: Explicitly register schemas with an Operation engine. No magic globals.
  • Bound Instances: Objects know where they belong. user.save() just works because the user carries "The Bloodline" (the engine reference).
  • Dirty Tracking: Automatic change detection. Calling .save() only updates what changed (efficient UPDATE vs INSERT).
  • 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 Operation

Create an engine and register your models. This is your "Database Context".

from opyra import Operation

op = Operation("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 = Operation(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

opyra-0.0.4.tar.gz (14.9 kB view details)

Uploaded Source

Built Distribution

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

opyra-0.0.4-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

File details

Details for the file opyra-0.0.4.tar.gz.

File metadata

  • Download URL: opyra-0.0.4.tar.gz
  • Upload date:
  • Size: 14.9 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

Hashes for opyra-0.0.4.tar.gz
Algorithm Hash digest
SHA256 9d1d28d43d92241963919d34c77714fa34dcd072561c727195373b4450d7f81b
MD5 7aa5dcc1d73f1017aa35375e4cb0aee4
BLAKE2b-256 01a1aa86b7f46b25b712937e854d248df3febfcc0f8723457f71562ff69d2e39

See more details on using hashes here.

File details

Details for the file opyra-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: opyra-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 17.6 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

Hashes for opyra-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b7b3f56239f70715d17b65816dc38f6eedb96dc71c72b54df42752a254cecff1
MD5 564c4d066e759104e469f2b87cbd7422
BLAKE2b-256 26e2d38f1d0ac5f1202628f4fcc5c0e15a14dc243ed0e1c3c43ab3a997bb08d8

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