Lightweight ORM for MySQL and YugabyteDB
Project description
mydborm
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_URLenvironment 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
SERIALprimary keys- Native
BOOLEAN JSONBinstead ofJSONRETURNING idon 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
Release history Release notifications | RSS feed
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5d52c7d2cdcebea0c58ac218a23ca0fa63459d08dfce095cfeec9f2afe53ca7e
|
|
| MD5 |
7c6e47f8aeb4b59903d899cb832b7dce
|
|
| BLAKE2b-256 |
4b920bc64aeecae20853f9fadfa30c0b652af3ee34ce863a9094493e1114075c
|
Provenance
The following attestation bundles were made for mydborm-0.4.0.tar.gz:
Publisher:
ci.yml on codengers/mydborm
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mydborm-0.4.0.tar.gz -
Subject digest:
5d52c7d2cdcebea0c58ac218a23ca0fa63459d08dfce095cfeec9f2afe53ca7e - Sigstore transparency entry: 1845220554
- Sigstore integration time:
-
Permalink:
codengers/mydborm@aee1d0c96da23ba68c6a0bdb900b85f37bb0ca38 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/codengers
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@aee1d0c96da23ba68c6a0bdb900b85f37bb0ca38 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f94e3a194550fbf05b83021fba05d9d7ad4e9fa79fcf45ed2a3ecfd568705891
|
|
| MD5 |
88541d35035acceaca99b48e40450ab8
|
|
| BLAKE2b-256 |
6419014906e213f4130565b53c717240b51dbe849c9c5cc11f238ac60b8df7a2
|
Provenance
The following attestation bundles were made for mydborm-0.4.0-py3-none-any.whl:
Publisher:
ci.yml on codengers/mydborm
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mydborm-0.4.0-py3-none-any.whl -
Subject digest:
f94e3a194550fbf05b83021fba05d9d7ad4e9fa79fcf45ed2a3ecfd568705891 - Sigstore transparency entry: 1845220829
- Sigstore integration time:
-
Permalink:
codengers/mydborm@aee1d0c96da23ba68c6a0bdb900b85f37bb0ca38 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/codengers
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@aee1d0c96da23ba68c6a0bdb900b85f37bb0ca38 -
Trigger Event:
push
-
Statement type: