Skip to main content

Lightweight ORM for MySQL and YugabyteDB

Project description

mydborm

PyPI version Python License: MIT

mydborm is a lightweight, developer-friendly ORM for MySQL 8+ and YugabyteDB (YSQL).
Zero bloat. Declarative models. Full CRUD. Schema migrations. CLI included.


Features

  • Declarative model definitions with field validation
  • Full CRUD — create, get, all, filter, update, delete, count, exists
  • Schema migration engine with history tracking
  • Dual database support — MySQL and YugabyteDB
  • Thread-safe connection manager with context manager support
  • DATABASE_URL environment variable support
  • Rich CLI — ping, inspect, tables, migrate
  • Zero mandatory dependencies beyond database drivers
  • Python 3.8+ compatible, platform independent

Installation

pip install mydborm

With CLI support:

pip install mydborm[cli]

Quickstart

1. Configure connection

from mydborm import db

# Direct config
db.configure(
    dialect  = "mysql",       # or "yugabyte"
    host     = "127.0.0.1",
    port     = 3306,
    user     = "root",
    password = "yourpassword",
    database = "mydb",
)

# Or via environment variable
# export DATABASE_URL="mysql://root:password@localhost:3306/mydb"
db.from_env()

2. Define models

from mydborm import BaseModel, IntField, StrField, BoolField, FloatField

class User(BaseModel):
    __tablename__ = "users"
    id       = IntField(primary_key=True)
    username = StrField(max_length=100, nullable=False)
    email    = StrField(max_length=255, nullable=False, unique=True)
    active   = BoolField(default=True)

class Product(BaseModel):
    __tablename__ = "products"
    id     = IntField(primary_key=True)
    name   = StrField(max_length=100, nullable=False)
    price  = FloatField(nullable=False)
    active = BoolField(default=True)

3. Run migrations

from mydborm.migrations import migrate, migration_status

migrate(User,    description="Create users table")
migrate(Product, description="Create products table")

for m in migration_status():
    print(m["description"], "→", "Applied" if not m["rolled_back"] else "Rolled back")

4. CRUD operations

# Create
uid = User.create(username="alice", email="alice@example.com", active=True)

# Read
user  = User.get(id=uid)
users = User.all()
devs  = User.filter(active=True)

# Update
User.update({"active": False}, id=uid)

# Delete
User.delete(id=uid)

# Aggregate
count  = User.count()
exists = User.exists(email="alice@example.com")

Field types

Field SQL Type (MySQL) SQL Type (YugabyteDB)
IntField INT INTEGER
StrField VARCHAR(n) VARCHAR(n)
TextField TEXT TEXT
BoolField TINYINT(1) BOOLEAN
FloatField FLOAT FLOAT
DecimalField DECIMAL(p,s) DECIMAL(p,s)
DateField DATE DATE
DateTimeField DATETIME TIMESTAMP
JSONField JSON JSONB
ForeignKeyField INT INTEGER

CLI commands

# Show version
mydborm version

# Test connectivity
mydborm ping --dialect mysql --host 127.0.0.1 --port 3306 --password root

# List all tables
mydborm tables --dialect mysql --port 3306 --password root

# Inspect schema
mydborm inspect --dialect mysql --port 3306 --password root

# Run migration for a model
mydborm migrate --dialect mysql --port 3306 --password root \
  --model myapp.models.User

# Show migration history
mydborm migrate --status --dialect mysql --port 3306 --password root

# Rollback last migration
mydborm migrate --rollback --dialect mysql --port 3306 --password root \
  --model myapp.models.User

YugabyteDB support

db.configure(
    dialect  = "yugabyte",
    host     = "127.0.0.1",
    port     = 5433,
    user     = "yugabyte",
    password = "yugabyte",
    database = "yugabyte",
)

mydborm automatically uses YSQL-compatible SQL:

  • Double-quoted identifiers
  • SERIAL primary keys
  • Native BOOLEAN
  • JSONB instead of JSON
  • RETURNING id on INSERT

Docker quickstart

services:
  mysql:
    image: mysql:8.0
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: mydb
    ports:
      - "3306:3306"

  yugabyte:
    image: yugabytedb/yugabyte:latest
    command: bash -c "bin/yugabyted start --daemon=false"
    ports:
      - "5433:5433"
docker compose up -d

Project structure

mydborm/
├── mydborm/
│   ├── __init__.py       # Public API
│   ├── db.py             # Connection manager
│   ├── fields.py         # Field types
│   ├── model.py          # BaseModel + CRUD
│   ├── migrations.py     # Schema migration engine
│   ├── cli.py            # CLI commands
│   └── dialects/
│       ├── mysql.py      # MySQL SQL generation
│       └── yugabyte.py   # YugabyteDB SQL generation
├── tests/                # pytest test suite
├── examples/             # Usage examples
└── pyproject.toml

Running tests

pip install mydborm[dev]
pytest

Author

Atikrant Upadhye
PyPI · GitHub


License

MIT License — see LICENSE for details.

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

mydborm-0.4.0.tar.gz (38.1 kB view details)

Uploaded Source

Built Distribution

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

mydborm-0.4.0-py3-none-any.whl (30.7 kB view details)

Uploaded Python 3

File details

Details for the file mydborm-0.4.0.tar.gz.

File metadata

  • Download URL: mydborm-0.4.0.tar.gz
  • Upload date:
  • Size: 38.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mydborm-0.4.0.tar.gz
Algorithm Hash digest
SHA256 5d52c7d2cdcebea0c58ac218a23ca0fa63459d08dfce095cfeec9f2afe53ca7e
MD5 7c6e47f8aeb4b59903d899cb832b7dce
BLAKE2b-256 4b920bc64aeecae20853f9fadfa30c0b652af3ee34ce863a9094493e1114075c

See more details on using hashes here.

Provenance

The following attestation bundles were made for mydborm-0.4.0.tar.gz:

Publisher: ci.yml on codengers/mydborm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mydborm-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: mydborm-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 30.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mydborm-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f94e3a194550fbf05b83021fba05d9d7ad4e9fa79fcf45ed2a3ecfd568705891
MD5 88541d35035acceaca99b48e40450ab8
BLAKE2b-256 6419014906e213f4130565b53c717240b51dbe849c9c5cc11f238ac60b8df7a2

See more details on using hashes here.

Provenance

The following attestation bundles were made for mydborm-0.4.0-py3-none-any.whl:

Publisher: ci.yml on codengers/mydborm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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