Metadata-Version: 2.1
Name: spacs
Version: 0.0.3
Summary: Simple Pydantic AIOHTTP Client Sessions
Home-page: https://github.com/rlebel12/spacs
Author: rlebel12
Requires-Python: >=3.11,<4.0
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Requires-Dist: aiohttp (>=3.8.4,<4.0.0)
Requires-Dist: pydantic (>=1.10.7,<2.0.0)
Project-URL: Repository, https://github.com/rlebel12/spacs
Description-Content-Type: text/markdown

# SPACS: Simple Pydantic AIOHTTP Client Sessions

A package to assist in managing and using long-lived AIOHTTP client sessions with simplicity. Built to handle Pydantic objects.

## Features

* Handles request params and bodies as either Pydantic objects or native Python dictionaries, converting items to JSON-safe format.
* Abstracts away internals of managing the request/response objects, instead either returning parsed response content on success, or raising a specialized error object.
* Automatically manages persistent connections to be shared over extended lifespan across application, cleaning up all open connections on teardown.
* Utilizes modern Python type hinting.

## Usage

```python
import spacs
from pydantic import BaseModel

...

example_client = spacs.SpacsClient(base_url="http://example.com")

# Basic request with error handling
try:
    apple_response = await example_client.get("fruit/apple", params={"cultivar": "honeycrisp"})
except spacs.SpacsRequestError as error:
    print({"code": error.status_code, "reason": error.reason})

# Sending Pydantic objects via HTTP POST
class MyModel(BaseModel):
    name: str
    age: int

example_object = MyModel(name="James", age=25)
person_response = await example_client.post("person", body=example_object)

# Manually closing a session
await example_client.close()
# Alternatively, to close all open sessions:
await spacs.SpacsClient.close_all()
```

## Building

```
poetry build
```

