一键导入
fastapi-settings
Set up pydantic-settings configuration for a FastAPI project with environment variables, .env file support, and dependency injection.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Set up pydantic-settings configuration for a FastAPI project with environment variables, .env file support, and dependency injection.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Generate a complete FastAPI CRUD endpoint with Pydantic v2 schemas, async SQLAlchemy queries, dependency injection, response models, and error handling.
Generate a SQLAlchemy model with matching Pydantic v2 schemas for FastAPI. Includes relationships, indexes, and the correct from_attributes configuration.
Scan a FastAPI project for Pydantic v1 leftovers, async anti-patterns, missing response models, database session issues, and security gaps.
| name | fastapi-settings |
| description | Set up pydantic-settings configuration for a FastAPI project with environment variables, .env file support, and dependency injection. |
Use this skill when a FastAPI project has hardcoded configuration or needs environment-based settings.
Check if pydantic-settings is installed. If not, suggest adding it.
Generate the Settings class:
from pydantic_settings import BaseSettings, SettingsConfigDict
from functools import lru_cache
class Settings(BaseSettings):
# App
app_name: str = "My API"
debug: bool = False
# Database
database_url: str
# Auth
secret_key: str
access_token_expire_minutes: int = 30
# External services
redis_url: str = "redis://localhost:6379"
model_config = SettingsConfigDict(
env_file=".env",
env_file_encoding="utf-8",
case_sensitive=False,
)
@lru_cache
def get_settings() -> Settings:
return Settings()
Generate .env.example with all required variables.
Set up dependency injection:
from typing import Annotated
from fastapi import Depends
SettingsDep = Annotated[Settings, Depends(get_settings)]
Show how to override in tests:
def get_settings_override():
return Settings(database_url="sqlite+aiosqlite:///:memory:")
app.dependency_overrides[get_settings] = get_settings_override