Skip to main content

python-oceanbase-driver

Python 的 OceanBase 驱动,基于 PyMySQL 1.2.0,纯 Python,用法与 PyMySQL 完全一致, 区别是默认置上握手包 capability bit27,可直连 OceanBase Oracle 租户。 未打补丁的 MySQL 协议驱动连 Oracle 租户会被服务端拒绝:

pyoceanbase.err.NotSupportedError: (1235, 'Oracle tenant for current client driver is not supported')

原理:OceanBase 登录时检查该位(OB_CLIENT_SUPPORT_ORACLE_MODE, 与 MySQL 8.0 的 CLIENT_QUERY_ATTRIBUTES 同一位),mysql 8.0 客户端默认置位, PyMySQL 默认没置。本驱动默认置上,对 MySQL / MariaDB / OB MySQL 租户无副作用。

安装

pip install pyoceanbase

注意:顶层包名为 pyoceanbase,可与上游 PyMySQL 共存于同一环境,按需选用。

用法

import pyoceanbase

conn = pyoceanbase.connect(
    host="HOST",
    port=9090,
    user="USER@TENANT#CLUSTER",
    password="PASSWORD",
    database="DBNAME",
)
with conn.cursor() as cur:
    cur.execute("SELECT USER FROM DUAL")
    print(cur.fetchone())
conn.close()

注意事项

  1. 业务 SQL 须用 Oracle 方言(如 FROM DUALSYSDATE)。
  2. 默认 autocommit=False,写入后记得 conn.commit()(标准 PyMySQL 行为)。
  3. 数字类型默认返回 Decimal(标准 PyMySQL 行为),可用 conv 覆盖。
  4. DSN 参数等细节见上游文档:https://github.com/PyMySQL/PyMySQL

协议

MIT,与上游一致。

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyoceanbase-1.0.1.tar.gz (44.1 kB view details)

Uploaded Source

Built Distribution

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

pyoceanbase-1.0.1-py3-none-any.whl (45.8 kB view details)

Uploaded Python 3

File details

Details for the file pyoceanbase-1.0.1.tar.gz.

File metadata

  • Download URL: pyoceanbase-1.0.1.tar.gz
  • Upload date:
  • Size: 44.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pyoceanbase-1.0.1.tar.gz
Algorithm Hash digest
SHA256 c586126b97a01b0437b914e6af5e5096be06a2c892f00006ba0b9dabb1e1f1f8
MD5 c10306ebc1ad976d9bd279e32f135963
BLAKE2b-256 0820c79f69ba8e0fb426bbff2ec71847bc682bf7ef5cfa1a2a9279d3bc74bca6

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyoceanbase-1.0.1.tar.gz:

Publisher: publish.yml on oceanbase-driver/python-oceanbase-driver

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

File details

Details for the file pyoceanbase-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: pyoceanbase-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 45.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pyoceanbase-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 24f72976d494e59d68963e653c7cf6a325b34389aebf96fbbb88b0433ac9d209
MD5 4bd4370784eb6bcb6650125a58cf6428
BLAKE2b-256 02a3a0c478336e45e2465f838969ce3ed74de0e505b422839bed42546e094119

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyoceanbase-1.0.1-py3-none-any.whl:

Publisher: publish.yml on oceanbase-driver/python-oceanbase-driver

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

Release history Release notifications | RSS feed

1.1.0

2 files

This release

1.0.1 This release

2 files

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