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.1.tar.gz (3.8 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.1-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: spacs-0.0.1.tar.gz
  • Upload date:
  • Size: 3.8 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.1.tar.gz
Algorithm Hash digest
SHA256 31b54f2358def28ee3fdfb05ef4d56e25dfad3b9ad0735e358b1a6cdc14bae46
MD5 ab7e7d2076ced6585ddc2c62eb714fde
BLAKE2b-256 2d1aad7cbf2e321a768bcf246fbb5afd29340a4ff792939ac525000e1a386ea6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spacs-0.0.1-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

Hashes for spacs-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 165246343efb919f5943605b2d83a6e14cc00b0e408a16881848290de17bbb22
MD5 9acb6ae92522e33660a3a2898d907c6d
BLAKE2b-256 44e1536fa52c8377c57c235037470e5a08af20a7300dad7e1b4f4d37757c3352

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