Token导航 LogoToken导航TokenDH.com
前端设计敏感数据github未标认证来源可访问许可证需确认审计通过

python-fastapiPython FastAPI 测试

Agent Skill

用于辅助 Python 项目开发、测试、依赖管理和常见框架工作流。它适合让 Agent 阅读 Python 代码、定位测试问题、整理运行命令、生成脚本或分析数据处理逻辑。使用时需要确认项目虚拟环境、依赖版本和测试入口;涉及执行脚本、读写文件、访问数据库或调用外部 API 时,应先明确运行目录和输入输出范围,避免误改生产数据。

总安装

210

周安装

9

GitHub Stars

1

下载量

73
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:python-fastapi(Python FastAPI 测试)
来源仓库:https://github.com/karibulab/skills
仓库路径:skills/python-fastapi
安装命令:
npx skills add https://github.com/karibulab/skills --skill python-fastapi
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/karibulab/skills --skill python-fastapi

简介

专为 FastAPI 框架开发提供端到端支持。

  • 适合路由设计、Pydantic 模型定义与异步处理。
  • 自动生成 OpenAPI 文档与测试用例。
  • 需明确请求/响应格式与状态码约定。python-fastapi 属于前端设计类 Skill,可作为该场景下的辅助能力补充。
  • 生产部署时应配置 HTTPS 与速率限制策略。

SKILL.md

python-fastapi

This skill defines how to build APIs using FastAPI following best practices in architecture, security, maintainability, and performance. This is the minimum acceptable standard.

When to use

Use when you need to build APIs using FastAPI following best practices in architecture, security, maintainability, and performance.

Instructions

1. Core Principles

  1. Secure by default.
  2. Strict typing and strong validation.
  3. Clear separation of concerns.
  4. No business logic inside routers.
  5. Zero hardcoded secrets.
  6. Fail closed, not fail open.

If it "works but is insecure", it does not work.


2. Project Structure

Recommended minimum structure:

app/
 ├── main.py
 ├── api/
 │    ├── deps.py
 │    └── v1/
 │         ├── routes_x.py
 ├── core/
 │    ├── config.py
 │    ├── security.py
 │    └── logging.py
 ├── services/
 ├── repositories/
 ├── models/
 └── schemas/

Rules:

  • api/ → endpoints only.
  • services/ → business logic.
  • repositories/ → data access.
  • schemas/ → Pydantic request/response models.
  • core/ → configuration, security, cross-cutting concerns.

Everything inside main.py is not minimalism. It is chaos.


3. Secure Configuration

3.1 Environment Variables

Use pydantic-settings.

from pydantic_settings import BaseSettings

class Settings(BaseSettings):
    app_name: str
    environment: str
    secret_key: str
    database_url: str
    access_token_expire_minutes: int = 15

    class Config:
        env_file = ".env"

Rules:

  • No default values for secrets.
  • No secrets in the repository.
  • .env files are forbidden in production.

4. Authentication Security

4.1 Never Custom Authentication

Use: - OAuth2 + JWT - Or a trusted identity provider (Auth0, Cognito, Keycloak, etc.)

4.2 Secure JWT

  • Signed with HS256 or RS256.
  • Short expiration time.
  • Validate:

- exp - iss - aud

Never trust the payload without verifying the signature.


5. Endpoint Security

5.1 Dependency Injection for Security

from fastapi import Depends, HTTPException, status

def get_current_user(token: str = Depends(oauth2_scheme)):
    ...

Rules:

  • Every sensitive route must require authentication.
  • Separate authentication from authorization.
  • Implement explicit RBAC or ABAC.

5.2 Strict Validation with Pydantic

Always use models:

class UserCreate(BaseModel):
    email: EmailStr
    password: constr(min_length=12)

Rules:

  • Never accept raw dicts.
  • Avoid Any unless absolutely necessary.
  • Limit string sizes.
  • Validate nested structures.

6. OWASP Top 10 Protection

6.1 Injection

  • Never build SQL queries manually.
  • Use ORM or parameterized queries.
  • Enforce strict typing.

6.2 Excessive Data Exposure

Never return:

  • Password hashes
  • Tokens
  • Internal fields
  • Stack traces

Use explicit response models:

@router.get("/", response_model=UserResponse)

6.3 Error Handling

Do not expose internal errors.

@app.exception_handler(Exception)
async def global_exception_handler(request, exc):
    return JSONResponse(
        status_code=500,
        content={"detail": "Internal server error"},
    )

Log internally. Do not leak details externally.


7. Rate Limiting and Abuse Protection

Implement rate limiting:

  • SlowAPI or equivalent.
  • Or external gateway (NGINX, API Gateway).

Rules: - Never expose login without rate limiting. - Never expose public endpoints without abuse control.


8. Secure CORS

Never:

allow_origins=["*"]
allow_credentials=True

Explicitly configure allowed origins per environment.


9. Secure Logging

  • Do not log passwords.
  • Do not log tokens.
  • Do not log sensitive data.
  • Use structured logging (JSON).
  • Include request_id.

If you feel the need to log the full request body, rethink your architecture.


10. File Upload Security

If uploads are allowed:

  • Enforce size limits.
  • Validate MIME type.
  • Do not trust file extensions.
  • Never execute uploaded content.
  • Store outside public root.

11. Production Hardening

11.1 Server

Never use:

uvicorn main:app --reload

Use:

  • Gunicorn + Uvicorn workers
  • Proper worker configuration
  • Reverse proxy in front

11.2 Security Headers

Add:

  • X-Content-Type-Options
  • X-Frame-Options
  • Content-Security-Policy
  • Strict-Transport-Security

Preferably via middleware or reverse proxy.


12. Mandatory Testing

At minimum:

  • Authentication tests.
  • Authorization tests.
  • Validation tests.
  • Error handling tests.

Testing only the happy path is self-deception.


13. Code Quality Standards

  • Full typing.
  • mypy enabled.
  • ruff or flake8.
  • black mandatory.
  • No logic in decorators.
  • No side effects at import time.

14. What NOT To Do

  • Do not expose /docs in production without authentication.
  • Do not use DEBUG=True.
  • Do not return raw exceptions.
  • Do not trust frontend input.
  • Do not mix sync and async blindly.
  • Never use eval.

15. Pre-Deployment Checklist

  • Environment variables secured
  • Secrets outside repository
  • Rate limiting enabled
  • Restricted CORS
  • Logs free of sensitive data
  • JWT validates signature and expiration
  • Auth tests passing
  • Dependencies updated
  • /docs protected or disabled

If this checklist is not satisfied, it is not a deployment. It is a gamble.

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

36.6%
按下载量换算27

Claude

27.49%
按下载量换算20

Cursor

20.29%
按下载量换算15

Gemini CLI

8.89%
按下载量换算6

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

敏感数据

该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills