Skip to main content

Python Async API Client

This have in mind to start developing API clients for Home Assistant to be 100% asynchronous

How to Use it?

Fork this repository by using it as a template.

Structure

This package provides good defaults for any API client code that is split on the following modules:

  • errors.py: module that define the custom errors the API and/or client would be returning to their users.
  • model.py: definition of the API data model. All returned objects from the clients would be defined here.
  • client.py: the logic around calling the API

Development

To start developing with this package, fork it, create a virtual environment and install all the dependencies needed for development.

python3 -m venv .venv
source .venv/bin/activate
pip install '.[dev]'

Best Practices

This package provides already an skeleton with some best practices when starting developing your API client.

  1. 100% async from the start: Home Assistant runs its main logic using an asynchronous engine, and having 3rd party clients running async can have performance benefits and ease of integration on new and existing components.
  2. A aiohttp.ClientSession should always to be a constructor argument (so a session and connection pool can be shared between multiple clients). The template already provides a class constructor to create the Client without any initial ClientSession in case it is not available.
  3. The output of each API endpoint is a typed Model that is build as a dataclass and can be parsed from a JSON response or a nested dictionary. This ensures the consumer of the API outputs can take benefits from the benefits dataclasses provide like readaibility on its structure and field types.
  4. The whole library is annotated with Python types so type checkers can help us detect errors early on rather than at runtime.

Release files for meteoswiss-async 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for meteoswiss-async 0.1.1
File Size Uploaded
meteoswiss_async-0.1.1.tar.gz 15.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for meteoswiss-async 0.1.1
File Interpreter ABI Platform
meteoswiss_async-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 24.1 kB

Release files / meteoswiss_async-0.1.1.tar.gz

Download URL meteoswiss_async-0.1.1.tar.gz
Size 15.3 kB
Tags Source
SHA-256 checksum
How to use checksums
14f6285e32818c2516410471e7fd6df4e03cf22da6e3ec0ff6f917bd6f9344a7
BLAKE2b-256 checksum
How to use checksums
c9418850d12509ff8d1d867553f29cad8090f75956ea90cc6fb728ddccf318cb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.32.3

Release files / meteoswiss_async-0.1.1-py3-none-any.whl

Download URL meteoswiss_async-0.1.1-py3-none-any.whl
Size 8.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
abdfec117050d40ab1bc8e5f90cc27824bde48abcfa221c714f809429351328e
BLAKE2b-256 checksum
How to use checksums
b40f4f2df0b2ed26d524a5ffdc918bd538402d41a47aa1f9761dcd0800fae46d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.32.3
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page