Skip to main content

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.

CI Python 3.10+ License: MIT PyPI


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

How It Works

Timetracer acts as middleware that intercepts your app's external calls:

                      RECORD MODE
┌──────────┐      ┌──────────────┐      ┌──────────────┐
│  Client  │ ───► │   Your App   │ ───► │   External   │
│  (curl)  │      │ + Timetracer │      │   APIs/DB    │
└──────────┘      └──────────────┘      └──────────────┘
                         │
                         ▼
                   ┌───────────┐
                   │  Cassette │  (saves everything)
                   │   .json   │
                   └───────────┘


                      REPLAY MODE
┌──────────┐      ┌──────────────┐       ╳ External APIs
│  Client  │ ───► │   Your App   │       ╳ (not called)
│  (curl)  │      │ + Timetracer │
└──────────┘      └──────────────┘
                         ▲
                         │
                   ┌───────────┐
                   │  Cassette │  (replays from here)
                   │   .json   │
                   └───────────┘

Installation

pip install timetracer[all]

Or install only what you need:

pip install timetracer[fastapi,httpx]    # FastAPI + httpx
pip install timetracer[fastapi,aiohttp]  # FastAPI + aiohttp
pip install timetracer[flask,requests]   # Flask + requests

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 TimeTracerMiddleware
from timetracer.plugins import enable_httpx

app = FastAPI()

config = TraceConfig(
    mode="record",
    cassette_dir="./my-cassettes",
    errors_only=True,
)
app.add_middleware(TimeTracerMiddleware, 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, aiohttp
Databases SQLAlchemy
Cache Redis
Storage Local filesystem, AWS S3
Tools CLI, diff engine, HTML timeline, Dashboard

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
timetracer dashboard --dir ./cassettes --open  # Generate interactive dashboard
timetracer serve --dir ./cassettes --open      # Start live dashboard with replay

Dashboard

Browse and debug all recorded cassettes with the interactive dashboard:

# Static HTML dashboard (open in browser)
timetracer dashboard --dir ./cassettes --open

# Live dashboard with real-time replay
timetracer serve --dir ./cassettes --open

Features:

  • Sortable table - Sort by time, method, status, duration
  • Filters - Filter by method, status, duration, time range
  • Error highlighting - Errors shown in red with warning icons
  • Stack traces - View exception details and Python tracebacks
  • Replay - One-click replay to see recorded request/response
  • Raw JSON - Expandable view of full cassette data

Security

Timetracer automatically protects sensitive data:

  • Removes Authorization, Cookie, and Set-Cookie headers
  • Masks sensitive fields like password, token, api_key in 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

timetracer-1.3.0.tar.gz (86.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

timetracer-1.3.0-py3-none-any.whl (89.0 kB view details)

Uploaded Python 3

File details

Details for the file timetracer-1.3.0.tar.gz.

File metadata

  • Download URL: timetracer-1.3.0.tar.gz
  • Upload date:
  • Size: 86.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for timetracer-1.3.0.tar.gz
Algorithm Hash digest
SHA256 67e5b20cf8c09e2e704a01c837af3de494e3cbee4083e6f4b6261f749cf0171f
MD5 5b0b62f53f7c48a0bf2ac2e97260edd9
BLAKE2b-256 076c1a9f4915d71c7c66b8ed9ec3aa28abd1faa71b0990af59ca45aaf3d6f04b

See more details on using hashes here.

Provenance

The following attestation bundles were made for timetracer-1.3.0.tar.gz:

Publisher: ci.yml on usv240/timetracer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file timetracer-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: timetracer-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 89.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for timetracer-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bf1f0a937c8d5d2e0cc020185f3def2f422699dfc0f0648db099505a694d53b7
MD5 c76060dd212baae9248ca1fa083f3faa
BLAKE2b-256 b4e3c433b3084f7bc11c76a3577a113fc579195de1f07c0dc23ef1879635851f

See more details on using hashes here.

Provenance

The following attestation bundles were made for timetracer-1.3.0-py3-none-any.whl:

Publisher: ci.yml on usv240/timetracer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page