{% extends "main.html" %} {% block tabs %} {{ super() }} {#- Language detection -#} {% set is_zh = (i18n_file_locale | default('en')) == 'zh' %} {#- Translation macro -#} {% macro t(en, zh) %}{% if is_zh %}{{ zh }}{% else %}{{ en }}{% endif %}{% endmacro %}
{{ t("Open Source", "开源项目") }} · Pydantic v2 · Python 3.10+

{{ t("Clean Architecture for Python", "Python 的整洁架构框架") }}

{{ t( "Define business entities, declare relationships, let the framework assemble your data.", "定义业务实体,声明关系,让框架组装数据。" )}}

pip install pydantic-resolve

{{ t("Provides the Missing Layer", "提供了缺失的那一层") }}

{{ t("Components map 1:1 to Clean Architecture — dependency direction always points inward.", "组件与整洁架构一一对应,依赖方向始终指向内层。") }}

{{ t("Enterprise: Entity + ER Diagram", "企业业务规则:实体 + ER 图") }}

{{ t("Define business entities and relationships independent of any framework or database — the stable core everything else derives from.", "定义独立于框架和数据库的业务实体与关系——所有其他层都从中派生的稳定内核。") }}

{{ t("Application: Resolver + resolve/post", "应用业务规则:解析器 + resolve/post") }}

{{ t("Automate data assembly orchestration — resolve loads missing data with batching, post computes derived fields after the tree is ready.", "自动化数据组装编排——resolve 批量加载缺失数据,post 在树就绪后计算派生字段。") }}

{{ t("Adapters: Loader (data access)", "接口适配器:Loader(数据访问)") }}

{{ t("Abstract data sources behind a unified interface. Swap SQLAlchemy for Django or Tortoise ORM — Entity and Response stay untouched.", "用统一接口抽象数据源。从 SQLAlchemy 切换到 Django 或 Tortoise ORM,实体和响应层无需改动。") }}

{{ t("N+1 solved automatically", "自动解决 N+1 问题") }}

{{ t("Replace manual loops with declarative data loading.", "用声明式数据加载替代手动循环查询。") }}

{{ t("Before — N+1 problem", "Before — N+1 问题") }}
# Sprint has 10 tasks, each needs owner
for task in sprint.tasks:
    task.owner = await get_user(task.owner_id)
 # 10 queries!
{{ t("After — pydantic-resolve", "After — pydantic-resolve") }}
class TaskView(BaseModel):
    owner_id: int
    owner: Optional[UserView] = None

    def resolve_owner(self, loader=Loader(user_loader)):
        return loader.load(self.owner_id)
 # 1 query!

{{ t("From ER Model to Use Case", "从 ER 模型到 Use Case") }}

1
{{ t("Define ER Diagram — Enterprise Business Rules", "定义 ER 图 — 企业业务规则") }}
class UserEntity(BaseModel, BaseEntity):
    id: int
    name: str

class TaskEntity(BaseModel, BaseEntity):
    __relationships__ = [
        Relationship(fk='owner_id', target=UserEntity, loader=user_loader),
    ]
    id: int
    name: str
    owner_id: int

class StoryEntity(BaseModel, BaseEntity):
    __relationships__ = [
        Relationship(fk='id', target=list[TaskEntity], loader=task_loader),
    ]
    id: int
    name: str
2
{{ t("Pick fields & hide FK — Use Case Composition", "挑选字段 & 隐藏 FK — 用例的组合") }}
class TaskSummary(DefineSubset):
    __subset__ = (TaskEntity, ('id', 'name'))
    owner: Optional[UserEntity] = None  # implicit match, no AutoLoad

class StoryView(DefineSubset):
    __subset__ = (StoryEntity, ('id', 'name'))
    tasks: list[TaskSummary] = []      # implicit match
3
{{ t("Query root data & resolve — Application Business Rules", "查询根数据 & 解析 — 应用业务规则") }}
@router.get("/stories")
async def get_stories():
    stories = [StoryView.model_validate(s)
               for s in await get_stories_from_db()]
    return await Resolver().resolve(stories)
4
{{ t("Result — fully assembled response", "结果 — 完整组装的响应") }}
[
  {
    "id": 1,
    "name": "Sprint 1",
    "tasks": [
      {
        "id": 101,
        "name": "Implement login",
        "owner": { "id": 1, "name": "Alice" }
      }
    ]
  }
]

{{ t("Progressive learning path", "循序渐进的学习路径") }}

{{ t("Start simple, scale as needed. Each concept builds on the last.", "从简单开始,按需扩展。每个概念都建立在前一个之上。") }}

1 {{ t("resolve_*", "resolve_*") }}
2 {{ t("Nested Structure", "嵌套结构") }}
3 {{ t("post_*", "post_*") }}
4 {{ t("Cross-Layer", "跨层数据流") }}
5 {{ t("ERD + AutoLoad", "ERD + AutoLoad") }}
6 {{ t("GraphQL / MCP / FastAPI", "GraphQL / MCP / FastAPI") }}

{{ t("Everything you need for data assembly", "数据组装的全套工具") }}

{{ t("From loading related data to generating GraphQL APIs — all in one library.", "从加载关联数据到生成 GraphQL API — 一个库全覆盖。") }}

{{ t("Batch Loading", "批量加载") }}

{{ t("Auto-batch queries via DataLoader pattern. 100 lookups become 1 query.", "通过 DataLoader 模式自动批量查询,100 次查询变 1 次。") }}

{{ t("Post Processing", "后处理") }}

{{ t("Compute derived fields after all nested data is resolved. Counts, aggregates, formatting.", "在嵌套数据就绪后计算派生字段:计数、聚合、格式化。") }}

{{ t("Cross-Layer Data Flow", "跨层数据流") }}

{{ t("ExposeAs, SendTo, Collector — pass context down or aggregate data up without traversal code.", "ExposeAs / SendTo / Collector,无需手写遍历逻辑即可跨层传递数据。") }}

{{ t("ER Diagram + AutoLoad", "ER 图 + AutoLoad") }}

{{ t("Centralize relationship declarations. Reuse across models, GraphQL, and MCP services.", "集中管理关系声明,跨模型复用,同时驱动 GraphQL 和 MCP。") }}

{{ t("GraphQL Generation", "GraphQL 生成") }}

{{ t("Auto-generate GraphQL schema and resolvers from your ER Diagram.", "从 ER 图自动生成 GraphQL schema 和 resolver。") }}

{{ t("MCP Service", "MCP 服务") }}

{{ t("Expose GraphQL APIs to AI agents via Model Context Protocol.", "通过 MCP 协议将 GraphQL API 暴露给 AI 代理。") }}

{{ t("Built for your stack", "为你的技术栈而建") }}

{{ t("Works with your existing frameworks and ORMs.", "与你现有的框架和 ORM 无缝集成。") }}

{{ t("Thoroughly Tested, Production Ready", "测试详尽,生产可用") }}

{{ t("849+ Test Cases", "849+ 测试用例") }}

{{ t("Every feature is covered — from core resolution to ER Diagram, cross-layer data flow, and edge cases.", "每个功能都有覆盖——从核心解析到 ER 图、跨层数据流和边界情况。") }}

{{ t("Stable API Contract", "稳定的 API 契约") }}

{{ t("Entity-First architecture keeps your API independent of database changes. No more cascade refactoring.", "Entity-First 架构让 API 独立于数据库变更,不再级联重构。") }}

{{ t("CI / CD Verified", "CI/CD 验证") }}

{{ t("Every commit passes automated CI. Python 3.10–3.13 compatible with continuous integration.", "每次提交通过自动化 CI,兼容 Python 3.10–3.13。") }}

{{ t("Ready to build with Clean Architecture?", "准备好用整洁架构来构建了吗?") }}

{{ t("Define entities, declare relationships, let the framework assemble. Start from resolve_*, scale to ER Diagram when ready.", "定义实体,声明关系,让框架组装。从 resolve_* 开始,准备好了再扩展到 ER 图。") }}

{% endblock %} {% block content %}{% endblock %} {% block footer %}{% endblock %}