Django Rapyd Wiretap
A Django middleware that logs HTTP requests and responses to your database for auditing or troubleshooting purposes. Unlike similar packages, it works in production — logging is not gated on settings.DEBUG.
Inspired by nathforge/django-wiretap.
Install
pip install django-rapyd-wiretap
Quickstart
-
Add
wiretaptoINSTALLED_APPS:INSTALLED_APPS = [ ... "wiretap", ]
-
Add the middleware to
MIDDLEWARE:MIDDLEWARE = [ ... "wiretap.middleware.WiretapMiddleware", ]
-
Apply migrations:
python manage.py migrate
Usage
In the Django admin, create a Tap to configure which requests to capture:
- Path — a Python regex matched against the full request path with
re.search. - Is active — deactivate a tap without deleting it.
Each matched request is stored as a Message with the request method, path, headers, body, response status, and timing information. Messages are read-only in the admin.
Tap recipes
| Goal | Path regex |
|---|---|
Capture all /api/ traffic |
^/api/ |
| Capture a specific endpoint exactly | ^/api/v1/payments/$ |
| Capture a versioned endpoint (any version) | ^/api/v\d+/payments/ |
| Capture everything | / |
Capture everything except /admin/ and /static/ |
^/(?!admin/|static/) |
| Capture POSTs to webhooks (combine with another middleware filtering by method) | ^/webhooks/ |
The path regex is matched with re.search, not re.fullmatch — anchor with ^ if you want a prefix match, and add $ if you want an exact match. Query strings are not part of the path; they're available on Message.request_path only if Django's path router includes them (it normally doesn't).
Reading captured messages
Each Message row has the following fields:
| Field | Description |
|---|---|
started_at / ended_at |
When request logging began and response logging finished (UTC, indexed). |
duration |
Whole seconds between started_at and ended_at (indexed). For sub-second precision, compute from the timestamps directly. |
remote_addr |
Client IP from REMOTE_ADDR (indexed). If you sit behind a proxy, install django.middleware.common.CommonMiddleware-style IP unwrapping before WiretapMiddleware. |
request_method |
GET, POST, etc. (indexed). |
request_path |
Full request path (no query string). |
request_headers_json / response_headers_json |
JSON-encoded header dicts. Use the request_headers / response_headers properties to get a dict. |
request_body_raw / response_body_raw |
UTF-8-decoded body. Set to empty string for empty bodies; non-UTF-8 bodies are skipped (the row is still saved). |
request_body_pretty / response_body_pretty |
JSON-pretty-printed body, populated only when the corresponding Content-Type contains json and the body parses. NULL otherwise. |
response_status_code / response_reason_phrase |
HTTP status (indexed). |
Helper methods on Message:
message.get_request_header("Content-Type") # raises KeyError if missing
message.get_request_header("X-Custom", default=None) # returns default if missing
message.get_response_header("Location", "")
Header lookups are case-insensitive (titled-cased internally).
Operations
Pruning old messages
Message rows accumulate forever once a Tap is active. A 100 RPS endpoint matched by ^/api/ produces ~8.6M rows/day — plan storage accordingly and prune on a schedule.
# delete messages older than 30 days
python manage.py wiretap_prune --older-than-days 30
# preview without deleting
python manage.py wiretap_prune --older-than-days 30 --dry-run
Run as a daily cron / scheduled job. The command issues a single bulk DELETE filtered on started_at.
Middleware ordering
Place WiretapMiddleware near the top of MIDDLEWARE, after security/common middleware but before any middleware that mutates request bodies or response content. The earlier it sits, the closer the captured payload is to the on-the-wire form.
If you sit behind a load balancer or reverse proxy, install IP-unwrapping middleware (e.g., django.middleware.common.CommonMiddleware plus USE_X_FORWARDED_HOST, or a dedicated package) before WiretapMiddleware, so remote_addr reflects the real client IP rather than the proxy's.
Indexed fields and ad-hoc queries
started_at, ended_at, duration, remote_addr, request_method, response_status_code, and response_reason_phrase are indexed. Filtering/ordering by those scales. Filtering by request_path (a TextField) on a large table will table-scan; if you do this often, add a custom index in your project's migrations.
Sensitive data
Wiretap captures everything in matched requests, including Authorization and Cookie headers, request/response bodies, and any tokens or PII passing through. Tap conservatively, and keep the Message table on storage with the same threat model as your secrets store.
Built-in opt-in redaction is on the roadmap — see issue #10.
Supported versions
| Package | Versions |
|---|---|
| Python | 3.10, 3.11, 3.12, 3.13 |
| Django | 4.2 LTS, 5.2 LTS |
Contributing
See CONTRIBUTING.md for development setup, test commands, and the release process.
License
Apache 2.0. See LICENSE.
Metadata
Release files for django-rapyd-wiretap 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django_rapyd_wiretap-0.2.0.tar.gz | 87.3 kB | With provenance | Details for django_rapyd_wiretap-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_rapyd_wiretap-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for django_rapyd_wiretap-0.2.0-py3-none-any.whl |
Total release size: 105.5 kB
Release files / django_rapyd_wiretap-0.2.0.tar.gz
| Download URL | django_rapyd_wiretap-0.2.0.tar.gz |
|---|---|
| Size | 87.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
42a2a79c0e2cbae6bbfb6a4e155402295e7f64722ff6b8cde15fbb6ef35eae80
|
|
BLAKE2b-256 checksum How to use checksums |
a49c5d109e94d4eae0640edf8e550f08f3b5f12030615ec6adc2b5c6f84ce173
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 May 9, 2026.
Transparency logRelease files / django_rapyd_wiretap-0.2.0-py3-none-any.whl
| Download URL | django_rapyd_wiretap-0.2.0-py3-none-any.whl |
|---|---|
| Size | 18.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1ca0d046416bbdbb47674797dbaa1d07665a88044a75a0f3b6b80ff2c7f2b036
|
|
BLAKE2b-256 checksum How to use checksums |
721a65d9350cb105fb99fec6c75f0bc08a2148906046bcac9fd6479b9d3ab802
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 May 9, 2026.
Transparency logSecurity for django-rapyd-wiretap 0.2.0
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for django_rapyd_wiretap-0.2.0.tar.gz
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 May 9, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.