Skip to main content

Python implementation of MyBatis-Plus: generic CRUD, fluent query builder, Pydantic-driven entity mapping, multi-dialect support, and pluggable middleware chain.

Project description

mybatis-plus-py

Python implementation of MyBatis-Plus: Pydantic-driven entity mapping, generic CRUD repositories, fluent query builder, multi-dialect support (SQLite / PostgreSQL / MySQL), Druid-style connection pool, and MyBatis-Plus style SQL interceptor pipeline.

Quick Start

pip install mybatis-plus-py
# with database driver extras
pip install mybatis-plus-py[postgres]  # or [mysql]
from pydantic import BaseModel
from mybatis_plus import entity, Field, Query, BaseRepository, SQLiteDataSource, EntitySession, SqlExecutor

@entity(table="users")
class User(BaseModel):
    id: int = Field(primary_key=True, auto_increment=True)
    name: str
    age: int = Field(default=18)

ds = SQLiteDataSource(":memory:")
session = EntitySession(SqlExecutor(ds))
session.create_table(User)
session.insert(User(name="Alice", age=30))

# Fluent query
adults = session.select_list(User, Query().gt("age", 18))

# Repository
repo = BaseRepository(User, session)
page = repo.select_page(Query().order_by("id"), page=1, size=10)

Database Support

Database Driver Datasource
SQLite stdlib sqlite3 SQLiteDataSource
PostgreSQL psycopg2 PostgresDataSource
MySQL pymysql MySQLDataSource

Key Features

  • Entity mapping@entity() + Field() with primary keys, auto-increment, version, soft delete, auto-fill
  • Fluent query builderQuery().eq("name", "Tom").gt("age", 18).order_by("id")
  • Generic CRUDBaseRepository[T] with insert, update, delete, select, pagination
  • Chain wrappersChainQuery(User, session).eq("age", 18).list()
  • SQL interceptors — MyBatis-Plus style InnerInterceptor / MybatisPlusInterceptor pipeline with PaginationInnerInterceptor
  • Connection pool — Druid-style pool with ExceptionSorter, ValidConnectionChecker, RemoveAbandoned, PreparedStatementPool
  • Middleware — Tenant, logic delete, optimistic lock, auto-fill, block attack, dynamic table name

Architecture

Entity API / Repository / Chain / ActiveRecord
        -> EntitySession
        -> SqlBuilder + EntityMetaRegistry
        -> SqlExecutor
        -> MybatisPlusInterceptor + StatementHandler
        -> ParameterHandler / ResultSetHandler
        -> DataSource / Dialect

License

Apache-2.0

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

mybatis_plus_py-0.2.0.tar.gz (110.8 kB view details)

Uploaded Source

Built Distribution

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

mybatis_plus_py-0.2.0-py3-none-any.whl (100.8 kB view details)

Uploaded Python 3

File details

Details for the file mybatis_plus_py-0.2.0.tar.gz.

File metadata

  • Download URL: mybatis_plus_py-0.2.0.tar.gz
  • Upload date:
  • Size: 110.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for mybatis_plus_py-0.2.0.tar.gz
Algorithm Hash digest
SHA256 e8cd3ce70858d32a412446a340e3ee85920bd3581f7bd2860ff8bee389538dc0
MD5 1b5795bd358cdd972cc5a24df601c44a
BLAKE2b-256 4818e0f0cf93c7531afc5951af5c3b484b564bf641802161b67842ad5da26660

See more details on using hashes here.

File details

Details for the file mybatis_plus_py-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mybatis_plus_py-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8ba15a35d40ff7cabe4c3f86ad7eb07ad10654035cb3906c50e0f36bdd4bea98
MD5 e730ea602e859b0fe6517e64a0a6b249
BLAKE2b-256 b67324e8bac6df37c276ae34cc553add035545d5490845c8008881a34fede341

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