Skip to main content

Sample Python Project for creating a new Python Async Client for a new API

Project description

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.

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

project_async-0.0.1rc105.post1.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file project_async-0.0.1rc105.post1.tar.gz.

File metadata

File hashes

Hashes for project_async-0.0.1rc105.post1.tar.gz
Algorithm Hash digest
SHA256 e0298d8c7faf61e991067ac69ef1d7d43ded035c256a00199efce8fdf3ccbb0c
MD5 3f184eb5dacf0a0e57459352cd008484
BLAKE2b-256 2706924cd9284a82bc0f37ef51a8eceaaebcbcfc05b30493ad20a9a9304317c2

See more details on using hashes here.

File details

Details for the file project_async-0.0.1rc105.post1-py3-none-any.whl.

File metadata

File hashes

Hashes for project_async-0.0.1rc105.post1-py3-none-any.whl
Algorithm Hash digest
SHA256 4354e2a927c3c74a404f34b9e7e1c31a202274ff380545925281c49df10f89a1
MD5 3544c95a4767567090cdb82595443cc7
BLAKE2b-256 b91c4ce7d7e88154bd8846729fd3f110232adc2f54ff5e6f0c7ab3d3dcdac67f

See more details on using hashes here.

Supported by

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