第六章:Python SDK 原理

Dynamo 的 Python SDK 通过 PyO3 实现 Rust-Python 互操作,提供简洁的服务定义接口。

本章概述

本章深入解析 Dynamo 的 Python SDK,包括 Rust-Python 互操作、PyO3 绑定实现、服务装饰器、DynamoService 类以及 CLI 工具。


子文档列表

序号文件主题内容简介
101-rust-python-interop.mdRust-Python 互操作FFI、PyO3、Maturin
202-pyo3-bindings.mdPyO3 绑定实现核心类、LLM 类、异步支持
303-service-decorators.md服务装饰器@service、@dynamo_endpoint、@depends
404-dynamo-service-class.mdDynamoService 类继承关系、链接、端点管理
505-cli-tools.mdCLI 工具dynamo serve、配置文件

阅读顺序建议

flowchart LR A["01-Rust-Python 互操作"] --> B["02-PyO3 绑定"] B --> C["03-服务装饰器"] C --> D["04-DynamoService 类"] D --> E["05-CLI 工具"] style A fill:#e1f5fe style B fill:#e1f5fe style C fill:#fff3e0 style D fill:#fff3e0 style E fill:#e8f5e9

关键概念速查

概念说明详见文档
PyO3Rust-Python 绑定库01-rust-python-interop.md
@service服务定义装饰器03-service-decorators.md
@dynamo_endpoint端点定义装饰器03-service-decorators.md
@depends依赖注入装饰器03-service-decorators.md
DynamoService服务基类04-dynamo-service-class.md
dynamo serve服务启动命令05-cli-tools.md

架构总览

graph TB subgraph python["Python 层"] Service["@service 装饰器"] Endpoint["@dynamo_endpoint"] Depends["@depends"] CLI["dynamo serve"] end subgraph pyo3["PyO3 绑定"] PyRuntime["PyDistributedRuntime"] PyComponent["PyComponent"] PyEndpoint["PyEndpoint"] end subgraph rust["Rust 层"] Runtime["DistributedRuntime"] Component["Component"] Endpoint2["Endpoint"] end Service --> PyRuntime Endpoint --> PyEndpoint Depends --> PyComponent PyRuntime --> Runtime PyComponent --> Component PyEndpoint --> Endpoint2

下一章

完成本章阅读后,建议继续阅读 第七章:HTTP API 层原理,了解 Dynamo 的 HTTP 接口设计。