This project allows you to execute a list of http operations asynchronously from within a synchronous context.
Project description
Overview
This project allows you to execute a list of http operations asynchronously from within a synchronous context.
It does not care whether you should do this. It simply allows you to do so if you desire.
Installing
The package is available via pip.
pip install loamy
If you're not on Windows, install the uvloop extra to increase performance.
pip install "loamy[uvloop]"
Usage
The package can be imported as shown:
from loamy.session import Clump, RequestMap, RequestResponse
| Class | Description |
|---|---|
Clump |
Container object that stores collection of requests (type RequestMap) to send |
RequestMap |
Container object that stores all info about an individual request to send |
RequestResponse |
Container object that stores the request response and any exception raised for each individual request |
Example
# Create RequestMap objects
req1 = RequestMap(
url="https://baconipsum.com/api",
http_op="GET",
query_params={"type": "meat-and-filler", "format": "json"},
)
req2 = RequestMap(
url="https://baconipsum.com/api",
http_op="GET",
query_params={"type": "all-meat", "format": "json"},
)
req3 = RequestMap(
url="https://baconipsum.com/api",
http_op="GET",
query_params={"type": "meat-and-filler", "format": "json"},
)
# Create Clump and call send_requests()
session = Clump(requests=[req1, req2, req3])
responses: list[RequestResponse] = session.send_requests(return_exceptions=True)
# Handle responses for individual requests
for resp in responses:
http_verb = resp.request_map.http_op
print(f"Evaluating response for {http_verb} request to {resp.request_map.url}")
if resp.error is not None:
print("Exception raised for request")
else:
print(f"Status Code: {resp.status_code}")
if resp.body is not None:
print(resp.body)
RequestMap Class
class RequestMap(BaseModel):
url: str
http_op: Literal["GET", "POST", "PUT", "PATCH", "OPTIONS", "DELETE"]
body: dict | None = None
query_params: dict[str, str] | None = None
headers: dict[str, str] | None = None
RequestResponse Class
class RequestResponse(BaseModel):
request_map: RequestMap
status_code: int
body: dict | None = None
error: BaseException | None = None
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 loamy-0.0.10.tar.gz.
File metadata
- Download URL: loamy-0.0.10.tar.gz
- Upload date:
- Size: 5.7 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5035a6a45273b943e20b1efe5ca64cff969e855810856cf2c51904cf42bfe7c9
|
|
| MD5 |
404e2485791f02f7c8f74a9259959d46
|
|
| BLAKE2b-256 |
39cc98000b2facac088ef41a1d5b3dc21be625830f3734abed558f27125abb15
|
Provenance
The following attestation bundles were made for loamy-0.0.10.tar.gz:
Publisher:
release.yml on fullerzz/loamy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
loamy-0.0.10.tar.gz -
Subject digest:
5035a6a45273b943e20b1efe5ca64cff969e855810856cf2c51904cf42bfe7c9 - Sigstore transparency entry: 147849614
- Sigstore integration time:
-
Permalink:
fullerzz/loamy@04dd81fe320e2aa2567b01cbb9e3a2a60ea74365 -
Branch / Tag:
refs/tags/v0.0.10 - Owner: https://github.com/fullerzz
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@04dd81fe320e2aa2567b01cbb9e3a2a60ea74365 -
Trigger Event:
push
-
Statement type:
File details
Details for the file loamy-0.0.10-py3-none-any.whl.
File metadata
- Download URL: loamy-0.0.10-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5a7cb0015279da0b7c72518fc190f2d2127ad70f05386764fb35fc3c9898b8b0
|
|
| MD5 |
1733306ae13008665dbdfdf6c9d365ab
|
|
| BLAKE2b-256 |
42a8930edd41af18cec43d1556310c07e6c3d9d8f5896eaf00c402adc10f3791
|
Provenance
The following attestation bundles were made for loamy-0.0.10-py3-none-any.whl:
Publisher:
release.yml on fullerzz/loamy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
loamy-0.0.10-py3-none-any.whl -
Subject digest:
5a7cb0015279da0b7c72518fc190f2d2127ad70f05386764fb35fc3c9898b8b0 - Sigstore transparency entry: 147849616
- Sigstore integration time:
-
Permalink:
fullerzz/loamy@04dd81fe320e2aa2567b01cbb9e3a2a60ea74365 -
Branch / Tag:
refs/tags/v0.0.10 - Owner: https://github.com/fullerzz
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@04dd81fe320e2aa2567b01cbb9e3a2a60ea74365 -
Trigger Event:
push
-
Statement type: