snowland-http
A rate-limited, parallel HTTP client with pluggable requests / httpx / aiohttp / zero-dependency stdlib (urllib) backends.
Features
- Pluggable transport:
requests(sync only),httpx(sync + async),aiohttp(async only), andstdlib(sync, built on the Python standard libraryurllib— requires no third-party install). Select viabackend=or usebackend="auto"to auto-detect (preference: httpx > aiohttp > requests > stdlib). - Global rate limiting: a token-bucket limiter shared by all parallel workers, so the aggregate request rate never exceeds the configured ceiling. Provides both a blocking
acquire()and an asyncacquire_async(). - Parallel requests: thread pool (
ThreadPoolExecutor) for sync, andasyncio.gather+Semaphorefor async. - Orchestrator: manage multiple HTTP connections with multi-process or coroutine-based parallel/concurrent execution for improved throughput.
- Connection lifecycle: explicit
open()/close()(and async counterparts), with context-manager support that opens on enter and closes on exit.
Installation
The three third-party transports (requests / httpx / aiohttp) are optional dependencies, independent of each other — none is required for the package to import (backends are imported lazily). When none is installed, the client automatically falls back to the built-in stdlib backend (pure urllib), so it works in a bare Python environment with zero installs. Install at least one third-party transport to use the corresponding backend:
# Option A: install a transport library directly
pip install requests # or httpx / aiohttp — install at least one
# Option B: install via extras (recommended)
pip install ".[requests]" # sync backend only
pip install ".[httpx]" # sync + async backend (recommended)
pip install ".[aiohttp]" # async backend only
pip install ".[all]" # everything
# ".[stdlib]" is a no-op extra: it documents the always-available urllib backend.
With backend="auto", the client detects installed libraries in the order httpx > aiohttp > requests, and finally falls back to stdlib (no install needed).
Quick start
Sync + rate limiting + parallel
from snowland_http import HttpClient, RateLimitConfig
client = HttpClient(
backend="requests",
rate_limit=RateLimitConfig(max_rate=5, burst=2), # <=5 req/s, burst of 2
)
resp = client.get("https://example.com")
print(resp.status_code, resp.json())
# parallel GET
results = client.get_many(["https://example.com/1", "https://example.com/2"])
for r in results:
print(r if isinstance(r, Exception) else r.status_code)
Async + rate limiting + parallel
import asyncio
from snowland_http import HttpClient, RateLimitConfig
async def main():
client = HttpClient(
backend="httpx",
rate_limit=RateLimitConfig(max_rate=10, burst=5),
)
async with client: # open_async on enter, close_async on exit
results = await client.get_many_async(["https://example.com/1", "https://example.com/2"])
for r in results:
print(r.status_code)
asyncio.run(main())
Zero-dependency (stdlib / urllib)
No third-party package needed — works with a stock Python:
pip install snowland-http # nothing else required
from snowland_http import HttpClient
# backend="auto" falls back to stdlib when requests/httpx/aiohttp are absent,
# or pick it explicitly:
client = HttpClient(backend="stdlib")
resp = client.get("https://example.com")
print(resp.status_code, resp.text)
API
HttpClient(backend="auto", rate_limit=None, max_workers=10, max_concurrency=10)
The backend argument accepts "requests", "httpx", "aiohttp", "stdlib" (or "urllib"), or "auto". With "auto" the client prefers httpx > aiohttp > requests and finally falls back to the dependency-free stdlib backend.
| Method | Description |
|---|---|
request(method, url, **kwargs) |
Single sync request |
get/post/put/delete/head/patch(url, **kwargs) |
Sync convenience methods |
request_many(items, max_workers, return_exceptions) |
Sync parallel (thread pool) |
get_many(urls, method="GET", ...) |
Sync parallel GET |
request_async(method, url, **kwargs) |
Single async request |
get_async/... |
Async convenience methods |
request_many_async(items, max_concurrency, return_exceptions) |
Async parallel |
get_many_async(urls, ...) |
Async parallel GET |
open() / open_async() |
Open / establish connection resources |
close() / close_async() |
Close connection resources |
- Each element of
itemsmay be adict({"method": ..., "url": ..., ...}) or a(method, url, kwargs_dict)tuple. - Parallel methods default to
return_exceptions=True: a single failure is returned as an exception object in the result list rather than aborting the rest. Set it toFalseto raise immediately.
Rate limiting
RateLimitConfig(max_rate, burst)
max_rate: maximum requests per second.max_rate <= 0disables rate limiting entirely (the limiter becomes a no-op and never blocks); it does not raise.burst: how many requests may be sent back-to-back before smoothing kicks in.
Response encoding
HttpResponse.text is decoded according to the HTTP rules, not a hard-coded UTF-8:
- the
charsetdeclared in theContent-Typeheader wins (e.g.text/html; charset=gbk); - when no
charsetis present, the default is ISO-8859-1 (latin-1) per RFC 7231; - decoding is strict (no silent
errors="replace"): an invalid body raisesUnicodeDecodeErrorso mojibake is never hidden.
You can override the resolution by passing encoding= when constructing a response (used internally by the backends).
Backend constraints
requestssupports sync APIs only (callingrequest_asyncraisesAsyncRequiredError).aiohttpsupports async APIs only (callingrequestraisesAsyncRequiredError).httpxsupports both.stdlib(urllib) supports sync APIs only (callingrequest_asyncraisesAsyncRequiredError).
Orchestrator (Multi-connection parallel/concurrent execution)
The Orchestrator class manages a pool of HttpClient instances and provides high-level APIs for executing requests across multiple connections:
from snowland_http import Orchestrator, RateLimitConfig
# Create orchestrator with 4 connections
orch = Orchestrator(
num_connections=4,
backend="httpx",
rate_limit=RateLimitConfig(max_rate=10, burst=5),
)
# Execute in parallel (multi-process or multi-thread)
urls = ["https://api.example.com/data/1", "https://api.example.com/data/2"]
results = orch.execute_parallel(urls, mode="process") # or mode="thread"
# Execute concurrently (asyncio)
results = await orch.execute_async(urls, mode="coroutine") # or mode="semaphore"
Execution modes:
- Parallel (sync):
mode="process": Multi-process execution usingProcessPoolExecutormode="thread": Multi-threaded execution with load balancing across connections
- Concurrent (async):
mode="coroutine":asyncio.gatherwith load balancingmode="semaphore": Controlled concurrency usingasyncio.Semaphore
Scheduling strategies:
scheduling controls how tasks are assigned to the connections in the pool. It can be
set on the constructor (instance default) and overridden per call.
| Value | Behaviour |
|---|---|
"round_robin" (default) |
Task i always uses connection i % num_connections. Fast and deterministic, but a connection can pile up several slow tasks while others sit idle. |
"idle" |
Each task runs on the next idle connection; a connection serves a single task at a time, so concurrency is capped at num_connections. Best when request durations vary a lot. |
from snowland_http import Orchestrator, SCHEDULING_IDLE
orch = Orchestrator(num_connections=4, backend="httpx", scheduling=SCHEDULING_IDLE)
# or per call
results = orch.execute_parallel(items, mode="thread", scheduling="idle")
Notes:
- In
mode="process"the parameter is ignored (a warning is logged): worker processes pull tasks from a shared call queue, so idle-first dispatch already happens naturally. - With
scheduling="idle", usemax_workers >= num_connectionsin thread mode so every connection can be busy at the same time.
Convenience methods:
# Parallel GET requests
results = orch.get_many_parallel(urls, mode="thread")
# Async concurrent GET requests
results = await orch.get_many_async(urls, mode="coroutine")
Standalone functions:
from snowland_http import execute_parallel_requests, execute_async_requests
# Parallel execution
results = execute_parallel_requests(items, num_connections=4, mode="process")
# Async execution
results = await execute_async_requests(items, num_connections=4, mode="coroutine")
Context manager support:
# Sync context manager
with Orchestrator(num_connections=4) as orch:
results = orch.get_many_parallel(urls)
# Async context manager
async with Orchestrator(num_connections=4) as orch:
results = await orch.get_many_async(urls)
Task (Pre-processing and Post-processing)
The Task class allows you to define HTTP requests with optional pre-processing and post-processing hooks:
from snowland_http import Task
# Define pre-processing function
def add_auth(params):
params["headers"] = {"Authorization": "Bearer token"}
# Define post-processing function
def extract_json(response):
return response.json()
# Create a task
task = Task(
request_params={"method": "GET", "url": "https://api.example.com/data"},
pre_process=add_auth,
post_process=extract_json,
name="fetch_data",
)
# Execute task
result = task.execute(client)
Executing tasks with Orchestrator:
# Create multiple tasks
tasks = [
Task(
request_params={"method": "GET", "url": f"https://api.example.com/data/{i}"},
pre_process=add_auth,
post_process=extract_json,
)
for i in range(10)
]
# Execute tasks in parallel
results = orch.execute_tasks_parallel(tasks, mode="thread")
# Execute tasks concurrently
results = await orch.execute_tasks_async(tasks, mode="coroutine")
Task execution flow:
- Pre-processing (optional): Modify request parameters before sending
- HTTP Request: Execute the HTTP request
- Post-processing (optional): Process the response before returning
This allows you to:
- Add authentication headers dynamically
- Transform request parameters
- Extract and transform response data
- Implement custom error handling
- Add logging or monitoring
Development & CI
- Tests run on
masteranddevbranches (see.github/workflows/test.yml), across Python 3.8–3.12, installing.[all]so functional/parallel tests execute. - Publishing to PyPI happens on GitHub Release (
release: published) via.github/workflows/release.yml, authenticating with thePYPI_API_TOKENrepository secret.
Run the test suite locally:
pip install -e ".[all]"
python -m unittest discover -s tests -v
License
BSD 3-Clause. See LICENSE.
Metadata
Release files for snowland-http 0.3.2
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 |
|---|---|---|---|---|
| snowland_http-0.3.2.tar.gz | 32.6 kB | Without provenance | Details for snowland_http-0.3.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| snowland_http-0.3.2-py3-none-any.whl | Python 3 | none | any | Details for snowland_http-0.3.2-py3-none-any.whl |
Total release size: 59.3 kB
Release files / snowland_http-0.3.2.tar.gz
| Download URL | snowland_http-0.3.2.tar.gz |
|---|---|
| Size | 32.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6aeed167f6250a05d92a0c4eb22839f956e3a8b294d08f1cc7ab70c8ead20fca
|
|
BLAKE2b-256 checksum How to use checksums |
324969e94abacab901b070bf07c1e41b13c8a3817bed351e0338a47456130cbf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / snowland_http-0.3.2-py3-none-any.whl
| Download URL | snowland_http-0.3.2-py3-none-any.whl |
|---|---|
| Size | 26.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2b7be0651a1e73d7dcb64a0846c78609dd5e8e4b65530f325ddc6062a05f44af
|
|
BLAKE2b-256 checksum How to use checksums |
62180d90d1ff79830a89845b8a5ba70d516d7ad3f5fa596ab55d22c3099483d6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Security for snowland-http 0.3.2
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.