Skip to main content

SQLAlchemy OceanBase Dialect

PyPI version License Python

A SQLAlchemy dialect for OceanBase Oracle mode, providing seamless integration between SQLAlchemy and OceanBase database.

Features

  • Full Compatibility: Supports SQLAlchemy 1.3.x and 2.0+
  • Optimized Performance: Enhanced SQL queries specifically optimized for OceanBase
  • Advanced Reflection: Enhanced constraint reflection with OceanBase-specific optimizations
  • Connection Safety: Secure connection string building utilities

Installation

pip install oceanbase-sqlalchemy

From Source

git clone https://github.com/oceanbase/ecology-plugins.git
cd ecology-plugins/oceanbase-sqlalchemy-plugin
pip install -e .

Quick Start

Basic Usage

from sqlalchemy import create_engine, text
from oceanbase_sqlalchemy.utils import build_safe_connection_string

# Build connection string
connection_string = build_safe_connection_string(
    username="your_username",
    password="your_password",
    host="your_host",
    port="2881",
    service_name="your_service_name",
)

# Create engine
engine = create_engine(connection_string)

# Test connection
with engine.connect() as conn:
    result = conn.execute(text("SELECT 1 FROM DUAL"))
    print(result.fetchone())

Using with SQLAlchemy ORM

from sqlalchemy import create_engine, Column, Integer, String, MetaData, Table
from sqlalchemy.ext.declarative import declarative_base
from oceanbase_sqlalchemy.utils import build_safe_connection_string

# Create engine
connection_string = build_safe_connection_string(
    username="your_username",
    password="your_password",
    host="your_host",
    port="2881",
    service_name="your_service_name",
)
engine = create_engine(connection_string)

# Define model
Base = declarative_base()


class User(Base):
    __tablename__ = "users"

    id = Column(Integer, primary_key=True)
    name = Column(String(50))
    email = Column(String(100))


# Create tables
Base.metadata.create_all(engine)

Requirements

  • Python 3.7+
  • SQLAlchemy 1.3.x or 2.0+
  • cx_Oracle (for Oracle mode)

Contributing

We welcome contributions! Please see our Contributing Guide for details.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Support

FAQ

Q: How to connect to OceanBase MySQL mode?

A: The current version only supports OceanBase Oracle mode. For MySQL mode, please use the standard MySQL driver.

Q: Which SQLAlchemy versions are supported?

A: Supports SQLAlchemy 1.3.x and 2.0+ versions.

Troubleshooting

Connection Issues

  • Check network connection and firewall settings
  • Verify username, password and service name
  • Confirm the port number is correct (default 2881)

Performance Issues

  • Enable SQL logging (echo=True) to view executed SQL
  • Analyze slow query logs

Compatibility Issues

  • Ensure using supported SQLAlchemy version
  • Check cx_Oracle driver version
  • Review OceanBase version compatibility

Metadata

Release files for oceanbase-sqlalchemy 0.8.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for oceanbase-sqlalchemy 0.8.0
File Size Uploaded Provenance Actions
oceanbase_sqlalchemy-0.8.0.tar.gz 19.5 kB With provenance Details for oceanbase_sqlalchemy-0.8.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for oceanbase-sqlalchemy 0.8.0
File Interpreter ABI Platform Actions
oceanbase_sqlalchemy-0.8.0-py3-none-any.whl Python 3 none any Details for oceanbase_sqlalchemy-0.8.0-py3-none-any.whl

Total release size: 40.8 kB

Release files / oceanbase_sqlalchemy-0.8.0.tar.gz

Download URL oceanbase_sqlalchemy-0.8.0.tar.gz
Size 19.5 kB
Tags Source
SHA-256 checksum
How to use checksums
0f44d752f83c8550c2b8df80df0122d2f7cf4b3a88f079763d6ded44b1f103e8
BLAKE2b-256 checksum
How to use checksums
8cdb764372752d402c25f2dbfb90757e17a6bdd2ed4f41a2c4062db9f57fabfd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

Release files / oceanbase_sqlalchemy-0.8.0-py3-none-any.whl

Download URL oceanbase_sqlalchemy-0.8.0-py3-none-any.whl
Size 21.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
db690c74057f9bcf74661cb4f5598cf954260426c1a0ff6aeaef356e41cd0d0f
BLAKE2b-256 checksum
How to use checksums
c562b4ae53e099b54b2485f5044166a1c9b36316ce25b44d63042a1a11542dfd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

Security for oceanbase-sqlalchemy 0.8.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for oceanbase_sqlalchemy-0.8.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page