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-0.1.5-cp312.py3-none-any.whl (63.5 kB view details)

Uploaded CPython 3.12Python 3

dm_pure-0.1.5-cp311.py3-none-any.whl (66.6 kB view details)

Uploaded CPython 3.11Python 3

dm_pure-0.1.5-cp310.py3-none-any.whl (43.6 kB view details)

Uploaded CPython 3.10Python 3

dm_pure-0.1.5-cp39.py3-none-any.whl (43.4 kB view details)

Uploaded CPython 3.9Python 3

dm_pure-0.1.5-cp38.py3-none-any.whl (43.4 kB view details)

Uploaded CPython 3.8Python 3

File details

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

File metadata

  • Download URL: dm_pure-0.1.5-cp312.py3-none-any.whl
  • Upload date:
  • Size: 63.5 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-0.1.5-cp312.py3-none-any.whl
Algorithm Hash digest
SHA256 afa17921f0bf1e9108d5a8e5db9979a37775b99790d3e3a72b8d2042d100b0b5
MD5 9647919d7f48802a0d9ca1782120fd60
BLAKE2b-256 9248cf7d871c15126fc422cc32bd7cc95f76d3a7106aa637504d7619de3a0f9c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dm_pure-0.1.5-cp311.py3-none-any.whl
  • Upload date:
  • Size: 66.6 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-0.1.5-cp311.py3-none-any.whl
Algorithm Hash digest
SHA256 fb67298715ba83638456badfe40df3f3f012c3e453634649f50c1140c10e1166
MD5 ee06236f1b989574e2f0b64bf9fe4907
BLAKE2b-256 dfad4d2dfcc3302d509cc562346a8e362b6c2e86c87c7428034132162881671c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dm_pure-0.1.5-cp310.py3-none-any.whl
  • Upload date:
  • Size: 43.6 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-0.1.5-cp310.py3-none-any.whl
Algorithm Hash digest
SHA256 1eb695e084617cb33011e09e69970c7270c1a13c482aece75f1b2702739670ba
MD5 4e9e8810fd0fed73c39da0da2509f8c6
BLAKE2b-256 b006b275ea11b23ac166f88d9de78aac3609092f3776810f420d097641a9724b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dm_pure-0.1.5-cp39.py3-none-any.whl
  • Upload date:
  • Size: 43.4 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-0.1.5-cp39.py3-none-any.whl
Algorithm Hash digest
SHA256 3983fea298e9a4407d6051e7f794d0ce7db69e7cdda02ea8ed2706542be22db7
MD5 8898fd772488e72463f1a9ecfbab1ab0
BLAKE2b-256 a6e8debe3b499e2d1434b33919f6f95779c400fe5ead1496d7cab4163f0b39d4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dm_pure-0.1.5-cp38.py3-none-any.whl
  • Upload date:
  • Size: 43.4 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-0.1.5-cp38.py3-none-any.whl
Algorithm Hash digest
SHA256 b9cb92006f40aec1cc0d001132300558364737306e6607d1f6eacd83d9864cbe
MD5 5705e68ade298aaecb288635dfcf4a99
BLAKE2b-256 762c7e7f31bcd818b84ac26824950dc8fd6f4cedbae486cbe3353cb00e0a1d47

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

1.0.0

5 files

This release

0.1.5 This release

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