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.2.tar.gz
(3.9 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.2-py3-none-any.whl
(3.8 kB
view details)
File details
Details for the file spacs-0.0.2.tar.gz.
File metadata
- Download URL: spacs-0.0.2.tar.gz
- Upload date:
- Size: 3.9 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 |
a607dc366ef6ce13e7cfb71f5d60377ba8b63983f006cd8b05e167468cfad2f1
|
|
| MD5 |
63428d806a0da0e9204e97e4ca82f29b
|
|
| BLAKE2b-256 |
730d6a5f45165722e80c200841390c833ac620cf2b8e175c0e9cb1fd9b59b997
|
File details
Details for the file spacs-0.0.2-py3-none-any.whl.
File metadata
- Download URL: spacs-0.0.2-py3-none-any.whl
- Upload date:
- Size: 3.8 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 |
31ff7a89e88003f01922aef419d68e12bd926db5f83bc4fb288a17b9dfd3c6d7
|
|
| MD5 |
650908ef6341d5aeef9b711f47191c13
|
|
| BLAKE2b-256 |
a417de7ad022458bbffc515d385d4b99951a1426301d543b5f925c2b4c955b97
|