Skip to content
Back to skills

Fastapi Services

ASecurity

Build FastAPI endpoints with pydantic models, dependencies, async correctness and tests

  • 5 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 30, 2026
developmentgosqlfastapigitapidatabasesecurity

Works with

  • cli
  • api

Security analysis

A100/100

Scanned November 30, 2026

npx -y skills add AdityaaaTiwari/ANVIL --skill fastapi-services --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Fastapi Services?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Fastapi Services
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/adityaaatiwari-fastapi-services/badge)](https://www.skillsdirectory.com/skills/adityaaatiwari-fastapi-services)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: fastapi-services
description: Build FastAPI endpoints with pydantic models, dependencies, async correctness and tests
---

<!-- Generated by `anvil plugin build` from catalog/. Edit the catalog, not this file. -->

# FastAPI services

Use in projects that depend on `fastapi`.

## Endpoints
- Declare request and response models with pydantic and set `response_model` so internal fields never leak. Check whether the project uses pydantic v1 or v2 (`model_dump` vs `dict`).
- Use dependencies (`Depends`) for database sessions, the current user and permissions. Keep authorization checks in a dependency or the service layer, not copy-pasted in handlers.
- Return correct status codes (`status_code=201` for creation, `HTTPException(404)` for missing objects). Do not return 200 with an error payload.

## Async correctness
- In `async def` endpoints, never call blocking code (sync database drivers, `requests`, `time.sleep`, heavy CPU work). Use async libraries (`httpx.AsyncClient`, async SQLAlchemy) or declare the endpoint with plain `def` so FastAPI runs it in a thread pool.
- Create clients (httpx, database engines) once at startup with the `lifespan` handler, not per request.

## Data and settings
- Settings via `pydantic-settings`, read once. Secrets only from the environment.
- Database sessions: one per request through a dependency that closes it (`yield`).
- Migrations through Alembic. Never call `create_all` in production code paths.

## Security
CORS limited to known origins · OAuth2/JWT validation in a dependency, verifying signature, expiry and audience · password hashing with argon2 or bcrypt · rate limiting on login.

## Verify
Tests with `TestClient` (or `httpx.AsyncClient` with `ASGITransport` for async tests), overriding dependencies with `app.dependency_overrides`. Then `pytest -q`, ruff and the type checker.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.