A minimal, zero-dependency library for timing HTTP requests
Project description
http-timer
A minimal, zero-dependency Python library for timing HTTP requests.
Why?
Measuring HTTP request timing in Python is more complicated than it should be:
| Library | Issue |
|---|---|
| requests | No native timing metrics |
| httpx | Requires verbose event hooks |
| aiohttp | Async-only, requires boilerplate |
| curl | External tool, not Pythonic |
http-timer is designed to be:
- Zero dependencies (uses only stdlib)
- Minimal API
- Human-readable output
- Perfect for debugging and profiling
Installation
pip install http-timer
Usage
from http_timer import timed_get
body, timing = timed_get("https://api.example.com/users")
print(f"Status: {timing.status}")
print(f"Time: {timing.total_ms:.2f}ms")
print(f"Size: {timing.size_bytes} bytes")
POST with JSON
from http_timer import timed_post
body, timing = timed_post(
"https://api.example.com/users",
json={"name": "Ana", "email": "ana@example.com"}
)
print(f"Created in {timing.total_ms:.2f}ms")
Custom headers
body, timing = timed_get(
"https://api.example.com/users",
headers={"Authorization": "Bearer token123"}
)
Available functions
| Function | Description |
|---|---|
timed_get(url, headers=None, timeout=30) |
GET request |
timed_post(url, headers=None, json=None, data=None, timeout=30) |
POST request |
timed_put(url, headers=None, json=None, data=None, timeout=30) |
PUT request |
timed_delete(url, headers=None, timeout=30) |
DELETE request |
TimingResult
All functions return a tuple (body, timing) where timing is a TimingResult:
| Attribute | Type | Description |
|---|---|---|
total_ms |
float | Total request time in milliseconds |
dns_ms |
float | DNS resolution time |
connect_ms |
float | TCP connection time |
tls_ms |
float | TLS handshake time (HTTPS only) |
transfer_ms |
float | Response transfer time |
status |
int | HTTP status code |
size_bytes |
int | Response body size |
headers |
dict | Response headers |
Detailed timing example
from http_timer import timed_get
body, timing = timed_get("https://api.example.com")
print(f"DNS: {timing.dns_ms:.1f}ms")
print(f"Connect: {timing.connect_ms:.1f}ms")
print(f"TLS: {timing.tls_ms:.1f}ms")
print(f"Transfer: {timing.transfer_ms:.1f}ms")
print(f"Total: {timing.total_ms:.1f}ms")
# Or use the string representation
print(timing)
# Output: total=245.3ms | dns=12.1ms | connect=45.2ms | tls=89.4ms | transfer=98.6ms | status=200 | size=1234B
Comparison with alternatives
# With requests (no timing)
import requests
import time
start = time.time()
r = requests.get("https://api.example.com")
elapsed = (time.time() - start) * 1000
print(f"{elapsed:.2f}ms")
# With http-timer (simple!)
from http_timer import timed_get
body, timing = timed_get("https://api.example.com")
print(f"{timing.total_ms:.2f}ms")
CLI
# Basic usage
http-timer https://api.example.com
# POST with JSON
http-timer -X POST -j '{"name": "test"}' https://api.example.com
# With custom headers
http-timer -H "Authorization: Bearer token" https://api.example.com
# Quiet mode (one-liner output)
http-timer -q https://api.example.com
# Output: total=245.3ms | dns=12.1ms | connect=45.2ms | tls=89.4ms | transfer=98.6ms | status=200 | size=1234B
# Show response headers
http-timer --verbose https://api.example.com
CLI options
| Option | Description |
|---|---|
-X, --method |
HTTP method (GET, POST, PUT, DELETE) |
-d, --data |
Request body data |
-j, --json |
JSON request body |
-H, --header |
Request header (repeatable) |
-t, --timeout |
Timeout in seconds (default: 30) |
-q, --quiet |
One-liner output |
--verbose |
Show response headers |
--no-color |
Disable colors |
-v, --version |
Show version |
Limitations
Current version (v0.3.0) does not support:
- Async requests
- Session/connection pooling
These features are planned for future releases.
Development
# Clone the repository
git clone https://github.com/nilerbarcelos/http-timer.git
cd http-timer
# Install dev dependencies
pip install hatch
# Run tests
hatch run test:run
Roadmap
v0.1.0 — MVP
- timed_get / timed_post / timed_put / timed_delete
- Total time measurement
- Response size and headers
v0.2.0 — Detailed timing
- DNS resolution time
- TCP connection time
- TLS handshake time
- Transfer time
v0.3.0 — CLI (current)
- Command-line interface
- Colored output
- Quiet mode for scripting
v0.4.0 — Async support
- httpx/aiohttp integration
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file http_timer-0.3.0.tar.gz.
File metadata
- Download URL: http_timer-0.3.0.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aca3d276e006a31bcc0e930d0020807f4cdcb72c47bca04a6559dfda39d20519
|
|
| MD5 |
61b3ef51d518863f303a2a63799a8d3a
|
|
| BLAKE2b-256 |
98fe43c22121b29f36f18edcd6ddb3bac3fc2902b96dc6b12c783475fe4ee15b
|
Provenance
The following attestation bundles were made for http_timer-0.3.0.tar.gz:
Publisher:
python-publish.yml on nilerbarcelos/http-timer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
http_timer-0.3.0.tar.gz -
Subject digest:
aca3d276e006a31bcc0e930d0020807f4cdcb72c47bca04a6559dfda39d20519 - Sigstore transparency entry: 729426527
- Sigstore integration time:
-
Permalink:
nilerbarcelos/http-timer@927d0dc39b2b355bb93711bf3eef2fed0b712956 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/nilerbarcelos
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@927d0dc39b2b355bb93711bf3eef2fed0b712956 -
Trigger Event:
release
-
Statement type:
File details
Details for the file http_timer-0.3.0-py3-none-any.whl.
File metadata
- Download URL: http_timer-0.3.0-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
50c8347ad841465f13210f95c983061f7193e9d925872c9fc803b7865f1b7df7
|
|
| MD5 |
15108f89c443d94cdc08a30129fbc063
|
|
| BLAKE2b-256 |
c72b6aa9bcb7ca59f1ccf610d07b7eae7af1a0d31d6f500824e158d652eac549
|
Provenance
The following attestation bundles were made for http_timer-0.3.0-py3-none-any.whl:
Publisher:
python-publish.yml on nilerbarcelos/http-timer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
http_timer-0.3.0-py3-none-any.whl -
Subject digest:
50c8347ad841465f13210f95c983061f7193e9d925872c9fc803b7865f1b7df7 - Sigstore transparency entry: 729426541
- Sigstore integration time:
-
Permalink:
nilerbarcelos/http-timer@927d0dc39b2b355bb93711bf3eef2fed0b712956 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/nilerbarcelos
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@927d0dc39b2b355bb93711bf3eef2fed0b712956 -
Trigger Event:
release
-
Statement type: