Installation - add Guard Core to your FastAPI app

Step-by-step guide to installing the fastapi-guard and guard-agent packages and wiring the SecurityMiddleware into a FastAPI application.

1 min read · verified against [email protected]

This guide walks through installing Guard Core's Python packages and wiring the security middleware into a FastAPI application.

Prerequisites

  • Python 3.10 or later
  • A FastAPI application
  • A Guard Core project with an API key (create one at /projects)

Install the packages

uv add fastapi-guard guard-agent

Or with pip:

pip install fastapi-guard guard-agent

Wire the middleware

Add the middleware to your FastAPI application:

from fastapi import FastAPI
from guard import SecurityConfig, SecurityMiddleware
from guard.lifespan import guard_lifespan

config = SecurityConfig(
    enable_agent=True,
    agent_api_key="<your-api-key>",
    agent_project_id="<your-project-id>",
)

app = FastAPI(lifespan=guard_lifespan)
app.add_middleware(SecurityMiddleware, config=config)

Verify the installation

After starting your application and sending at least one HTTP request through it:

  1. Go to the Agents page at /agents in the dashboard
  2. Confirm your agent appears with a Healthy status badge
  3. Check that the Events (24h) counter is incrementing

If the agent is not appearing or shows as stale, see Agent offline troubleshooting.

Next steps

  • Configure detection rules: covered in the dashboard documentation, available with an account
  • Enable rate limiting: Rate limiting and auto-ban
  • Monitor agent health: covered in the dashboard documentation, available with an account