harfile
Writer for HTTP Archive (HAR) files
What it is and what it does
harfile is a minimal, zero-dependency library for programmatically writing HTTP Archive (HAR) files in Python. It provides a context manager interface to build HAR files by adding individual HTTP request/response entries with timing data, suitable for recording network activity in test scenarios or debugging workflows.
The package is designed for single-threaded use and does not support HAR's page grouping feature. It accepts entries via a simple API that takes request, response, timing, and metadata objects, then serializes them to standard HAR format. With no external dependencies and support for modern Python versions (3.8 through 3.14), it integrates easily into testing and monitoring pipelines.
Use it for:
- Record HTTP interactions during integration tests and save them as HAR files for analysis or replay
- Generate HAR archives from captured network traffic in debugging or performance profiling workflows
- Export request/response logs from a test suite in a standardized format for sharing with other tools
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Writes HTTP Archive (HAR) files in Python with zero external dependencies, supporting single-threaded entry recording without page grouping.
Yes, for test and debugging workflows that need HAR output. The zero-dependency design, permissive license, and active maintenance make it a low-risk choice. The single-threaded constraint and lack of page support are acceptable trade-offs for most recording use cases; verify that your HAR field requirements match the library's scope before adopting.
Install
harfile on PyPI
pip
pip install harfileuv
uv add harfilepoetry
poetry add harfileInstalling harfile
Before you install
Low friction: pure Python wheel with no runtime dependencies. Active maintenance with a recent release (77 days ago) and current repository activity.
License in practice
MIT permissive license allows commercial and private use with minimal restrictions; attribution required.
Quickstart
import datetime
import harfile
with harfile.open("output.har") as har:
har.add_entry(
startedDateTime=datetime.datetime.now(datetime.timezone.utc),
time=42,
request=harfile.Request(method="GET", url="http://example.com", httpVersion="HTTP/1.1"),
response=harfile.Response(status=200, statusText="OK", httpVersion="HTTP/1.1"),
timings=harfile.Timings(send=0, wait=0, receive=0),
)
Single-threaded environment only; pages are not supported.
Verify before relying
- Whether the package handles all HAR specification fields or only a subset
- Performance characteristics with large numbers of entries
- Validation of HAR output against the official HAR specification
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 77 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 2,744,639/month — #2,909 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: harfile-0.5.0-py3-none-any.whl
Keywords: har, http, testing
Tags
More Testing packages
Pluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
virtualenvvirtualenv creates isolated Python environments…
permissive · top 100 on PyPI
coverageCoverage.py measures which lines of Python code…
permissive · top 1,000 on PyPI
pytest-asynciopytest-asyncio is a pytest plugin that enables…
permissive · top 1,000 on PyPI
pytest-json-ctrfA pytest plugin that generates test reports in…
permissive · top 1,000 on PyPI
warcioReads and writes WARC (Web ARChive) and legacy…
permissive · top 5,000 on PyPI
pylightxlReads and writes Microsoft Excel files (.xlsx,…
permissive · top 15,000 on PyPI
unix-arReads and writes AR archive files (Unix static…
permissive · top 5,000 on PyPI
libarchive-clibarchive-c provides a Python interface to…
permissive · top 15,000 on PyPI
arParses and reads ar archive files (.a),…
permissive · top 15,000 on PyPI
aiofileProvides asynchronous file I/O operations for…
permissive · top 1,000 on PyPI
kaldiioKaldiio reads and writes Kaldi archive (ark)…
unclear · top 5,000 on PyPI
pyorcPyORC reads and writes Apache ORC files using…
permissive · top 15,000 on PyPI
pmtilesRead and write PMTiles archives, a single-file…
permissive · top 15,000 on PyPI
savepagenowWrapper and CLI tool to submit URLs to…
permissive · top 15,000 on PyPI