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.
Installation
Using poetry (preferred):
poetry add spacs
Using pip:
pip install spacs
Usage
from spacs import SpacsClient, SpacsRequest, SpacsRequestError
from pydantic import BaseModel
...
example_client = SpacsClient(base_url="http://example.com")
# Basic request with error handling
try:
request = SpacsRequest(path="/fruit/apple", params={"cultivar": "honeycrisp"})
apples = await example_client.get(request)
except 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)
request = SpacsRequest(path="/person", body=example_object, response_model=MyModel)
created_person = await example_client.post(request)
# Manually closing a session
await example_client.close()
# Alternatively, to close all open sessions:
await 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.5.tar.gz
(5.1 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.5-py3-none-any.whl
(5.1 kB
view details)
File details
Details for the file spacs-0.0.5.tar.gz.
File metadata
- Download URL: spacs-0.0.5.tar.gz
- Upload date:
- Size: 5.1 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 |
147e8663c169b3bc370296e4cfeb2bc216f85cec901e54a47b3f9a0346bf8b6c
|
|
| MD5 |
2d3c2a23f20c81815b8aeb32a7f25d46
|
|
| BLAKE2b-256 |
73957017e407c96e42cd6a27d9852dda553e351e4d1f899777732e36ef729b30
|
File details
Details for the file spacs-0.0.5-py3-none-any.whl.
File metadata
- Download URL: spacs-0.0.5-py3-none-any.whl
- Upload date:
- Size: 5.1 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 |
b26a187399d3b13c77ac7aed61c27b203e67ddfe43a7db2a44dd21aa73bea219
|
|
| MD5 |
d1ccbaf95e03943c6d68e81c15df0a41
|
|
| BLAKE2b-256 |
c8e6a079a79b8b93dd6680bde06df01996ac173509f0c047e0a1d69023aad41e
|