A lightweight HTTP client with retry and form/JSON support
Project description
HTTP Client
A lightweight, chainable HTTP client for Python that supports automatic retries, custom retry callbacks, and easy JSON or form submissions.
Features
- Simple and expressive chainable API
- Built-in retry support with customizable retry callbacks
- Automatic JSON and form data handling
- Fully testable with responses
- No heavy dependencies — designed to be minimal and easy to extend
Usage
- Basic GET request
from event_scale_http_client import Http
response = Http().get("http://127.0.0.1:7000/", {
"name": "Alex"
})
print(response.status_code)
print(response.json())
- Automatic retries with callback
You can define how many times the request should retry and handle each failed attempt with a callback:
from event_scale_http_client import Http
def retry_callback(attempt, error):
print(f"Attempt {attempt} failed due to: {error}")
(
Http()
.retry(3, retry_callback)
.get("http://127.0.0.1:7000/")
)
Explanation:
- retry(3, callback) → retries up to 3 times if the request fails.
- The callback function receives two arguments: attempt → current attempt number (starting at 1) error → the exception or status that caused the failure
- POST request with JSON body
from event_scale_http_client import Http
data = {
"name": "Bedram",
"email": "tmgbedu@gmail.com"
}
response = Http().post("http://127.0.0.1:7000", data)
print(response.status_code)
- Sends JSON data by default (Content-Type: application/json).
- POST request as form data
from event_scale_http_client import Http
(
Http()
.asForm()
.post("http://127.0.0.1:7000", {
"name": "Bedram",
"email": "tmgbedu@gmail.com"
})
)
- Sends data as application/x-www-form-urlencoded.
- Automatically encodes form fields.
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 event_scale_http_client-0.1.1.tar.gz.
File metadata
- Download URL: event_scale_http_client-0.1.1.tar.gz
- Upload date:
- Size: 2.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.12.8 Darwin/23.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
68433f830f5abf8f36f3a9bfb66e6a55b57787dd52d8bbeb0efc45e6b8303e5b
|
|
| MD5 |
edaf0ee407f4520fed0706d18a962030
|
|
| BLAKE2b-256 |
7536ce582a0b9e4e20624161b2a0360c8f070ffc6b256fff978a41ba659e7df5
|
File details
Details for the file event_scale_http_client-0.1.1-py3-none-any.whl.
File metadata
- Download URL: event_scale_http_client-0.1.1-py3-none-any.whl
- Upload date:
- Size: 3.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.12.8 Darwin/23.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
514c1d6b933f1417ac59f1a4a572d2f9724ab40c46ad6d22932aba5fd2c921b0
|
|
| MD5 |
5794ecb590dda85be90a7d75c217c3de
|
|
| BLAKE2b-256 |
a12377c7a24138a8e49f5d23e4a2253643f6d098dbda1eb691323d6e65737807
|