Skip to main content

Timetracer

Time-travel debugging for FastAPI, Starlette, Flask, and Django — 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[starlette,httpx]  # Starlette + httpx
pip install timetracer[flask,requests]   # Flask + requests
pip install timetracer[django,requests]  # Django + requests
pip install timetracer[motor]            # Motor (MongoDB async) + PyMongo (sync)

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()

Starlette

from starlette.applications import Starlette
from timetracer.integrations.starlette import auto_setup

app = auto_setup(Starlette(debug=True))

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_COMPRESSION Cassette compression: none, gzip none
TIMETRACER_MOCK_PLUGINS Plugins to mock during replay all
TIMETRACER_LIVE_PLUGINS Plugins to keep live during replay none

Features

Category Supported
Frameworks FastAPI, Starlette, Flask, Django
HTTP Clients httpx, requests, aiohttp
Databases SQLAlchemy, Motor (MongoDB async), PyMongo (MongoDB sync)
Cache Redis
Storage Local filesystem, AWS S3
Testing pytest plugin with fixtures
Tools CLI, diff engine, HTML timeline, Dashboard
Compression Gzip (60-95% size reduction)

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.

Metadata

Release files for timetracer 1.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for timetracer 1.6.0
File Size Uploaded
timetracer-1.6.0.tar.gz 109.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for timetracer 1.6.0
File Interpreter ABI Platform
timetracer-1.6.0-py3-none-any.whl Python 3 none any Details

Total release size: 214.1 kB

Release files / timetracer-1.6.0.tar.gz

Download URL timetracer-1.6.0.tar.gz
Size 109.6 kB
Tags Source
SHA-256 checksum
How to use checksums
1d4fb1f597c2ac31bc8ba8bb25e05368e8a86979d7ca50e89cf4d591598d54ff
BLAKE2b-256 checksum
How to use checksums
5809cd71be668e4604a1e58f44ca5488145a46c24ee8e9d2cafae7df152c846a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 24, 2026.

Transparency log

Release files / timetracer-1.6.0-py3-none-any.whl

Download URL timetracer-1.6.0-py3-none-any.whl
Size 104.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
930be5ecef47879d3ef8e902decd3717c32494f28e1111ad0879ff7e300c70eb
BLAKE2b-256 checksum
How to use checksums
e53b3f8d7ed7ee9e178b73d48b558fe1e91efc531fd2ca0a772ad4d2f1deb396
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 24, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.6.0 This release

2 release files

1.5.0

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.2

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page