dpe-sdk
DPE(Document / Page / Element)协议的 Python SDK:把结构化文档正确、增量、可靠地投递到任意 DPE 服务端。
- sans-IO 协议核心 + httpx 传输适配(sync / async);
- 只接受 remote URL 与可插拔的
CredentialProvider,不封装任何服务端私有端点; - hash 由
dpe-hash计算(同版本精确依赖); - 规范与源码:https://github.com/A2C-SMCP/dpe-protocol。
数据模型
三层对象(core §2)是 pydantic v2 模型:线上对象 ElementObject / PageObject / DocumentObject(子对象以 hash 列表引用),以及展开视图 Document / Page(页与元素内联)。
from dpe_sdk import Document, ElementObject, Page
doc = Document(
file_type="md",
title="A",
pages=[Page(elements=[ElementObject(category="NarrativeText", text="hello")])],
)
doc.doc_hash() # "dpe1:…"
doc.hashes() # {"doc_hash", "pages": [{"page_hash", "elements"}…]}
- 校验全部交给
dpe-hash,顺序与错误码遵循 core §2.8;封闭 schema、category 允许的字段、file_type 枚举都取自dpe_hash的常量; - 构造、
model_validate、model_validate_json失败时抛dpe_hash.DpeHashError,带规范错误码code与违例位置path(RFC 6901);model_validate_json按 I-JSON 严格解析(拒绝重复键); - 模型保留输入的原样表示,序列化只输出显式给出的字段;null 与缺省、metadata 缺省与
{}是否等价由 hash 判定(core §2.7)。
协议错误与响应报文
dpe_sdk.errors:core §6 的每个错误码一个异常类(基类DpeError),带code与retryable(只表示原样重试可能成功);from_problem(problem, retry_after)按 problem 体的code构造异常(含missing清单与Retry-After),不按 HTTP 状态码分派;core §6 之外的码构造为UnknownCodeError;- 客户端本地判定不经
DpeError:本地判定为不合法时(目前如get_skeleton的uri不符合 core §1.1)在发请求前即抛dpe_hash.ValidationError(ValueError子类,code仍为DPE_VALIDATION);响应不合规抛UnexpectedResponseError。捕获DpeError的调用方请按需一并处理; dpe_sdk.wire:各端点的响应模型(Capabilities、Head、Skeleton、ListPage、CommitResult等);信封对未知成员宽容,内嵌的三层对象仍是封闭 schema。
参考服务端(testing)
dpe_sdk.testing.Engine 是内存版 DPE 服务端的核心引擎(不含传输),按规范的求值顺序实现 core 语义(含暂存会话与分块上传,#43),供集成测试与第三方实现对照:
from dpe_sdk.testing import Engine, EngineConfig, IfAbsent
engine = Engine(EngineConfig(max_payload_bytes=1 << 20))
body = b'{"document": {"file_type": "md", "pages": []}}'
engine.commit(
"caller", "s3://bucket/a.md", body, "dpe1", IfAbsent()
) # CommitResult(status="created", …)
engine.head("caller", "s3://bucket/a.md", "dpe1")
# 暂存路径:negotiate → upload_*(页 / 元素 / blob,支持分块与断点查询)→ commit 引用会话
session = engine.negotiate("caller", negotiate_body, "dpe1") # NegotiateResult
engine.upload_page("caller", session.staging_session.id, page_hash, page_bytes, "dpe1")
engine.upload_offset("caller", session.staging_session.id, page_hash) # 断点查询,不续期
- 带 JSON 请求体的操作(
batch_head、negotiate、commit、move)接收原始字节,传输层上限、I-JSON、契约声明、请求信封、对象校验、授权、前置条件都在引擎内按 core §3.3、§3.4、§5.2 的顺序判定;upload_page/upload_element/upload_blob按 HTTP 绑定 §4.6、§4.7 的两套阶梯处理,结果为UploadResult(含续期后的expires_at与下一层缺失清单); - negotiate 与上传响应的缺失清单、commit 的可得性判定使用同一去重范围;可配置限额、受支持契约(第一个为主契约)、去重范围(
DedupScope.DOCUMENT/WRITABLE)与可插拔授权器(can_write/can_force); EngineConfig的clock与session_id_factory可注入(会话过期与确定性测试);- 错误以
dpe_sdk.errors抛出(分块偏移不连续为UploadOffsetError,带offset)。HTTP(ASGI)与一致性测试钩子随 #44、#45 接入。
客户端协议核心、传输适配与增量推送尚在开发中(#12–#17)。
Metadata
Release files for dpe-sdk 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| dpe_sdk-0.2.1.tar.gz | 60.1 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| dpe_sdk-0.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 133.8 kB
Release files / dpe_sdk-0.2.1.tar.gz
| Download URL | dpe_sdk-0.2.1.tar.gz |
|---|---|
| Size | 60.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
63bd49d0af5b515b1e83e11e67ac4e775527e04e8f1cd6d7c7eae97505225bd8
|
|
BLAKE2b-256 checksum How to use checksums |
7d3daf0ba3e1c2b081af7101a26805c4a77ef9a5006a40cb9a7fff55cdad116a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 9, 2026.
Transparency logRelease files / dpe_sdk-0.2.1-py3-none-any.whl
| Download URL | dpe_sdk-0.2.1-py3-none-any.whl |
|---|---|
| Size | 73.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f0f069e7bfa55d934cb2d38567f9db89d96e34719965e2045213957a61e8eca1
|
|
BLAKE2b-256 checksum How to use checksums |
13680001fad340d00217cce246cf6476a445ebda9286a258a711cc9cf8838979
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 9, 2026.
Transparency logSecurity for dpe-sdk 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for dpe_sdk-0.2.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 9, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.