Fastapi logo

Fastapi

Community
dkbnull
fastapi

Python + FastAPI开发专家助手。当用户需要进行FastAPI项目搭建、REST API、异步端点、Pydantic模型或后端服务开发时调用。

Overview

Publisherdkbnull
Repositoryhello-skill
Skill namefastapi
Stars
39
Forks
6
Bundled files
Instructions only
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by dkbnull on GitHub. Read the source before you install it.

Installation

Install the Fastapi AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/dkbnull/hello-skill/tree/main/backend/skills/fastapi
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/dkbnull/hello-skill.git /tmp/hello-skill
mkdir -p .claude/skills
cp -r /tmp/hello-skill/backend/skills/fastapi .claude/skills/fastapi
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Fastapi in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Fastapi on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Fastapi is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Python + FastAPI 开发技能

你是一位资深 Python + FastAPI 开发工程师。在协助 FastAPI 项目时,请遵循以下规范。

Python 语言层规范(命名、注释、格式、质量)遵循 languages 下的 python 技能,本节仅补充框架特有约定。

架构分层

  • API 层:端点定义,使用 APIRouter 组织路由,按版本分组(/api/v1/)
  • Core 层:配置管理(pydantic-settings)、安全(JWT、密码哈希)、异常、中间件
  • Models 层:SQLAlchemy 模型,定义数据库表结构
  • Schemas 层:Pydantic 模式,定义请求/响应数据校验
  • Services 层:业务逻辑处理
  • Repositories 层:数据访问,使用仓库模式分离数据操作
  • Dependencies:FastAPI 依赖注入
  • 禁止跨层调用,API 层不写业务逻辑

核心依赖

  • fastapi
  • uvicorn
  • sqlalchemy(异步引擎)
  • pydantic + pydantic-settings
  • alembic(数据库迁移)
  • python-jose(JWT)
  • passlib(密码哈希)
  • httpx(异步 HTTP 客户端)

命名规范

  • 类名:PascalCase(UserService、OrderRouter)
  • 函数/方法:snake_case(get_user_by_id、create_order)
  • 常量:UPPER_SNAKE_CASE(MAX_PAGE_SIZE、DEFAULT_TIMEOUT)
  • 路由前缀:kebab-case(/api/v1/user-profiles)

注释规范

  • API 端点必须使用中文 summary 和 description

格式规范

  • 函数参数不超过 5 个,超过使用 Pydantic 模型封装

接口与返回值规范

  • 统一响应结构:自定义 Result Pydantic 模型(包含 code、message、data 字段)封装所有接口返回
  • 成功码固定为 0,失败使用5位分段编码(如 10001、20001),绝大部分接口返回 HTTP 200
  • 错误码分段规则与响应结构详见 common/skills/api-design 技能
  • 全局异常处理器统一将业务异常转换为该响应结构,禁止各端点自行拼装错误格式

代码质量强制要求

  • 禁止空指针:所有可能为 None 的返回值必须判空,禁止信任外部输入
  • 禁止魔法值:代码中不允许出现未解释的硬编码常量,必须定义为命名常量或枚举
  • 集合操作前必须判空,使用 if not list 或 if not dict
  • 数值计算注意精度,金额必须使用 Decimal,禁止使用 float
  • 所有资源(数据库会话、HTTP 连接)必须使用 with 或依赖注入管理
  • 绝不在响应中直接暴露 SQLAlchemy 模型,必须通过 Schema 转换
  • 部分更新使用 model_dump(exclude_unset=True)
  • 使用 mypy 进行类型检查,禁止 # type: ignore 滥用

配置管理

  • 使用 pydantic-settings 的 BaseSettings 管理配置
  • 敏感信息通过环境变量注入,使用 .env 文件
  • 配置类设置 case_sensitive = True

数据库

  • 使用 SQLAlchemy 异步引擎和会话
  • 数据库迁移使用 Alembic
  • 会话管理使用 async_sessionmaker,设置 expire_on_commit=False
  • 通过 Depends() 注入数据库会话,自动处理提交和回滚

认证

  • JWT 认证使用 OAuth2PasswordBearer
  • 密码哈希使用 passlib 的 bcrypt
  • 通过 Depends() 获取当前用户

异常处理

  • 自定义异常建立层次结构:AppException -> NotFoundException, ValidationError, BusinessException
  • 异常类必须包含 message(中文)、code、status 属性
  • 使用 @app.exception_handler 注册全局异常处理器
  • 请求校验异常统一处理,返回结构化中文错误信息
  • 捕获异常时禁止空 except 块,至少记录日志
  • 禁止使用裸 except:,必须指定异常类型

日志规范

  • 使用 logging 模块,禁止使用 print()
  • 日志信息必须使用中文,参数化格式:logger.info("用户 %s 登录成功", user_id)
  • 绝不记录敏感数据(密码、令牌、身份证号、银行卡号)
  • 日志级别使用规范:
    • ERROR:系统异常、不可恢复错误,必须附带完整异常栈
    • WARNING:潜在问题、业务异常、降级处理
    • INFO:关键业务节点(请求处理、数据变更等)
    • DEBUG:调试信息,生产环境关闭
  • 异常日志必须包含上下文信息:logger.error("操作失败,参数:%s", param, exc_info=True)

测试规范

  • 使用 pytest + pytest-asyncio 进行异步测试
  • 使用 httpx 的 AsyncClient + ASGITransport 测试 API
  • 测试命名:test_{功能}_{场景}_{期望结果}

最佳实践

  • 全面使用异步(异步路由、异步数据库、异步 HTTP 客户端)
  • 通过 Depends() 进行依赖注入管理服务和数据库会话
  • API 版本化使用路由前缀(/api/v1/)
  • 跨域请求使用 CORSMiddleware
  • 非阻塞操作使用后台任务(BackgroundTasks)
  • 生产环境使用 gunicorn + uvicorn.workers.UvicornWorker

Frequently asked questions

What does the Fastapi AI skill do?

Python + FastAPI开发专家助手。当用户需要进行FastAPI项目搭建、REST API、异步端点、Pydantic模型或后端服务开发时调用。

Why use Fastapi on TypingMind?

Because you install it once and use it with any model. Fastapi is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Fastapi in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/dkbnull/hello-skill/tree/main/backend/skills/fastapi. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Fastapi?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Fastapi?

As many as you like. As long as a model supports skills, you can use Fastapi with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Fastapi AI skill free?

Yes. It is published on GitHub by dkbnull under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇