Skip to main content

SQLAlchemy dialect for OceanBase Oracle mode (supports SQLAlchemy 1.3.x and 2.0+)

Project description

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

From PyPI (Recommended)

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

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

oceanbase_sqlalchemy-0.5.0.tar.gz (16.3 kB view details)

Uploaded Source

Built Distribution

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

oceanbase_sqlalchemy-0.5.0-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

Details for the file oceanbase_sqlalchemy-0.5.0.tar.gz.

File metadata

  • Download URL: oceanbase_sqlalchemy-0.5.0.tar.gz
  • Upload date:
  • Size: 16.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for oceanbase_sqlalchemy-0.5.0.tar.gz
Algorithm Hash digest
SHA256 a38eeb28090c9352c71080c8b12b3c5b5ca5e8efe3f893ad746b4b9262c4a015
MD5 871de1cc05ccb0f02bfb2f3983c43b0b
BLAKE2b-256 22f8bdbe40eef253505294d84537dd4ce90579cdf3285be9effd5183e56d8442

See more details on using hashes here.

Provenance

The following attestation bundles were made for oceanbase_sqlalchemy-0.5.0.tar.gz:

Publisher: publish_oceanbase_sqlachemy.yaml on oceanbase/ecology-plugins

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file oceanbase_sqlalchemy-0.5.0-py3-none-any.whl.

File metadata

File hashes

Hashes for oceanbase_sqlalchemy-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 53584035262a6d9385dd2bb5aaaf40933a8aaa5bef8745d1943a692eba91cb4d
MD5 ffea2cb4947a03a6b26abdcca8f6465a
BLAKE2b-256 c8fb30f05168f9183e0e24e1e84d8a502d1792d23a5b51c404f338ae78e86149

See more details on using hashes here.

Provenance

The following attestation bundles were made for oceanbase_sqlalchemy-0.5.0-py3-none-any.whl:

Publisher: publish_oceanbase_sqlachemy.yaml on oceanbase/ecology-plugins

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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