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.6.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.6-py3-none-any.whl
(5.1 kB
view details)
File details
Details for the file spacs-0.0.6.tar.gz.
File metadata
- Download URL: spacs-0.0.6.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 |
0046c8e58d183fd3292a9519ab6d65a425cb20d7fea6216c789c933163f899fc
|
|
| MD5 |
dcded57aa3a34e75747d1636e9e60e26
|
|
| BLAKE2b-256 |
ca81573cbc58776f0f9629d9535538f84b9cdb129009765f691be55f295337b1
|
File details
Details for the file spacs-0.0.6-py3-none-any.whl.
File metadata
- Download URL: spacs-0.0.6-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 |
c4a630cf95b716a9a4169351f207fb08d914a586fb7da0e86d5c937a41822262
|
|
| MD5 |
3ed360b11d96dd8409d20e3a6d2cf372
|
|
| BLAKE2b-256 |
f0cf52e9f04e735dff3f510cd02c539fdf2fbfcc1408eb20363776db532721dc
|