A Cython-Accelerated, Pythonic MySQL ORM & Query Builder
Created to be used in a project, this package is published to github for ease of management and installation across different modules.
Installation
Install from PyPi
pip install mysqlengine
Install from github
pip install git+https://github.com/AresJef/MysqlEngine.git
Requirements
- Python 3.10 or higher.
- MySQL 5.5 or higher.
Features
MysqlEngine is a Python/Cython hybrid library that provides a high-performance, programmatic interface to MySQL. It provides:
- An ORM-style schema definition via <'Database'>, <'Table'>, <'Column'>, etc.
- A fluent query-builder (less hand-written SQL strings).
- Built-in support for both sync and async workflows.
- Custom <'TimeTable'> class to create and manage time-series partitions.
- Critical parts are implemented in Cython, minimizing Python overhead and maximizing throughput.
MysqlEngine is built on top of SQLCyCli. Because SQLCyCli already delivers solid and high-performance connectivity, MysqlEngine can concentrate on its higher-level features.
- Delegates raw socket I/O, packet parsing, authentication, pooling, and cursor management to SQLCyCli.
- All exeption is inherited from the
SQLCyCli.errors.MySQLError.
Example (Normal Table)
import asyncio
from mysqlengine import Database, Table, Pool
from mysqlengine import Column, Index, Define, PrimaryKey
# Difine Table
class User(Table):
id: Column = Column(Define.BIGINT(unsigned=True, auto_increment=True))
name: Column = Column(Define.VARCHAR(255))
pk: PrimaryKey = PrimaryKey("id")
idx: Index = Index("name")
class Product(Table):
id: Column = Column(Define.BIGINT(unsigned=True, auto_increment=True))
product_name: Column = Column(Define.VARCHAR(255))
product_price: Column = Column(Define.DECIMAL(12, 2))
pk: PrimaryKey = PrimaryKey("id")
idx: Index = Index("product_name")
# Define Database
class MyDatabase(Database):
user: User = User()
product: Product = Product()
# Instanciate Database
pool = Pool(host="localhost", user="root", password="Password_123456")
db = MyDatabase("db", pool)
# Synchronize Demo
def sync_demo(db: MyDatabase) -> None:
db.Initialize() # Initialize 'db'
db.ShowDatabases()
db.user.ShowCreateTable()
db.user.ShowMetadata()
db.user.Insert().Columns(db.user.name).Values(1).Execute(
["John", "Sarah"], many=True
)
db.Select("*").From(db.user).Execute() # ((1, 'John'), (2, 'Sarah'))
db.Drop() # Drop 'db'
sync_demo(db)
# Asynchronize Demo
async def async_demo(db: MyDatabase) -> None:
await db.aioInitialize() # Initialize 'db'
await db.aioShowDatabases()
await db.user.aioShowCreateTable()
await db.user.aioShowMetadata()
await db.user.Insert().Columns(db.user.name).Values(1).aioExecute(
["John", "Sarah"], many=True
)
await db.Select("*").From(db.user).aioExecute() # ((1, 'John'), (2, 'Sarah'))
await db.aioDrop() # Drop 'db'
asyncio.run(async_demo(db))
Example (Temporary Table)
import asyncio
from mysqlengine import Pool, Database, Table, TempTable
from mysqlengine import Column, Index, Define, PrimaryKey
class MyTable(Table):
id: Column = Column(Define.BIGINT(unsigned=True, auto_increment=True))
name: Column = Column(Define.VARCHAR(255))
pk: PrimaryKey = PrimaryKey("id")
class MyTempTable(TempTable):
id: Column = Column(Define.BIGINT(unsigned=True, auto_increment=True))
name: Column = Column(Define.VARCHAR(255))
pk: PrimaryKey = PrimaryKey("id")
class MyDatabase(Database):
tb: MyTable = MyTable()
pool = Pool(host="localhost", user="root", password="Password_123456")
db = MyDatabase("db", pool)
db.Drop(True)
# Synchronize Demo
def sync_demo(db: MyDatabase) -> None:
db.Initialize() # Initialize 'db'
db.tb.Insert().Columns("name").Values(1).Execute(["John", "Sarah"], many=True)
with db.transaction() as conn:
with db.CreateTempTable(conn, "temp_tb", MyTempTable()) as tmp:
tmp.Insert().Columns("name").Select("name").From(db.tb).Execute()
tmp.Select("*").Execute() # ((1, 'John'), (2, 'Sarah'))
# temporary table is automatically dropped
db.Drop() # Drop 'db'
sync_demo(db)
# Asynchronize Demo
async def async_demo(db: MyDatabase) -> None:
await db.aioInitialize() # Initialize 'db'
await db.tb.Insert().Columns("name").Values(1).aioExecute(
["John", "Sarah"], many=True
)
async with db.transaction() as conn:
async with db.CreateTempTable(conn, "temp_tb", MyTempTable()) as tmp:
await tmp.Insert().Columns("name").Select("name").From(db.tb).aioExecute()
await tmp.Select("*").aioExecute() # ((1, 'John'), (2, 'Sarah'))
# temporary table is automatically dropped
await db.aioDrop() # Drop 'db'
asyncio.run(async_demo(db))
Example (Time Table)
import asyncio
from mysqlengine import Pool, Database, TimeTable
from mysqlengine import Column, Index, Define, PrimaryKey
class MyTimeTable(TimeTable):
id: Column = Column(Define.BIGINT(unsigned=True, auto_increment=True))
name: Column = Column(Define.VARCHAR(255))
dt: Column = Column(Define.DATETIME())
pk: PrimaryKey = PrimaryKey("id", "dt")
class MyDatabase(Database):
tb: MyTimeTable = MyTimeTable("dt", "YEAR", "2024-01-01", "2025-01-01")
pool = Pool(host="localhost", user="root", password="Password_123456")
db = MyDatabase("db", pool)
db.Drop(True)
# Synchronize Demo
def sync_demo(db: MyDatabase) -> None:
db.Initialize() # Initialize 'db'
db.tb.Insert().Columns("name", "dt").Values(2).Execute(
[("John", "2024-02-01"), ("Sarah", "2025-02-01")], many=True
)
db.tb.ShowPartitionRows() # {'past': 0, 'y2024': 1, 'y2025': 1, 'future': 0}
db.tb.ExtendToTime(end_with="2026-02-01")
db.tb.ShowPartitionRows() # {'past': 0, 'y2024': 1, 'y2025': 1, 'y2026': 0, 'future': 0}
db.tb.DropToTime(start_from="2025-01-01")
db.tb.ShowPartitionRows() # {'past': 0, 'y2025': 1, 'y2026': 0, 'future': 0}
db.Drop() # Drop 'db'
sync_demo(db)
# Asynchronize Demo
async def async_demo(db: MyDatabase) -> None:
await db.aioInitialize() # Initialize 'db'
await db.tb.Insert().Columns("name", "dt").Values(2).aioExecute(
[("John", "2024-02-01"), ("Sarah", "2025-02-01")], many=True
)
await db.tb.aioShowPartitionRows() # {'past': 0, 'y2024': 1, 'y2025': 1, 'future': 0}
await db.tb.aioExtendToTime(end_with="2026-02-01")
await db.tb.aioShowPartitionRows() # {'past': 0, 'y2024': 1, 'y2025': 1, 'y2026': 0, 'future': 0}
await db.tb.aioDropToTime(start_from="2025-01-01")
await db.tb.aioShowPartitionRows() # {'past': 0, 'y2025': 1, 'y2026': 0, 'future': 0}
await db.aioDrop() # Drop 'db'
asyncio.run(async_demo(db))
Acknowledgements
MysqlEngine is based on several open-source repositories.
Metadata
Release files for mysqlengine 1.3.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mysqlengine-1.3.4.tar.gz | 4.0 MB | Without provenance | Details for mysqlengine-1.3.4.tar.gz |
Built distributions (wheels)
Total release size: 226.9 MB
Release files / mysqlengine-1.3.4.tar.gz
| Download URL | mysqlengine-1.3.4.tar.gz |
|---|---|
| Size | 4.0 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4a3d79618862a6807da72326ddff98fb30df7ddc9b1a8367329574f6d0ac4807
|
|
BLAKE2b-256 checksum How to use checksums |
dcee33c1b023df4bd8d8e126124692001ce417b79c35e3a6f40a8dec6b3ec5fc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / mysqlengine-1.3.4-cp313-cp313-win_amd64.whl
| Download URL | mysqlengine-1.3.4-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 6.0 MB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
f0d1c01bd250decc30cfab14d0a9aea94b50e252db86255f310f303fd38b728a
|
|
BLAKE2b-256 checksum How to use checksums |
e0557997dd378dd3bc3769be6bdbb89d6abed3cb8fb58c936c38b4cde133165b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / mysqlengine-1.3.4-cp313-cp313-musllinux_1_2_x86_64.whl
| Download URL | mysqlengine-1.3.4-cp313-cp313-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 20.4 MB |
| Tags | CPython 3.13 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
6a547e388fa772c13f4f016488793d5940a536513d9dd8aad9bd5421022c02f6
|
|
BLAKE2b-256 checksum How to use checksums |
e09a7b28c7891b9cd8d2b306b42c16dad457269d422c9a20587880b9ce516dba
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / mysqlengine-1.3.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | mysqlengine-1.3.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 20.5 MB |
| Tags | CPython 3.13 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
b5295bd2e04c1793677e7f982ba32b9e7192cec0641f3f03cc6d3b30280e1574
|
|
BLAKE2b-256 checksum How to use checksums |
6d8eb56501dc97f27d31a5e869777c9787d6fccf0ae220beefa137c31b49f93f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / mysqlengine-1.3.4-cp313-cp313-macosx_10_13_universal2.whl
| Download URL | mysqlengine-1.3.4-cp313-cp313-macosx_10_13_universal2.whl |
|---|---|
| Size | 8.7 MB |
| Tags | CPython 3.13 macOS 10.13+ universal2 (ARM64, x86-64) |
|
SHA-256 checksum How to use checksums |
8d4ebe645966272e92d643d6bbb67124269605b1bddc82e503d378e277e259be
|
|
BLAKE2b-256 checksum How to use checksums |
7cae8ec6395c676afa625932bbafbd832f5477ecedaf8b8fbfe2872603468737
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / mysqlengine-1.3.4-cp312-cp312-win_amd64.whl
| Download URL | mysqlengine-1.3.4-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 6.0 MB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
ddcce5dbabe260734f76a0528b78f2240ad701a3a5a965dce243ae4e021a692c
|
|
BLAKE2b-256 checksum How to use checksums |
5491a2a4f25ac33d28d43fffd6fdc8d68c1e637e4275d81846eeba68aff85822
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / mysqlengine-1.3.4-cp312-cp312-musllinux_1_2_x86_64.whl
| Download URL | mysqlengine-1.3.4-cp312-cp312-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 20.5 MB |
| Tags | CPython 3.12 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
ac87a429974da4fa29be961883fab3b6e24085fdaeb3fbc6f6df47dd76999859
|
|
BLAKE2b-256 checksum How to use checksums |
ff8ca3dae8ed901acf813907d444e876c27471c90854486af9c4a03542b43332
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / mysqlengine-1.3.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | mysqlengine-1.3.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 20.6 MB |
| Tags | CPython 3.12 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
b0d2c35ed73cc3cf6fde11dac761bc5d963d2b98cecfea41617e13d8f748b733
|
|
BLAKE2b-256 checksum How to use checksums |
5796729a2394246da7843b5134a7dd2992b8f25a19f208294e268db45309ee83
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / mysqlengine-1.3.4-cp312-cp312-macosx_10_13_universal2.whl
| Download URL | mysqlengine-1.3.4-cp312-cp312-macosx_10_13_universal2.whl |
|---|---|
| Size | 8.7 MB |
| Tags | CPython 3.12 macOS 10.13+ universal2 (ARM64, x86-64) |
|
SHA-256 checksum How to use checksums |
bd7cb22a423ae0f39134091da76edd49e852acaccf7231078d3bdf5e28137ad7
|
|
BLAKE2b-256 checksum How to use checksums |
79048b35ee3ffa924cbca9b561051c595b44c3d3be662c9838b975f7ae3f54c3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / mysqlengine-1.3.4-cp311-cp311-win_amd64.whl
| Download URL | mysqlengine-1.3.4-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 6.0 MB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
be4e5f667cd04c90b46b6f0772027412df9663a1f90ae4a7b503a7fcf93b0ac0
|
|
BLAKE2b-256 checksum How to use checksums |
e98688dff412f1426b7e2664d018466d6f38782bb370533d6ec9aa8bac0676df
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / mysqlengine-1.3.4-cp311-cp311-musllinux_1_2_x86_64.whl
| Download URL | mysqlengine-1.3.4-cp311-cp311-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 21.0 MB |
| Tags | CPython 3.11 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
f33b846fe9aa0be11f2b708ccd56085a747862ed03ac0ae96897fba7d397cf2e
|
|
BLAKE2b-256 checksum How to use checksums |
0a18be738a01196115e1970bc4ccfa6730b3233906865803328ecbe3558843cf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / mysqlengine-1.3.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | mysqlengine-1.3.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 21.2 MB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
f6e0fcfce6a1eaf16a01dab44898c99b5dbee099c9aafd66200accbceab9f2c1
|
|
BLAKE2b-256 checksum How to use checksums |
1ccf3f59631ee434e02323064dbd86496364da132541f838ea5ab4b2d855f10d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / mysqlengine-1.3.4-cp311-cp311-macosx_10_9_universal2.whl
| Download URL | mysqlengine-1.3.4-cp311-cp311-macosx_10_9_universal2.whl |
|---|---|
| Size | 8.7 MB |
| Tags | CPython 3.11 macOS 10.9+ universal2 (ARM64, x86-64) |
|
SHA-256 checksum How to use checksums |
3a5dab9e3c107593ca5a088e841e60d610267f6118ece8acf133799c4356ca84
|
|
BLAKE2b-256 checksum How to use checksums |
35c3d33713134bd8357f2788b0998033622c6f98b3dbfc861b5355f2b30092ae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / mysqlengine-1.3.4-cp310-cp310-win_amd64.whl
| Download URL | mysqlengine-1.3.4-cp310-cp310-win_amd64.whl |
|---|---|
| Size | 5.9 MB |
| Tags | CPython 3.10 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
fdd58b391f4661f854ef226f21f0a669ac725a9475e6eda2c4bf8294648d11b5
|
|
BLAKE2b-256 checksum How to use checksums |
1a2ff2ca2470fe851193bb555934292c6d0a5c2c6225aca7ef423d953f3fca84
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / mysqlengine-1.3.4-cp310-cp310-musllinux_1_2_x86_64.whl
| Download URL | mysqlengine-1.3.4-cp310-cp310-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 19.9 MB |
| Tags | CPython 3.10 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
c87c1c2da717c97c08d902629a91471a5d2680c5d11790c25f5d8e254f3d8b05
|
|
BLAKE2b-256 checksum How to use checksums |
4a85b12dcac66a8cd5bd39400bc942523f512d4018450ebc1e6d62491b330c30
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / mysqlengine-1.3.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | mysqlengine-1.3.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 20.0 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
e1fc3f9607edb6cce3676e2a04de2ecfc15280d261e4a6b6b8a73c4e3d539b91
|
|
BLAKE2b-256 checksum How to use checksums |
54ee6c3861416c034e452331f83b6c5a664d8ffaaf3457e6ab529f96e6f2ceb5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / mysqlengine-1.3.4-cp310-cp310-macosx_10_9_universal2.whl
| Download URL | mysqlengine-1.3.4-cp310-cp310-macosx_10_9_universal2.whl |
|---|---|
| Size | 8.8 MB |
| Tags | CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64) |
|
SHA-256 checksum How to use checksums |
cdc64eb4db06c2599fa75cd73807ed54b545d4345de137c885630b80e9e46bee
|
|
BLAKE2b-256 checksum How to use checksums |
44d718e639a4adc2f7cfa19a97316ea9a954e8bbacbc2ab074c9b8edf2dcdbd3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Security for mysqlengine 1.3.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.