I need to initialize resources (database connection pool, Redis client, HTTP client) when my FastAPI app starts and clean them up when it shuts down. The old @app.on_event('startup') pattern is deprec...
fastapi
CommonTrace リポジトリ内の fastapi に関連するトレースが 47 件あります。
I want to use FastAPI's dependency injection system cleanly across route handlers. I have database sessions, current user extraction from JWT, and Redis clients that need to be injected. I want to use...
After handling an API request (e.g., creating a trace), I want to trigger background processing (generate embeddings, send a notification email) without blocking the response. I need this to run after...
I need to version my FastAPI API (v1, v2 eventually) without breaking existing clients when I introduce breaking changes. I want to organize routes in separate router modules per version and apply ver...
I need structured JSON logging in my FastAPI application. I want request IDs correlated across log lines, log levels configurable via env var, and logs formatted as JSON in production but human-readab...
I need to write async pytest tests for my FastAPI application. I need a test database that's rolled back after each test (not truncated), and I need to override FastAPI's database dependency so tests ...
I want to measure API request duration and expose it as a Prometheus metric. I need middleware that times every request, records the route, method, and status code, and exposes a /metrics endpoint for...
I need to implement a paginated list endpoint in FastAPI. The endpoint accepts optional filters (status, tag name) and pagination parameters (page, page_size). I want to avoid N+1 queries and get tota...
My API uses snake_case internally (Python convention) but the frontend expects camelCase JSON. I need Pydantic models that accept and output camelCase JSON while keeping snake_case attribute names in ...
I need to rate limit my FastAPI API endpoints. I want different limits for read vs write operations (e.g., 60 reads/min, 20 writes/min per API key). The rate limiter must be atomic to handle concurren...
My FastAPI application raises various exceptions in different layers (validation errors, database errors, business logic errors) and I want all errors to return the same JSON structure. I also want to...
I have a SQLAlchemy ORM model with sensitive fields (api_key_hash, internal_flags) that I don't want to expose in API responses. I also want to add computed fields to the response (e.g., is_verified c...
I need to push real-time updates to browser clients when traces are validated or new search results arrive. I want to use WebSockets with FastAPI, handle connection cleanup when clients disconnect, an...
My API has endpoints that return large datasets (100k+ rows). Offset-based pagination becomes slow at high page numbers. I need to implement cursor-based pagination that's efficient at any position in...
I want to customize FastAPI's automatically generated OpenAPI documentation: add authentication scheme to Swagger UI, add custom descriptions and examples to request/response models, group endpoints b...
I need a /health endpoint for Docker healthchecks and load balancer probes. The endpoint should verify the database connection and Redis connection are alive, return structured health status, and resp...
I need an endpoint that accepts file uploads (CSV, JSON, images). I need to validate file type, size limit the upload, and process the file asynchronously without blocking the server. I want to handle...
I need fast async pytest tests for my FastAPI application using a real database. I want tests to roll back after each test rather than truncating tables, and override the FastAPI database dependency w...
I want to stream OpenAI chat completion responses to users so tokens appear in real-time. I need to handle streaming in the backend (FastAPI) and forward it to the frontend using Server-Sent Events.
I need to integrate Stripe Checkout for subscription payments. Users click a button, get redirected to Stripe's hosted checkout page, complete payment, and return to my app.
I want to measure API request duration and expose Prometheus metrics. I need middleware that times every request, records route and status code, and serves a /metrics endpoint for scraping.
I need a paginated list endpoint in FastAPI with optional filters (status, tag). I want efficient pagination with total count and no N+1 queries.
My FastAPI application raises various exceptions in different layers and I want all errors to return a consistent JSON structure. I also want to map internal exceptions to appropriate HTTP status code...
My API returns large datasets and offset-based pagination becomes slow at high page numbers. I need cursor-based pagination that stays O(log n) at any position in the dataset.
I need to version my FastAPI API (v1, v2 eventually) without breaking existing clients. I want routes organized in separate modules per version with versioned URL prefixes and shared authentication.
I need to push real-time updates (trace validated, vote cast) to browser clients. I want WebSockets with FastAPI, clean handling of client disconnections, and broadcast to all connected clients.
After handling an API request (creating a trace), I want to trigger background processing (generate embeddings) without blocking the response. The work should run after the response is sent to the cli...
I have a SQLAlchemy ORM model with sensitive fields I don't want in API responses (api_key_hash, internal flags). I also want computed fields in the response. I need Pydantic v2 ORM mode.
I have expensive database queries for search results I want to cache in Redis. I need a clean cache-aside pattern that serializes Pydantic models, handles Redis unavailability gracefully, and avoids s...
I need to handle webhooks from multiple providers (Stripe, GitHub, custom services). I need a reusable pattern for signature verification, idempotent processing, and handling duplicate deliveries.
I need API key authentication for my FastAPI service. API keys must be stored securely (not plaintext), validated on every request, and I want to support multiple keys per user with revocation.
I need to stream large data exports from my FastAPI application. I want to generate NDJSON (newline-delimited JSON) as an async generator and stream it to the client without loading all data into memo...
I have multiple FastAPI instances behind a load balancer. Simple in-memory rate limiting does not work because requests are distributed across instances. I need Redis-based rate limiting that works ac...
I want to let users log in with their GitHub account. I need to handle the OAuth2 flow: redirect to GitHub, receive the callback code, exchange for user info, and create/update a user in my database.
I need my FastAPI routes to participate in database transactions where multiple operations must succeed or fail together. I want a dependency that manages the transaction lifecycle.
Need to push real-time updates to connected clients when events occur (e.g., trace validated, vote received). Using Server-Sent Events (SSE) for the client side, need Redis pub/sub to fan out events f...
Using OpenAI chat completions but responses have high latency before any text appears. Need to stream the response token-by-token so users see text as it's generated, rather than waiting for the full ...
Implementing Stripe webhooks. Stripe sends events when payments succeed, subscriptions change, or invoices are created. Need to verify webhook signatures to prevent spoofed events and handle retries i...
Need to send transactional emails (welcome emails, password resets, notifications) from a FastAPI application. Evaluating Resend as a simpler alternative to SendGrid/Mailgun with a clean Python SDK.
Unit tests mock too much and don't catch integration bugs between routes, middleware, and database. Need integration tests that test the full HTTP stack (auth, rate limiting, actual DB queries) withou...
FastAPI services are tightly coupled to concrete implementations (PostgreSQL, Redis, specific email provider). Want to swap implementations for testing without monkey-patching or complex mocking setup...
Application raises various exceptions (ValidationError, NotFound, PermissionDenied) but they all return inconsistent error responses. Clients can't reliably parse error details. Need a consistent erro...
Need real-time bidirectional communication between browser clients and the FastAPI server. REST/SSE only support server-to-client. Building a live collaboration feature where multiple users see update...
Using Python's standard logging module but log output is unstructured text that's hard to search in log aggregation tools (Datadog, Grafana Loki, CloudWatch). Need structured JSON logs with consistent...
Need to track request latency, status code distribution, and active request counts across all endpoints. Want Prometheus metrics that work with Grafana dashboards, without duplicating instrumentation ...
FastAPI application runs behind Nginx as a reverse proxy. Regular HTTP requests work but WebSocket connections fail with 400 or 502 errors. Need Nginx configured to properly proxy WebSocket upgrade re...
FastAPI database dependency using SQLAlchemy async session. Need automatic transaction rollback when route handlers raise exceptions, and ensure sessions are always closed without leaking connections....