Time-travel debugging for FastAPI and Flask - record API cassettes, replay with mocked dependencies
Project description
Timetracer
Time-travel debugging for FastAPI and Flask — Record API requests, replay with mocked dependencies.
What is Timetracer?
Timetracer captures real API requests into portable cassettes and replays them with mocked dependencies (HTTP calls, database queries, Redis commands).
Record once. Replay anywhere. Debug faster.
Common use cases:
- Reproduce production bugs locally without access to external services
- Build regression tests from real traffic patterns
- Run demos offline with pre-recorded data
- Detect performance regressions between releases
- Compare behavior between different code versions
Installation
pip install timetracer[all]
Or install only what you need:
pip install timetracer[fastapi,httpx] # FastAPI + HTTP
pip install timetracer[flask,requests] # Flask + HTTP
Quick Start
FastAPI
from fastapi import FastAPI
from timetracer.integrations.fastapi import auto_setup
app = auto_setup(FastAPI())
@app.get("/users/{user_id}")
async def get_user(user_id: int):
async with httpx.AsyncClient() as client:
return (await client.get(f"https://api.example.com/users/{user_id}")).json()
Flask
from flask import Flask
from timetracer.integrations.flask import auto_setup
app = auto_setup(Flask(__name__))
Record and Replay
# Record mode - captures all external calls
TIMETRACER_MODE=record uvicorn app:app
curl http://localhost:8000/users/123
# Replay mode - mocks external calls from cassette
TIMETRACER_MODE=replay \
TIMETRACER_CASSETTE=./cassettes/2026-01-16/GET__users_{user_id}__abc.json \
uvicorn app:app
Manual Setup
For more control over configuration:
import httpx
from fastapi import FastAPI
from timetracer import TraceConfig
from timetracer.integrations.fastapi import TimeTraceMiddleware
from timetracer.plugins import enable_httpx
app = FastAPI()
config = TraceConfig(
mode="record",
cassette_dir="./my-cassettes",
errors_only=True,
)
app.add_middleware(TimeTraceMiddleware, config=config)
enable_httpx()
Configuration
All settings are controlled via environment variables:
| Variable | Description | Default |
|---|---|---|
TIMETRACER_MODE |
off, record, replay |
off |
TIMETRACER_DIR |
Cassette storage directory | ./cassettes |
TIMETRACER_CASSETTE |
Path to cassette file (replay mode) | — |
TIMETRACER_SAMPLE_RATE |
Fraction of requests to record (0-1) | 1.0 |
TIMETRACER_ERRORS_ONLY |
Only record error responses | false |
TIMETRACER_MOCK_PLUGINS |
Plugins to mock during replay | all |
TIMETRACER_LIVE_PLUGINS |
Plugins to keep live during replay | none |
Features
| Category | Supported |
|---|---|
| Frameworks | FastAPI, Flask |
| HTTP Clients | httpx, requests |
| Databases | SQLAlchemy |
| Cache | Redis |
| Storage | Local filesystem, AWS S3 |
| Tools | CLI, diff engine, HTML timeline |
CLI
timetracer list --dir ./cassettes # List all cassettes
timetracer show ./cassettes/GET__users.json # Show cassette details
timetracer diff --a old.json --b new.json # Compare two cassettes
timetracer timeline ./cassettes/GET__users.json --open # Generate timeline
Security
Timetracer automatically protects sensitive data:
- Removes
Authorization,Cookie, andSet-Cookieheaders - Masks sensitive fields like
password,token,api_keyin request/response bodies - Enforces a 64KB body size limit to prevent large data captures
Documentation
Contributing
Contributions are welcome. See CONTRIBUTING.md for guidelines.
License
MIT License. See LICENSE for details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file timetracer-1.0.2.tar.gz.
File metadata
- Download URL: timetracer-1.0.2.tar.gz
- Upload date:
- Size: 63.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f3f8944adc04378bcefd27049f69cc2f0c4a3596abc92293f7904ee1521d43a7
|
|
| MD5 |
04f848a4746935dba5271632dbb5cd91
|
|
| BLAKE2b-256 |
649f8507ed2f66091e8bbffb8c73fbb9829c0a23a70ad7feb82809530eadeb96
|
Provenance
The following attestation bundles were made for timetracer-1.0.2.tar.gz:
Publisher:
ci.yml on usv240/timetracer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
timetracer-1.0.2.tar.gz -
Subject digest:
f3f8944adc04378bcefd27049f69cc2f0c4a3596abc92293f7904ee1521d43a7 - Sigstore transparency entry: 831994199
- Sigstore integration time:
-
Permalink:
usv240/timetracer@3ce14ddfa739048f73e350bbc9098a1be9e27f6a -
Branch / Tag:
refs/tags/v1.0.2 - Owner: https://github.com/usv240
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@3ce14ddfa739048f73e350bbc9098a1be9e27f6a -
Trigger Event:
release
-
Statement type:
File details
Details for the file timetracer-1.0.2-py3-none-any.whl.
File metadata
- Download URL: timetracer-1.0.2-py3-none-any.whl
- Upload date:
- Size: 69.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7a6ea0ca385ff0694b5ff48402da97a1c71b1cb95eb4826e0d88042cc65c2eb8
|
|
| MD5 |
2878ab4c4e266f0f360ce4b6b60b419c
|
|
| BLAKE2b-256 |
98a09f060f2758b6999e7cae954ef9f4777c01ca37e0c1342ced98e0a3356fd8
|
Provenance
The following attestation bundles were made for timetracer-1.0.2-py3-none-any.whl:
Publisher:
ci.yml on usv240/timetracer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
timetracer-1.0.2-py3-none-any.whl -
Subject digest:
7a6ea0ca385ff0694b5ff48402da97a1c71b1cb95eb4826e0d88042cc65c2eb8 - Sigstore transparency entry: 831994219
- Sigstore integration time:
-
Permalink:
usv240/timetracer@3ce14ddfa739048f73e350bbc9098a1be9e27f6a -
Branch / Tag:
refs/tags/v1.0.2 - Owner: https://github.com/usv240
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@3ce14ddfa739048f73e350bbc9098a1be9e27f6a -
Trigger Event:
release
-
Statement type: