{
  "id": "tneemo/fastapi-api-key",
  "kind": "module",
  "description": "API key authentication for FastAPI: a require_api_key dependency that checks the X-API-Key header against keys from the environment, in constant time.",
  "version": "1.0.0",
  "keywords": [
    "auth",
    "authentication",
    "api-key",
    "apikey",
    "security",
    "fastapi",
    "dependency",
    "header"
  ],
  "requires": {
    "fastapi": ">=0.100",
    "python": "*"
  },
  "provides": [
    "auth",
    "api-key"
  ],
  "license": "MIT",
  "repository": "https://github.com/tneemo/pkg",
  "risk": "ok",
  "quality": 100,
  "downloads": 0,
  "agent_reports": {
    "success": 0,
    "failure": 0,
    "success_rate": 0.5
  },
  "flags": 0,
  "reputation": 0.48,
  "updated_at": "2026-10-19T14:10:36.606Z",
  "latest": "1.0.0",
  "manifest": {
    "$schema": "https://pkg.tneemo.com/schema/pkg.json",
    "name": "fastapi-api-key",
    "version": "1.0.0",
    "kind": "module",
    "description": "API key authentication for FastAPI: a require_api_key dependency that checks the X-API-Key header against keys from the environment, in constant time.",
    "license": "MIT",
    "keywords": [
      "auth",
      "authentication",
      "api-key",
      "apikey",
      "security",
      "fastapi",
      "dependency",
      "header"
    ],
    "stack": {
      "requires": {
        "fastapi": ">=0.100",
        "python": "*"
      },
      "provides": [
        "auth",
        "api-key"
      ]
    },
    "env": {
      "API_KEYS": {
        "description": "Comma-separated list of accepted API keys",
        "example": "dev-key-change-me",
        "required": true
      }
    },
    "repository": "https://github.com/tneemo/pkg"
  },
  "readme": "# fastapi-api-key\n\nAPI key authentication for [FastAPI](https://fastapi.tiangolo.com) services, for machine-to-machine APIs where user accounts would be overkill.\n\n- `require_api_key` is a FastAPI dependency that reads the `X-API-Key` header and accepts any key listed in the `API_KEYS` environment variable (comma-separated, so keys can be rotated without downtime).\n- Comparison is constant time (`hmac.compare_digest`).\n- Missing or wrong keys get `401`; if no keys are configured the API answers `503` instead of silently allowing access.\n- The header shows up in the OpenAPI docs, so `/docs` gets an \"Authorize\" button.\n",
  "integration": "1. Protect a whole router (for example in `app/main.py` of `tneemo/fastapi-service`):\n   ```python\n   from fastapi import Depends\n   from app.security import require_api_key\n\n   app.include_router(items.router, prefix=\"/items\", dependencies=[Depends(require_api_key)])\n   ```\n   or a single route: `@router.get(\"/\", dependencies=[Depends(require_api_key)])`.\n2. Set `API_KEYS` (comma-separated) in the environment or `.env`. In tests use `monkeypatch.setenv(\"API_KEYS\", \"test-key\")` and send `headers={\"X-API-Key\": \"test-key\"}`.\n",
  "files": [
    {
      "path": "app/security/__init__.py",
      "size": 80
    },
    {
      "path": "app/security/api_key.py",
      "size": 872
    },
    {
      "path": "tests/__init__.py",
      "size": 0
    },
    {
      "path": "tests/test_api_key.py",
      "size": 855
    }
  ],
  "checks": {
    "risk": "ok",
    "quality": 100,
    "findings": []
  },
  "integrity": "sha256-mZPtuLrYeuNlqW1CT62jAeDxgJOB1xC65w+4D0fgoq0=",
  "publisher": "admin:tneemo",
  "published_at": "2026-10-19T14:10:36.606Z",
  "versions": [
    {
      "version": "1.0.0",
      "published_at": "2026-10-19T14:10:36.606Z",
      "risk": "ok",
      "yanked": false
    }
  ]
}