Sponsored byOutsenseAI that finds your next clients
SponsorGROUOutbound, LinkedIn content and leads for B2B teamsSponsorOutsenseAI that finds your next clientsAd+Your tool hereSeen by people installing AI tools@Weekly picksThe best new tools, one email a week

fastapi-guard

Skill by Guard-Core

Adds security middleware to FastAPI apps, covering IP filtering, rate limiting and per-route security decorators. Built for developers who want to protect a FastAPI service and trial rules safely.

  • Score 80
  • 829 stars
  • MIT
  • Updated
Works withClaude CodeClaude apps Antigravity CLI

Install fastapi-guard

Built from the published package, never by AI.

git clone --depth 1 https://github.com/Guard-Core/fastapi-guard /tmp/fastapi-guard && mkdir -p ~/.claude/skills && cp -r /tmp/fastapi-guard/guard/.agents/skills/fastapi-guard ~/.claude/skills/fastapi-guard

Run in your terminal. Claude Code loads skills from ~/.claude/skills automatically.

Step-by-step: install fastapi-guard in Claude Code

Skills can run scripts on your machine. Some need an API key: check the README.

About

fastapi-guard is a security middleware package for FastAPI applications. It provides IP filtering with whitelists, blacklists, country rules and cloud-provider blocking, plus rate limiting with optional Redis-backed state. It also offers signature-based attack-pattern detection and per-route security decorators that attach rules such as rate limits and authentication to individual endpoints.

The middleware is configured through a SecurityConfig object and added to the app with add_middleware. Passive mode logs suspicious requests without blocking them, which helps trial rules against production traffic. An optional Guard Agent integration sends security events and metrics to the Guard SaaS. The skill is aimed at developers adding this protection to a FastAPI application.

Written from the project's SKILL.md and checked against it.

What it can do

  • IP filteringApplies whitelist and blacklist rules using IPs and CIDR ranges, plus country and cloud-provider checks.
  • Rate limitingSets a global request limit with per-endpoint overrides and optional Redis state.
  • Per-route decoratorsAttaches rules such as rate_limit, require_auth, api_key_auth and ip_filter to single endpoints.
  • Route resolution strict modeBlocks requests whose route cannot be resolved when route_resolution_strict is set to True.
  • Global behavior rulesApplies behavior rules to every route, such as a global 404 watcher.
  • Passive modeLogs suspicious requests and emits events without blocking them.
  • Guard Agent telemetrySends security events and metrics to the Guard SaaS when enable_agent is set to True.

What you need

  • Python 3.10 to 3.14
  • uv or pip to install the package
  • fastapi-guard[agent] extra for SaaS telemetry
  • Guard SaaS API key and project ID for telemetry
  • Redis, optional, for distributed rate limit state

Try asking

  • Add fastapi-guard rate limiting to my FastAPI login endpoint.
  • Set up passive mode to trial IP blacklist rules on my FastAPI app.
  • Protect my /api/payments route with bearer auth and a rate limit.

Good to know

  • Without Redis, rate limits are kept per process.
  • route_resolution_strict=True makes requests to unserved paths return 500 instead of 404.
  • passive_mode=True logs checks but never blocks requests.
  • require_auth and api_key_auth reject requests with 401 when no verifier is supplied.

Security check

A

No download-and-run commands, hidden instructions or signs of sending keys out were found.

Checked automatically: guard/.agents/skills/fastapi-guard/SKILL.md. This looks for known risky patterns and is not a full audit. How grades work

Alternatives to fastapi-guard

All alternatives →

Compare with function_health, windows-privilege-escalation or github-actions-advanced

fastapi-guard: common questions

What does passive mode do in fastapi-guard?

Passive mode runs every check in log-only mode, so suspicious requests are logged and emitted as events but not blocked. The source suggests switching to passive_mode=False once the logs show the rules firing as expected.

Does fastapi-guard rate limiting work across several servers?

Redis is used for distributed state when enable_redis is True, which is the default. Without Redis, limits are per process.

Does fastapi-guard handle authentication by itself?

require_auth and api_key_auth need a verifier callable, given per route or globally in SecurityConfig. Without one, requests are rejected with 401. require_authorization_header only checks that the header is present and is not authentication.

How do I install fastapi-guard?

Run the command above to copy the skill into ~/.claude/skills/. Claude Code picks it up automatically.

Is fastapi-guard free?

The code is published under the MIT licence. The service it connects to may have its own pricing.

Is fastapi-guard safe to use?

It scores 80 of 100. Grades: maintenance A, licence A, quality A. Security check: grade A, no risky patterns found in the files checked. Review the code before you install. How grades work.

What are alternatives to fastapi-guard?

Similar skills: function_health, windows-privilege-escalation, github-actions-advanced, propose-security-hardening.

fastapi-guard Install

Add to stack

Loading.