Simple Pydantic AIOHTTP Client Sessions
Project description
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
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
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
spacs-0.0.4.tar.gz
(4.8 kB
view details)
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
spacs-0.0.4-py3-none-any.whl
(4.9 kB
view details)
File details
Details for the file spacs-0.0.4.tar.gz.
File metadata
- Download URL: spacs-0.0.4.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.1 CPython/3.11.1 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
35449f329408b6af13663762cd051ebedd328512cb959102e5237e87f97825ce
|
|
| MD5 |
03177ebca7f54952a7a844e74c8899bd
|
|
| BLAKE2b-256 |
e97051434d7b625dacdbf992d3f5da194404d0a0de94cb92a99dc7fffa773558
|
File details
Details for the file spacs-0.0.4-py3-none-any.whl.
File metadata
- Download URL: spacs-0.0.4-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.1 CPython/3.11.1 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
706c2665aadeb6162236b82b50dd9b4a83718c2a973fe182e6dfae862a429590
|
|
| MD5 |
fec255f8fb9df3f0da96b4fef7d0103b
|
|
| BLAKE2b-256 |
451fa302b2b9efd63e1fcba8e27921514fe63ec24787f5de25fcbc2dfeb0bb9e
|