CUBRID dialect for SQLAlchemy
Project description
sqlalchemy-cubrid
SQLAlchemy 2.0 dialect for the CUBRID database — Python ORM, schema reflection, Alembic migrations, and full type system support.
🇰🇷 한국어 · 🇺🇸 English · 🇨🇳 中文 · 🇮🇳 हिन्दी · 🇩🇪 Deutsch · 🇷🇺 Русский
Why sqlalchemy-cubrid?
CUBRID is a high-performance open-source relational database, widely adopted in Korean public-sector and enterprise applications. Until now, there was no production-ready SQLAlchemy dialect that supports the modern 2.0 API.
sqlalchemy-cubrid bridges that gap:
- Full SQLAlchemy 2.0 dialect with statement caching and PEP 561 typing
- 426 offline tests with 99%+ code coverage — no database required to run them
- Tested against 4 CUBRID versions (10.2, 11.0, 11.2, 11.4) across Python 3.10 -- 3.13
- CUBRID-specific DML constructs:
ON DUPLICATE KEY UPDATE,MERGE,REPLACE INTO - Alembic migration support out of the box
- Two driver options — C-extension (
cubrid://) or pure Python (cubrid+pycubrid://)
Architecture
flowchart TD
app["Application"] --> sa["SQLAlchemy Core/ORM"]
sa --> dialect["CubridDialect"]
dialect --> pycubrid["pycubrid driver"]
dialect --> cext["CUBRIDdb driver"]
pycubrid --> server["CUBRID Server"]
cext --> server
flowchart TD
expr["SQL Expression"] --> compiler["CubridSQLCompiler"] --> sql["SQL String"]
Requirements
- Python 3.10+
- SQLAlchemy 2.0 – 2.1
- CUBRID-Python (C-extension) or pycubrid (pure Python)
Installation
pip install sqlalchemy-cubrid
With the pure Python driver (no C build needed):
pip install "sqlalchemy-cubrid[pycubrid]"
With Alembic support:
pip install "sqlalchemy-cubrid[alembic]"
Quick Start
Core (Connection-Level)
from sqlalchemy import create_engine, text
engine = create_engine("cubrid://dba:password@localhost:33000/demodb")
with engine.connect() as conn:
result = conn.execute(text("SELECT 1"))
print(result.scalar())
ORM (Session-Level)
from sqlalchemy import create_engine, String
from sqlalchemy.orm import DeclarativeBase, Mapped, Session, mapped_column
class Base(DeclarativeBase):
pass
class User(Base):
__tablename__ = "users"
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
name: Mapped[str] = mapped_column(String(100))
email: Mapped[str] = mapped_column(String(200), unique=True)
engine = create_engine("cubrid://dba:password@localhost:33000/demodb")
Base.metadata.create_all(engine)
with Session(engine) as session:
user = User(name="Alice", email="alice@example.com")
session.add(user)
session.commit()
Features
- Complete type system -- numeric, string, date/time, bit, LOB, and collection types
- SQL compilation -- SELECT, JOIN, CAST, LIMIT/OFFSET, subqueries, CTEs, window functions
- DML extensions --
ON DUPLICATE KEY UPDATE,MERGE,REPLACE INTO,FOR UPDATE,TRUNCATE - DDL support --
COMMENT,IF NOT EXISTS/IF EXISTS,AUTO_INCREMENT - Schema reflection -- tables, views, columns, PKs, FKs, indexes, unique constraints, comments
- Alembic migrations via
CubridImpl(auto-discovered entry point) - All 6 CUBRID isolation levels (dual-granularity: class-level + instance-level)
Documentation
| Guide | Description |
|---|---|
| Connection | Connection strings, URL format, driver setup, pool tuning |
| Type Mapping | Full type mapping, CUBRID-specific types, collection types |
| DML Extensions | ON DUPLICATE KEY UPDATE, MERGE, REPLACE INTO, query trace |
| Isolation Levels | All 6 CUBRID isolation levels, configuration |
| Alembic Migrations | Setup, configuration, limitations, batch workarounds |
| Feature Support | Comparison with MySQL, PostgreSQL, SQLite |
| ORM Cookbook | Practical ORM examples, relationships, queries |
| Development | Dev setup, testing, Docker, coverage, CI/CD |
| Driver Compatibility | CUBRID-Python driver versions and known issues |
| Troubleshooting | Common issues, error solutions, debugging techniques |
Compatibility
| Python 3.10 | Python 3.11 | Python 3.12 | Python 3.13 | |
|---|---|---|---|---|
| Offline Tests | ✅ | ✅ | ✅ | ✅ |
| CUBRID 11.4 | ✅ | -- | ✅ | -- |
| CUBRID 11.2 | ✅ | -- | ✅ | -- |
| CUBRID 11.0 | ✅ | -- | ✅ | -- |
| CUBRID 10.2 | ✅ | -- | ✅ | -- |
FAQ
How do I connect to CUBRID with SQLAlchemy?
from sqlalchemy import create_engine
engine = create_engine("cubrid://dba:password@localhost:33000/demodb")
For the pure Python driver (no C build needed): create_engine("cubrid+pycubrid://dba@localhost:33000/demodb")
Does sqlalchemy-cubrid support SQLAlchemy 2.0?
Yes. sqlalchemy-cubrid is built for SQLAlchemy 2.0+ and supports the new 2.0-style API including Session.execute(), typed Mapped[] columns, and statement caching.
Does sqlalchemy-cubrid support Alembic migrations?
Yes. Install with pip install "sqlalchemy-cubrid[alembic]". The dialect auto-registers via entry point. Note that CUBRID auto-commits DDL, so migrations are not transactional.
What Python versions are supported?
Python 3.10, 3.11, 3.12, and 3.13.
Does CUBRID support RETURNING clauses?
No. CUBRID does not support INSERT ... RETURNING or UPDATE ... RETURNING. Use cursor.lastrowid or SELECT LAST_INSERT_ID() instead.
How do I use ON DUPLICATE KEY UPDATE with CUBRID?
from sqlalchemy_cubrid import insert
stmt = insert(users).values(name="Alice").on_duplicate_key_update(name="Alice Updated")
What's the difference between cubrid:// and cubrid+pycubrid://?
cubrid:// uses the C-extension driver (CUBRIDdb) which requires compilation. cubrid+pycubrid:// uses the pure Python driver which installs with pip alone — no build tools needed.
Benchmark
Performance benchmarks comparing CUBRID (via pycubrid) against MySQL (via PyMySQL) are tracked in the cubrid-benchmark suite.
- Tier 0 — Functional smoke tests (connect + CRUD)
- Tier 1 — Driver throughput: 10K INSERT/SELECT, 1K UPDATE/DELETE
- Same schema, same seed data, same CI hardware per run
- Results published to GitHub Pages dashboard
Related Projects
- pycubrid — Pure Python DB-API 2.0 driver for CUBRID
- cubrid-client — Native TypeScript client for CUBRID (CAS protocol)
- drizzle-cubrid — Drizzle ORM dialect for CUBRID
- cubrid-go — Pure Go database/sql driver for CUBRID
- gorm-cubrid — GORM dialect for CUBRID
- cubrid-rs — Native Rust database driver for CUBRID (sync + async, pure Rust)
- sea-orm-cubrid — SeaORM backend for CUBRID
- cubrid-cookbook — Production-ready examples for all CUBRID drivers
- cubrid-benchmark — Multi-language benchmark suite for CUBRID
Roadmap
See ROADMAP.md for this project's direction and next milestones.
For the ecosystem-wide view, see the CUBRID Labs Ecosystem Roadmap and Project Board.
Contributing
See CONTRIBUTING.md for guidelines and docs/DEVELOPMENT.md for development setup.
Security
Report vulnerabilities via email -- see SECURITY.md. Do not open public issues for security concerns.
License
MIT -- see LICENSE.
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 sqlalchemy_cubrid-0.7.1.tar.gz.
File metadata
- Download URL: sqlalchemy_cubrid-0.7.1.tar.gz
- Upload date:
- Size: 60.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
10e788bc03faffb5ab16c0476e0dc370790496503293da3d4e9c0deead183c13
|
|
| MD5 |
7dc1b990f10b54c5bf67c9f9bca224cc
|
|
| BLAKE2b-256 |
d1b8c78789b869279ce7f87a7c8df079cc4d302072fdfc84f4407df809b497b6
|
Provenance
The following attestation bundles were made for sqlalchemy_cubrid-0.7.1.tar.gz:
Publisher:
publish-pypi.yml on cubrid-labs/sqlalchemy-cubrid
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sqlalchemy_cubrid-0.7.1.tar.gz -
Subject digest:
10e788bc03faffb5ab16c0476e0dc370790496503293da3d4e9c0deead183c13 - Sigstore transparency entry: 1191210461
- Sigstore integration time:
-
Permalink:
cubrid-labs/sqlalchemy-cubrid@688c415b763d6b769a3e3a19f007b4dc8c8b3adf -
Branch / Tag:
refs/tags/v0.7.1 - Owner: https://github.com/cubrid-labs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@688c415b763d6b769a3e3a19f007b4dc8c8b3adf -
Trigger Event:
release
-
Statement type:
File details
Details for the file sqlalchemy_cubrid-0.7.1-py3-none-any.whl.
File metadata
- Download URL: sqlalchemy_cubrid-0.7.1-py3-none-any.whl
- Upload date:
- Size: 33.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8493ffa40bf5eb0db5173f72564bc3488590b91c72bed6b1c9840af957cb53b9
|
|
| MD5 |
bbeee01f67309758ebc925a2525977ed
|
|
| BLAKE2b-256 |
fe640cec089e77284cf314b9fb75651d8af95bbac197db34380dff3e50a8c224
|
Provenance
The following attestation bundles were made for sqlalchemy_cubrid-0.7.1-py3-none-any.whl:
Publisher:
publish-pypi.yml on cubrid-labs/sqlalchemy-cubrid
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sqlalchemy_cubrid-0.7.1-py3-none-any.whl -
Subject digest:
8493ffa40bf5eb0db5173f72564bc3488590b91c72bed6b1c9840af957cb53b9 - Sigstore transparency entry: 1191210477
- Sigstore integration time:
-
Permalink:
cubrid-labs/sqlalchemy-cubrid@688c415b763d6b769a3e3a19f007b4dc8c8b3adf -
Branch / Tag:
refs/tags/v0.7.1 - Owner: https://github.com/cubrid-labs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@688c415b763d6b769a3e3a19f007b4dc8c8b3adf -
Trigger Event:
release
-
Statement type: