Metadata-Version: 2.1
Name: loamy
Version: 0.0.7
Summary: 
Home-page: https://github.com/fullerzz/loamy
License: MIT
Author: Zach Fuller
Author-email: zach.fuller1222@gmail.com
Requires-Python: >=3.10,<4.0
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Provides-Extra: uvloop
Requires-Dist: aiodns (>=3.1.1,<3.2.0)
Requires-Dist: aiohttp (>=3.9.5)
Requires-Dist: loguru (>=0.7.2,<0.8.0)
Requires-Dist: msgspec (>=0.18.6,<0.19.0)
Requires-Dist: uvloop (==0.19.0) ; extra == "uvloop"
Project-URL: Repository, https://github.com/fullerzz/loamy
Description-Content-Type: text/markdown

![CI Workflow](https://github.com/fullerzz/zConcurrent/actions/workflows/ci.yml/badge.svg)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![Poetry](https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json)](https://python-poetry.org/)
[![PyPI version](https://badge.fury.io/py/loamy.svg)](https://badge.fury.io/py/loamy)
[![MIT License](https://img.shields.io/badge/license-MIT-blue)](https://img.shields.io/badge/license-MIT-blue)

# 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.

```bash
pip install loamy
```

If you're not on Windows, install the uvloop extra to increase performance.

```bash
pip install "loamy[uvloop]"
```

## Usage

The package can be imported as shown:

```python
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

```python
# 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

```python
class RequestMap(msgspec.Struct):
    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

```python
class RequestResponse(msgspec.Struct):
    request_map: RequestMap
    status_code: int
    body: dict | None = None
    error: BaseException | None = None
```

