Skip to main content

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


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.3.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spacs-0.0.3-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file spacs-0.0.3.tar.gz.

File metadata

  • Download URL: spacs-0.0.3.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.11.1 Windows/10

File hashes

Hashes for spacs-0.0.3.tar.gz
Algorithm Hash digest
SHA256 72e74f581a3c91de33c0386be279d677b90cc5df0683dcfd23449682f5acb4cf
MD5 f42a1f4b89d8b9eec93f0cee7bc31ee7
BLAKE2b-256 511b8209e8a00f37a4dfac71d4bc184394c95a28e5a47a2d731a3792b75331e8

See more details on using hashes here.

File details

Details for the file spacs-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: spacs-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.11.1 Windows/10

File hashes

Hashes for spacs-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 19a058fb50448746cc9ccba4e6eabd2527f1c2df5da85f5d1a866ee626b05abf
MD5 0219475412592bcae459bd2fe0d5c541
BLAKE2b-256 acd43950c714144480bc429e17089fb0ff103977fd85b4ea3ea9eb93f7b8f55f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page