@aid-framework/generator-py-fastapi

中文文档
0.1.98发布于 2026/11/03Apache-2.0TypeScriptES Module构建来源已验证近 30 天下载 1.1万

The AID Framework py-fastapi target generator: turns IR into a thin FastAPI app that binds to the aid-runtime-python library for everything it does at runtime.

原始使用文档
文档目录10 节
  1. Install
  2. Use it
  3. What it emits
  4. Serving it
  5. Capabilities
  6. The business/ seam
  7. Determinism
  8. Programmatic use
  9. Related packages
  10. License

@aid-framework/generator-py-fastapi

The Python target for AID Framework. It compiles an IR into a FastAPI service whose behaviour lives in aid-runtime-python, and whose prompts and tool handlers live in a business/ tier the compiler never touches.

app.spec.yaml ──aid gen──▶ app/generated/  (compiler)
                           app/business/   (you)

Install

npm install --save-dev @aid-framework/generator-py-fastapi

Requires Node.js 24 or newer. In practice you pull it in through @aid-framework/cli, which is also Node.

Use it

Declare the target, then generate:

project:
  name: support-copilot
  targets:
    - py-fastapi
npx aid gen
py-fastapi: 16 created, 0 updated, 0 unchanged, 0 kept

With no --target, aid gen emits the first target the spec declares, so a Python-only project never has to name its own target.

What it emits

PathContents
app/generated/__init__.pyPackage marker
app/generated/deps.pyThe FastAPI app object and dependency wiring
app/generated/requests.pyRequest models per HTTP-served pipeline
app/generated/schemas.pyPydantic models derived from the IR's types
app/generated/gateway/models.pyModelSpec values and pinned aliases from the IR
app/generated/observability.pyTracer setup
app/generated/contracts/The protocol each business module must satisfy
app/generated/pipelines/One module per pipeline: the step wiring, as ordinary async code
app/generated/prompts/The registry the IR's prompts resolve into
app/generated/tools/Tool definitions and dispatch
app/generated/evals/The eval dataset and gate thresholds
app/generated/routes/HTTP routes for pipelines with an http trigger
app/business/, app/business/prompts/, app/business/tools/Your seam — created once, then never touched

The exact file set follows the spec: a spec that declares no retrievers emits no retrieval modules, and a spec with no HTTP trigger emits no routes.

Serving it

The generator owns the routes; the application decides what to mount and how to run it. That entry point is hand-written — app/main.py:

from fastapi import FastAPI

from app.generated.routes.answer_ticket import answer_ticket_router

app = FastAPI(title="support-copilot", version="0.1.0")
app.include_router(answer_ticket_router)
pip install aid-runtime-python "fastapi>=0.115,<1" "uvicorn>=0.30,<1"
uvicorn app.main:app --reload

deps.py provides build_deps() and get_deps() — the process-wide container of the gateway, prompt registry and tool executor. It does not create an ASGI app: mounting is yours, so a regeneration cannot take it away.

The generator never writes main.py or a pyproject.toml, because packaging and mounting are application decisions rather than spec content.

Capabilities

The manifest declares what this target can honour, and the IR's capability gate rejects a spec that needs anything else:

http-trigger, json-schema, streaming, tool-calling, otel,
embeddings, rerank, guardrails, agents, cursor-memory

It emits against Pydantic for structured output and otel-genai for tracing.

Declaring a capability is not a claim that every field in that section is expressible. A declaration this target cannot honour is rejected at generation time with a diagnostic naming the field, rather than silently dropped.

The business/ seam

Everything in generated/ is replaced on the next aid gen. business/ is created only if it is missing and is never written again — that is where prompts, tool handlers and domain logic belong.

app/generated/contracts/ is the contract between the two: it declares what each business module must provide, so a missing or misnamed handler is a type error in your editor instead of an exception in production.

Determinism

Given the same IR, this generator produces byte-identical output — no timestamps, no absolute paths, no host names. That is what makes generated/ diffable and golden-file tests meaningful, and it is enforced by the generator's own tests rather than by convention.

Programmatic use

import { PACKAGE, TARGET, manifest, plan } from '@aid-framework/generator-py-fastapi';
import type { Generator } from '@aid-framework/generator-sdk';

The generator satisfies the Generator contract from @aid-framework/generator-sdk: plan(ir) is pure and emit(plan) returns the file set, with all regeneration safety supplied by the SDK.

License

Apache-2.0. Code generated by AID Framework is not subject to this license.

版本与发布记录

@aid-framework/generator-py-fastapi 共发布 52 个版本,首次发布于 2026/10/31;过去 12 个月发布了 52 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.1.98latest2026/11/032 天前
0.1.972026/11/032 天前
0.1.962026/11/033 天前
0.1.952026/11/033 天前
0.1.942026/11/033 天前
0.1.932026/11/033 天前

关于 @aid-framework/generator-py-fastapi 的常见问题

@aid-framework/generator-py-fastapi 是什么?

The AID Framework py-fastapi target generator: turns IR into a thin FastAPI app that binds to the aid-runtime-python library for everything it does at runtime.

如何安装 @aid-framework/generator-py-fastapi?

在项目目录运行 npm install @aid-framework/generator-py-fastapi,或使用 pnpm add / yarn add / bun add。

@aid-framework/generator-py-fastapi 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@aid-framework/generator-py-fastapi 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@aid-framework/generator-py-fastapi 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=24。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@aid-framework/generator-py-fastapi 可以商用吗?

@aid-framework/generator-py-fastapi 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@aid-framework/generator-py-fastapi 的下载量有多少?

根据 npm 官方下载统计,@aid-framework/generator-py-fastapi 在 2026/10/06 – 2026/11/04 这 30 天内被下载 10,703 次,日均约 357 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@aid-framework/generator-py-fastapi 还在维护吗?

最新版本 0.1.98 发布于 2026/11/03(2 天前);至今共发布 52 个版本,其中过去 12 个月发布了 52 个;首次发布于 2026/10/31。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。