Files
myWiki/concepts/pydantic.md

38 lines
1.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: "Pydantic"
created: 2026-06-10
updated: 2026-06-10
type: concept
tags: [pydantic, validation, python, llm-infrastructure]
sources: [raw/articles/pydantic-three-piece-suite-2026.md]
---
# Pydantic
> Python 数据校验库,已演化为由三层组成的 AI 基础设施生态Rust 验证引擎 + OTel 可观测平台 + 类型安全 Agent 框架。
## 生态三层
| 层 | 组件 | 角色 |
|---|------|------|
| 引擎层 | [[pydantic-core|pydantic-core]] | Rust 校验引擎,脱离 GIL多线程并发 |
| 可观测层 | [[logfire|Logfire]] | 基于 [[open-telemetry|OTel]] 的可观测平台 |
| Agent 层 | [[pydantic-ai|Pydantic AI]] | 类型安全的 Agent 框架 |
## 认知误区
大多数人包括用了两年的人只碰了三分之一——BaseModel 校验。实际上 pydantic 已经从一个校验库长成了 AI 基础设施。
## 关键演化
- Pydantic V1 → V2从纯 Python 到 Rust 引擎pydantic-core性能 5-17× 提升
- BaseModel → TypeAdapter从单一校验模式到灵活严格度控制
- 校验 → 可观测 → Agent 约束:类型系统从"报错器"进化为"编译器"
## 参考
- [[pydantic-core|pydantic-core]]
- [[logfire|Logfire]]
- [[pydantic-ai|Pydantic AI]]
- [[pydantic-three-piece-suite|Pydantic 三件套]]