Skip to main content

dm-pure:纯 Python 达梦 DM8 数据库驱动

零 native 依赖、100% Python 实现的达梦数据库驱动。支持达梦 DM8 常用功能,适合受限环境(无编译工具/无法加载 native 库的机器)。

特性

  • ✅ 连接:DH 密钥交换 + DES-CFB 加密登录(内置纯 Python 加密,零依赖)
  • ✅ 查询:SELECT / INSERT / UPDATE / DELETE,支持参数绑定(含 NULL)
  • ✅ 类型:INT / BIGINT / DECIMAL / DATE / TIME / DATETIME / FLOAT / 中文(GB18030)等
  • ✅ 大结果集:分批 fetch(cmd=7)
  • ✅ LOB:CLOB / BLOB 读写(含大 LOB 分段传输)
  • ✅ 事务:begin / commit / rollback / 隔离级别
  • ✅ 存储过程:CALL + IN/OUT 参数
  • ✅ 批量插入:executemany(协议级 batch)
  • ✅ 连接池:线程安全,自动重连
  • ✅ DB-API 2.0 兼容层:惰性游标(fetchone/fetchmany/fetchall 按需拉取)
  • ✅ 健壮性:超时控制、断线重连、错误码表

安装

pip install dm-pure

零依赖:加密算法(DES/AES/RC4)内置纯 Python 实现。若环境已安装 pycryptodome 会自动优先使用(性能更优),否则用内置实现,功能完全一致。

快速上手

底层 API

from dmpy import DMClient

c = DMClient("127.0.0.1", 5236, "SYSDBA", "password")
c.connect()
c.execute("SELECT id, name FROM t WHERE id = ?", [1])     # → (cols, rows)
c.execute("INSERT INTO t VALUES (?, ?)", [1, "x"])        # → (None, 影响行数)
c.begin(); c.execute(...); c.commit()                     # 事务
c.close()

DB-API 2.0(sqlite3/pymysql 风格)

import dmpy.dbapi as dm

conn = dm.connect(host="127.0.0.1", port=5236, user="SYSDBA", password="...")
cur = conn.cursor()
cur.execute("SELECT id, name FROM t WHERE id >= ?", [1])
rows = cur.fetchall()          # 大结果集自动分批拉取
cur.executemany("INSERT INTO t VALUES (?, ?)", [[1, "a"], [2, "b"]])
conn.commit()
conn.close()

存储过程

from dmpy import DMClient, OUT

c = DMClient("127.0.0.1", 5236, "SYSDBA", "password")
c.connect()
r = c.execute("CALL sp_test(?, ?, ?, ?)", [5, "hello", OUT(int), OUT(str)])
print(r[2])  # → [10, "hello"](OUT 参数返回值)

连接池

from dmpy.pool import ConnectionPool

pool = ConnectionPool(host="127.0.0.1", port=5236, user="SYSDBA", password="...",
                      min_connections=2, max_connections=10)
with pool.connection() as conn:
    cur = conn.cursor()
    cur.execute("SELECT 1")
pool.close()

大 LOB

# 写入 1MB CLOB/BLOB(自动分段传输)
c.execute("INSERT INTO t (id, content, data) VALUES (?, ?, ?)",
          [1, "大文本..." * 50000, b"\x00\x01..." * 100000])
# 读取(自动完整拉取)
rows = c.execute("SELECT content, data FROM t WHERE id = ?", [1])[1]

项目结构

dmpy/
├── client.py       # 核心:连接/查询/参数绑定/LOB/事务/存储过程/惰性查询
├── crypto.py       # 加密(内置纯 Python + 可选 pycryptodome)
├── _pure_crypto.py # 纯 Python DES/AES/RC4 实现
├── frame.py        # 协议帧封装/解析
├── result.py       # 列描述符/行数据/类型解码
├── dbapi.py        # DB-API 2.0 兼容层
└── pool.py         # 连接池

环境要求

  • Python >= 3.8
  • 可达的达梦 DM8 服务器(TCP 5236 端口)

测试

python test_all.py   # 22 项回归断言(需可达的达梦服务器,修改 test_all.py 中的连接参数)

发布

发布到 PyPI 的流程见 PUBLISHING.md

Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

dm_pure-1.0.0-cp312.py3-none-any.whl (63.8 kB view details)

Uploaded CPython 3.12Python 3

dm_pure-1.0.0-cp311.py3-none-any.whl (66.9 kB view details)

Uploaded CPython 3.11Python 3

dm_pure-1.0.0-cp310.py3-none-any.whl (43.9 kB view details)

Uploaded CPython 3.10Python 3

dm_pure-1.0.0-cp39.py3-none-any.whl (43.6 kB view details)

Uploaded CPython 3.9Python 3

dm_pure-1.0.0-cp38.py3-none-any.whl (43.6 kB view details)

Uploaded CPython 3.8Python 3

File details

Details for the file dm_pure-1.0.0-cp312.py3-none-any.whl.

File metadata

  • Download URL: dm_pure-1.0.0-cp312.py3-none-any.whl
  • Upload date:
  • Size: 63.8 kB
  • Tags: CPython 3.12, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for dm_pure-1.0.0-cp312.py3-none-any.whl
Algorithm Hash digest
SHA256 6b8e2d9944326a3b01f76e8af3dcb0d6961d64223184ff7f6528f9ec284b23f6
MD5 33a6787c1b7c2c05481246f3bad261e7
BLAKE2b-256 541dfb6a89531229c9c1153f7919b9344d792b39883edebab43d102f6c7648fb

See more details on using hashes here.

File details

Details for the file dm_pure-1.0.0-cp311.py3-none-any.whl.

File metadata

  • Download URL: dm_pure-1.0.0-cp311.py3-none-any.whl
  • Upload date:
  • Size: 66.9 kB
  • Tags: CPython 3.11, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.15

File hashes

Hashes for dm_pure-1.0.0-cp311.py3-none-any.whl
Algorithm Hash digest
SHA256 a9a481b43d408b0063d629dd507e7c207e46a6df4ea49f8505deedda15f50800
MD5 19fb7791ce71d47ac0afdb6433b5acbd
BLAKE2b-256 f3b4916dbeb242c73700b6dbd6f0e07108ebb38b07acfa34b68d14ce2751a532

See more details on using hashes here.

File details

Details for the file dm_pure-1.0.0-cp310.py3-none-any.whl.

File metadata

  • Download URL: dm_pure-1.0.0-cp310.py3-none-any.whl
  • Upload date:
  • Size: 43.9 kB
  • Tags: CPython 3.10, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.10.20

File hashes

Hashes for dm_pure-1.0.0-cp310.py3-none-any.whl
Algorithm Hash digest
SHA256 bf19be7654398efa0e67d1cbb5c9ae3d290442ebabb742f7dc713de57223d5e5
MD5 bbc1265c2db597c90b51952747f84e3a
BLAKE2b-256 3ec9dc0cd6363852fc096228afc6d78047efa6c7c2b28e6129b11cacae109e30

See more details on using hashes here.

File details

Details for the file dm_pure-1.0.0-cp39.py3-none-any.whl.

File metadata

  • Download URL: dm_pure-1.0.0-cp39.py3-none-any.whl
  • Upload date:
  • Size: 43.6 kB
  • Tags: CPython 3.9, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for dm_pure-1.0.0-cp39.py3-none-any.whl
Algorithm Hash digest
SHA256 a79d46580f8f8a7a9af1bb60734734ea7b53ede09c58528e5687c8bee7462010
MD5 e51d40c5a443d44b249356f8a74b6a17
BLAKE2b-256 c0704c1998ba20328f470eca54f61e67b838659da07515cbea33dcc3133c3b8c

See more details on using hashes here.

File details

Details for the file dm_pure-1.0.0-cp38.py3-none-any.whl.

File metadata

  • Download URL: dm_pure-1.0.0-cp38.py3-none-any.whl
  • Upload date:
  • Size: 43.6 kB
  • Tags: CPython 3.8, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.20

File hashes

Hashes for dm_pure-1.0.0-cp38.py3-none-any.whl
Algorithm Hash digest
SHA256 e62f6057d2ea14af293bbf18ff8905ab2441ad71613c769c2fa53cba0d805509
MD5 4aacce8d74293caccecfa1559b093383
BLAKE2b-256 5487367139f8be1e710ce497df1395d696d29ba0872ecd3aac2ce1b0f6a6b272

See more details on using hashes here.

Release history Release notifications | RSS feed

1.3.5

1 file

1.3.4

1 file

1.3.3

1 file

1.3.2

1 file

1.3.1

1 file

1.3.0

1 file

1.2.2

1 file

1.2.1

1 file

1.2.0

5 files

1.1.0

5 files

1.0.2

5 files

1.0.1

5 files

This release

1.0.0 This release

5 files

0.1.5

5 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