Skip to main content

No project description provided

Project description

CI Workflow Ruff Poetry

Overview

This project allows you to execute a list of http operations asynchronously from within an 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, RequestResults
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
RequestResults Container object that stores the request responses and any exceptions raised

Example

# Create RequestMap objects
req1 = RequestMap(
    url="https://baconipsum.com/api",
    httpOperation="GET",
    queryParams={"type": "meat-and-filler", "format": "json"},
)
req2 = RequestMap(
    url="https://baconipsum.com/api",
    httpOperation="GET",
    queryParams={"type": "all-meat", "format": "json"},
)
req3 = RequestMap(
    url="https://baconipsum.com/api",
    httpOperation="GET",
    queryParams={"type": "meat-and-filler", "format": "json"},
)

# Create Clump and call sendRequests()
session = Clump(requests=[req1, req2, req3])
reqResps: RequestResults = session.sendRequests(return_exceptions=True)

# Handle exceptions raised for individual requests
if len(reqResps.taskExceptions) > 0:
    print("Handling exceptions")

# Handle responses for individual requests
for resp in requestResponses:
    httpVerb = resp.requestMap.httpOperation
    print(f"Evaluating response for {httpVerb} request to {resp.requestMap.url}")
    print(f"Status Code: {resp.statusCode}")
    if resp.body is not None:
        print(resp.body)

RequestMap Class

class RequestMap(msgspec.Struct):
    url: str
    httpOperation: Literal["GET", "POST", "PUT", "PATCH", "OPTIONS", "DELETE"]
    body: dict | None = None
    queryParams: dict[str, str] | None = None
    headers: dict[str, str] | None = None

RequestResponse Class

class RequestResponse(msgspec.Struct):
    requestMap: RequestMap
    statusCode: int
    body: dict | None = None

RequestResults Class

@dataclass
class RequestResults:
    requestResponses: list[RequestResponse]
    taskExceptions: list[BaseException]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

loamy-0.0.2a0.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

loamy-0.0.2a0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file loamy-0.0.2a0.tar.gz.

File metadata

  • Download URL: loamy-0.0.2a0.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for loamy-0.0.2a0.tar.gz
Algorithm Hash digest
SHA256 cb34f5b417343ea82f1aec0c4299c543191d9d6812c42403995e826df93043e6
MD5 0d9aaa91a982733da8d3b7cf99394f1b
BLAKE2b-256 2b4ecbd2acb38cd69f5c44b66695aaf918612dd87a00ae14cfb5ec63a74689f4

See more details on using hashes here.

File details

Details for the file loamy-0.0.2a0-py3-none-any.whl.

File metadata

  • Download URL: loamy-0.0.2a0-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for loamy-0.0.2a0-py3-none-any.whl
Algorithm Hash digest
SHA256 d13ba3f987b1b088aa5b77eb13b189b320705d04a375927fcb5969710e920832
MD5 52118517e35009b2699d61ee19eba89e
BLAKE2b-256 a6729eb8480ee0421ad16b40ec6944e9fbf32d8ef7ed04aba2a864d51cc8bc5e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page