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.3.0.tar.gz (28.9 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.3.0-py3-none-any.whl (24.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for mydborm-0.3.0.tar.gz
Algorithm Hash digest
SHA256 622a92daeef3bd235ddd0075acbef90beae599aaf5207c99eb95ee353fd40392
MD5 5325aeff8c855765e48a23334e4e3e21
BLAKE2b-256 1c44abb6cc989082ef1e0c3ef85f20eb475d7ab856bf45f234eca73403af0029

See more details on using hashes here.

Provenance

The following attestation bundles were made for mydborm-0.3.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.3.0-py3-none-any.whl.

File metadata

  • Download URL: mydborm-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 24.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.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 09debf47a74caa1a86644c954ac740660e6b81a65d09e6a67cb0f9821428b145
MD5 08fbd0c49b9f3c17a76ff612b9f9bd4a
BLAKE2b-256 a4e199bff965e96464174b93dabbfc7f0ed174a562d7a50d4dab4260f1e64e59

See more details on using hashes here.

Provenance

The following attestation bundles were made for mydborm-0.3.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