SQLAlchemy dialect for OceanBase Oracle mode (supports SQLAlchemy 1.3.x and 2.0+)
Project description
SQLAlchemy OceanBase Dialect
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.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Support
- Issues: GitHub Issues
- Community: OceanBase Community
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
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 oceanbase_sqlalchemy-0.4.0.tar.gz.
File metadata
- Download URL: oceanbase_sqlalchemy-0.4.0.tar.gz
- Upload date:
- Size: 15.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f776bd40bdd3e9de1386af611ff8e90564edc6c2fe38f8f0b2b6b6c821effe95
|
|
| MD5 |
3a90ef81962b1218b553855d4b054a98
|
|
| BLAKE2b-256 |
3a90b5119f00069ade09eb8ba85bc0ecc291305ddbd0cf8217260f9cb42ba269
|
Provenance
The following attestation bundles were made for oceanbase_sqlalchemy-0.4.0.tar.gz:
Publisher:
publish_oceanbase_sqlachemy.yaml on oceanbase/ecology-plugins
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
oceanbase_sqlalchemy-0.4.0.tar.gz -
Subject digest:
f776bd40bdd3e9de1386af611ff8e90564edc6c2fe38f8f0b2b6b6c821effe95 - Sigstore transparency entry: 643621506
- Sigstore integration time:
-
Permalink:
oceanbase/ecology-plugins@ceee4b48609b401704e76f46c640931fa12a1059 -
Branch / Tag:
refs/tags/release_oceanbase_sqlalchemy_v0.4.0 - Owner: https://github.com/oceanbase
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_oceanbase_sqlachemy.yaml@ceee4b48609b401704e76f46c640931fa12a1059 -
Trigger Event:
push
-
Statement type:
File details
Details for the file oceanbase_sqlalchemy-0.4.0-py3-none-any.whl.
File metadata
- Download URL: oceanbase_sqlalchemy-0.4.0-py3-none-any.whl
- Upload date:
- Size: 17.2 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 |
cb0fff25acf232c7f6b8711f9d7d716bfc9d1e8e8df7389448bfcec69123d3d5
|
|
| MD5 |
2eab52c2fa058bf86cb292a27012aa32
|
|
| BLAKE2b-256 |
bd178bc781333e3945a75229b37d7b055692df46fb7bcba46be9100644819479
|
Provenance
The following attestation bundles were made for oceanbase_sqlalchemy-0.4.0-py3-none-any.whl:
Publisher:
publish_oceanbase_sqlachemy.yaml on oceanbase/ecology-plugins
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
oceanbase_sqlalchemy-0.4.0-py3-none-any.whl -
Subject digest:
cb0fff25acf232c7f6b8711f9d7d716bfc9d1e8e8df7389448bfcec69123d3d5 - Sigstore transparency entry: 643621523
- Sigstore integration time:
-
Permalink:
oceanbase/ecology-plugins@ceee4b48609b401704e76f46c640931fa12a1059 -
Branch / Tag:
refs/tags/release_oceanbase_sqlalchemy_v0.4.0 - Owner: https://github.com/oceanbase
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_oceanbase_sqlachemy.yaml@ceee4b48609b401704e76f46c640931fa12a1059 -
Trigger Event:
push
-
Statement type: