Keploy as a FastAPI testing framework
Keploy tests FastAPI applications by recording real requests through the running ASGI server and every async database or HTTP call they trigger, then replaying both as assertions. There are no dependency_overrides to register and no TestClient to construct.
keploy record -c "uvicorn app.main:app --port 8000"What Keploy gives a FastAPI team
Any FastAPI app, unchanged
Keploy runs the app through uvicorn, hypercorn, or gunicorn with uvicorn workers. Routers, sub-applications, and lifespan handlers all execute because capture happens at the socket rather than inside Starlette.
- FastAPI 0.95 and above
- uvicorn, hypercorn, or gunicorn
- Routers and mounted sub-apps
- Lifespan startup actually runs
Why FastAPI integration tests slow teams down
The friction is rarely the assertions. It is everything around them — spinning up dependencies, keeping mocks honest, and repairing tests after every refactor.
Testing FastAPI: by hand, with pytest + TestClient, or with Keploy
TestClient drives the app in-process with providers swapped out. Keploy records the running uvicorn server, so the app under test is the one you deploy and the real Depends chain executes.
Select any row for the full comparison, with code.
What you write for FastAPI vs what Keploy records
All three produce the same assertion. Only the third still passes after the next refactor without anyone editing it.
The route, its Depends chain, and Pydantic response validation are all absent — this only proves the service function works with the shapes you typed.
Idiomatic and fast — and both providers are overridden, so the real repository and payment client are never exercised by this test at all.
Pydantic validation, the auth dependency, and the real asyncpg query all ran on the way to this response — none of which a dependency_overrides test covers.
Times are estimates for authoring one endpoint’s coverage from scratch, not measurements.
FastAPI testing tools, compared
The options a team on Python actually reaches for, and where each one genuinely wins. Select a row for the full comparison.
Assessments reflect each tool’s documented behaviour, not benchmark measurements.
Record your FastAPI app once, replay it forever
Keploy sits below your FastAPI process at the network layer. It watches the calls your app already makes, then serves them back on replay so tests run with no dependencies attached.
Keploy records a GET call to /api/v1/orders/{id} on a FastAPI service and captures the dependency calls it makes.
What Keploy mocks for FastAPI, with zero config
7 of the 7 dependencies a typical FastAPI service talks to are stubbed from the recording itself — no mock classes, no fixture files, no containers in CI.
- Auto-mocked
PostgreSQLView page
Postgres protocol under asyncpg and SQLAlchemy
- Auto-mocked
MySQLView page
MySQL protocol under aiomysql
- Auto-mocked
RedisView page
RESP under redis-py asyncio
- Auto-mocked
MongoDBView page
Wire protocol under Motor
- Outbound HTTPAuto-mocked
Outbound HTTP
Any httpx AsyncClient or aiohttp call
- Auto-mocked
Apache KafkaView page
Kafka protocol under aiokafka
- Auto-mocked
gRPCView page
HTTP/2 framed calls from grpcio
Your first FastAPI test suite in under five minutes
Every command below runs against your existing FastAPI service. Nothing in your source tree changes.
1Install the Keploy CLI
A single binary. It needs a Linux kernel with eBPF support, or Docker on macOS and Windows — and it adds nothing to your project's dependencies.
curl -sSL https://keploy.io/install.sh | bash2Record your service
Pass the command you already use to start the app. Keploy runs it and watches every socket it opens.
keploy record -c "uvicorn app.main:app --port 8000"3Exercise the paths you care about
Drive the running server. Every request becomes a test case with its async database and httpx calls captured alongside.
curl -X POST localhost:8000/orders/ord_1/confirm -H 'Content-Type: application/json' -H 'Authorization: Bearer $TOKEN' -d '{"payment_token":"tok_123"}'4Replay in CI
Replay serves the recorded dependency responses, so the job needs no service containers and no Docker daemon.
keploy test -c "uvicorn app.main:app --port 8000" --delay 10
Ready to try it on your own FastAPI service?
Works with the rest of your FastAPI stack
Keploy records at the network layer, so framework and driver choices inside your FastAPI app do not change how it captures traffic.
Python
The language page covers driver-level coverage in depth.
Pydantic
Response validation runs on every recorded request.
SQLAlchemy
Async queries record as the SQL they emit.
PostgreSQL
asyncpg traffic records at the protocol layer.
Celery
Task enqueues appear as broker traffic on the recording.
Docker
Record in a container or on the host; replay needs neither.
Testing the rest of your stack
- Languages
Keploy as a Python testing framework
Turn the requests your Python service already handles into a pytest-grade regression suite, with every dependency mocked from the recording.
Read the guide - Databases
Keploy as a PostgreSQL testing framework
Record the Postgres frontend/backend protocol once and replay real result sets in tests — no container, no pg-mem, no schema to rebuild.
Read the guide - Caches & Stores
Keploy as a Redis testing framework
Record RESP traffic once and replay real cache hits, misses, TTLs, and pipeline responses without a Redis server in CI.
Read the guide - Databases
Keploy as a MongoDB testing framework
Mock MongoDB at the wire protocol — real documents, real BSON types, real aggregation results — without a mongod binary in CI.
Read the guide - Message Queues
Keploy as a Apache Kafka testing framework
Test producers and consumers against recorded broker exchanges — no embedded Kafka, no Testcontainers cluster, no flaky poll loops.
Read the guide - Frameworks
Keploy as a Django testing framework
No test database to create and destroy, no fixtures to load — Keploy records your Django app serving real requests and replays the ORM queries it made.
Read the guide
Join our GlobalCommunity
Connect with developers worldwide. Follow updates, ask questions, share feedback, and ship faster with other Keploy builders.
“Best report of integration and API tests I've seen — which we don't get from RestAssured.”
G2“Future of microservices testing. I don't write tests now!”
G2 · 5/5“An amazing product that simplifies the automation.”
Gartner · 4.0