http_toolkit
The httptoolkit library is a tool for working with HTTP requests in Python that allows you to easily create, customize, and send requests to various services. It provides a simple interface for working with HTTP clients. The library also allows flexible transport customization and abstraction from a particular implementation of HTTP clients.
HTTPXService
If you don't need to use a configured transport, use HTTPXService (for async -> AsyncHttpxService)
from httptoolkit import HttpxService
from httptoolkit import Header
headers = (
Header(name="My-Header", value="my-value", is_sensitive=False),
)
httpbin = HttpxService("http://httpbin.org", headers=headers)
httpbin.get("/get")
httpbin.post("/post")
Service
If you want to use a configured transport, use Service. (Service -> HttpxTransport, AsyncService -> AsyncHttpxTransport)
### Sync
from httptoolkit import Service, Header
from httptoolkit.transport import HttpxTransport
class DummyService(Service):
pass
DummyService(
headers=(Header(name="ServiceHeader", value="service-header", is_sensitive=False),),
transport=HttpxTransport(base_url="https://example.com:4321", proxies={"http://": "http://10.10.1.10:3128"}),
## base_url in this case is passed to transport
)
### Async
from httptoolkit import AsyncService, Header
from httptoolkit.transport import AsyncHttpxTransport
class DummyService(AsyncService):
pass
DummyService(
headers=(Header(name="ServiceHeader", value="service-header", is_sensitive=False),),
transport=AsyncHttpxTransport(base_url="https://example.com:4321", proxies={"http://": "http://10.10.1.10:3128"}),
## base_url in this case is passed to transport
)
Sending a request
from httptoolkit import Service, Header, HttpMethod
from httptoolkit.transport import HttpxTransport
from httptoolkit.request import Request
class DummyService(Service):
pass
service = DummyService(
headers=(Header(name="ServiceHeader", value="service-header", is_sensitive=False),),
transport=HttpxTransport(base_url="https://example.com:4321", proxies={"http://": "http://10.10.1.10:3128"}),
## base_url in this case is passed to transport
)
# By method
service.post(
path="/somewhere",
headers=(Header(name="SuperSecret", value="big_secret", is_sensitive=True, create_mask=lambda value: value[-4:]),),
params={"over": "the rainbow"},
body="Something",
)
# By request
service.request(Request(method=HttpMethod.POST, body="Request", params={}, path=""))
Sending JSON and multipart-files
from httptoolkit import Service, Header
from httptoolkit.transport import HttpxTransport
class DummyService(Service):
pass
service = DummyService(
headers=(Header(name="ServiceHeader", value="service-header", is_sensitive=False),),
transport=HttpxTransport(base_url="https://example.com:4321", proxies={"http://": "http://10.10.1.10:3128"}),
## base_url in this case is passed to transport
)
# Send JSON (json_encoder is the default, but can be changed in transport)
# Do not send with body and files
service.post(
path="/somewhere",
headers=(Header(name="SuperSecret", value="big_secret", is_sensitive=True, create_mask=lambda value: value[-4:]),),
params={"over": "the rainbow"},
json={
"param1": 1,
"param2": 2,
},
)
# Send multipart-files in the format Dict[str, Union[BinaryIO, Tuple[str, BinaryIO, str]]]
# Can be sent with body, but cannot be sent with json
service.post(
path="/somewhere",
headers=(Header(name="SuperSecret", value="big_secret", is_sensitive=True, create_mask=lambda value: value[-4:]),),
params={"over": "the rainbow"},
files={"upload-file": open("report.xls", "rb")},
# different format files = {'upload-file': ('report.xls', open('report.xls', 'rb'), 'application/vnd.ms-excel')}
)
The name of the library logger
httptoolkit
Default logging level
logging.INFO
Example of logging settings
import logging
import httptoolkit
logging.basicConfig(level="INFO")
class MyService(httptoolkit.HttpxService):
def test(self):
self.get("/")
service = MyService("https://test.ru")
service.test()
Output
INFO:httptoolkit.transport._sync:Sending GET https://test.ru/
All about Transport
OpenTelemetry
Allows using OpenTelemetry HTTPX to add request tracing via http_toolkit in case HttpxTransport is used.
Metadata
Release files for http-toolkit 1.0.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 |
|---|---|---|---|---|
| http_toolkit-1.0.2.tar.gz | 14.0 kB | Without provenance | Details for http_toolkit-1.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| http_toolkit-1.0.2-py3-none-any.whl | Python 3 | none | any | Details for http_toolkit-1.0.2-py3-none-any.whl |
Total release size: 36.6 kB
Release files / http_toolkit-1.0.2.tar.gz
| Download URL | http_toolkit-1.0.2.tar.gz |
|---|---|
| Size | 14.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
df89e7858c2078137f4af8b001f1d31dce014a919931e6975bd53678d3ddae6c
|
|
BLAKE2b-256 checksum How to use checksums |
ca0c15f751058e1925f4a9800627cb4a5313c73713d72c2743ea91e35499f02b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Release files / http_toolkit-1.0.2-py3-none-any.whl
| Download URL | http_toolkit-1.0.2-py3-none-any.whl |
|---|---|
| Size | 22.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
157ec96d9916ff8e5b00294b94fd4a6e91ba3951b5b1e093ddae7dcae9b494e6
|
|
BLAKE2b-256 checksum How to use checksums |
1e680c2f1a79460920a84a1c8b855495aad365075ee88d2db37d7d03f1ea3581
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Security for http-toolkit 1.0.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.