Skip to main content

hteetp

PyPI - Version PyPI - Python Version

hteetp is a Python package for copying HTTP responses to disk. It provides wrappers around the standard library's http.client infrastructure.

This is useful when making something that should capture traffic, either for later analysis or for a cache.

It's like tee but for HTTP requests.

Installation

pip install hteetp

Usage

The simplest usage is hteetp.http_request:

from hteetp import http_request


def request_and_record():
	response = http_request("./snapshot.http", "GET", "github.com", "/spenczar/hteetp")
	# Now the file ./snapshot.http exists - but it will only have headers and the 
	# 'HTTP/1.1' preamble
	
	response_data = response.read()
	# Now the file will be populated with the contents of response_data
	
	assert len(response.headers) > 0
	assert len(response_data) != 0

Long-lived connections

Alternatively, hteetp.TeeHTTPConnection is a replacement for http.client.HTTPConnection. You provide it with a function for generating filepaths given HTTP request parameters, and it manages the teeing for you. This gives you a long-lived connection if you're hitting the same host many times.

from hteetp import TeeHTTPConnection, relative_files


def request_and_record():
	conn = TeeHTTPConnection(relative_files("./snapshots") "github.com")
	for path in ["/spenczar/hteetp", "/python/cpython", "/psf/requests"]:
		resp = conn.request("GET", path)
		resp_data = resp.read()
		# handle each response
	# The following files will have been written:
	# ./snapshots/GET/github.com:443/spenczar/hteetp
	# ./snapshots/GET/github.com:443/python/cpython	
	# ./snapshots/GET/github.com:443/psf/requests	

Reading HTTP from files on disk

hteetp.http_response_from_file is a little utility for loading a http.client.HTTPResponse from a file on disk:

from hteetp import http_response_from_file

resp = http_response_from_file("./snapshots/GET/github.com:443/spenczar/hteetp")
print(resp.headers)
resp_body = resp.read()
print(resp_body)

Metadata

Release files for hteetp 0.1

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

Source distribution (sdist)

Source distribution for hteetp 0.1
File Size Uploaded Provenance Actions
hteetp-0.1.tar.gz 9.0 MB Without provenance Details for hteetp-0.1.tar.gz

Built distribution (wheel)

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

Total release size: 9.0 MB

Release files / hteetp-0.1.tar.gz

Download URL hteetp-0.1.tar.gz
Size 9.0 MB
Tags Source
SHA-256 checksum
How to use checksums
2c3f30b20d3ffa2cea8d8972301c0aad8dbc1ebaa5dfd7ac85365ee2d357fdc0
BLAKE2b-256 checksum
How to use checksums
73b75da70045dc90b7984f57a435f7bc7e9ce28b8c5fbe8b958420a696d0ded5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.24.0

Release files / hteetp-0.1-py3-none-any.whl

Download URL hteetp-0.1-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0f3d1183f2998cb58ae0cff905aa615492e5dcb4d6bd1c836605d19ec781966b
BLAKE2b-256 checksum
How to use checksums
f725ae6f886c4dbcb8f4a92feb5d7c310ff7f328e9d136127b9f8893bc7d417e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.24.0

Security for hteetp 0.1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A 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.

Release history Release notifications | RSS feed

This release

0.1 This release

2 release files No provenance

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