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, 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",
    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])
responses: list[RequestResponse] = session.sendRequests(return_exceptions=True)


# Handle responses for individual requests
for resp in responses:
    httpVerb = resp.requestMap.httpOperation
    print(f"Evaluating response for {httpVerb} request to {resp.requestMap.url}")
    if resp.error is not None:
        print("Exception raised for request")
    else:
        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

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for loamy-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7840819c3a7be85df29914bd12cd2dec8ff0f5988e6fa5789b0ef0a7e83aeb46
MD5 f6d79d5d90dde4a723edce67313889ca
BLAKE2b-256 6e9bcad718be1b6706b426ee8a0630f240a868dba240f70fe79e2cf3bc260068

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