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.
- 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.
- 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 initialClientSession
in case it is not available. - 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. - The whole library is annotated with Python types so type checkers can help us detect errors early on rather than at runtime.
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
Built Distribution
Close
Hashes for project_async-0.0.1rc99.post1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2abe203b40be86f672bdba040796a9d35bba15ac29e0bf980fe1989f262f0fd3 |
|
MD5 | 4b09e254bd10934b4831de4c82011280 |
|
BLAKE2b-256 | cc9b06567dbc49e3d496f7ff2f101f7f2641eb4b2265c551123c347e67d00b8b |
Close
Hashes for project_async-0.0.1rc99.post1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ffbad0460a4d2db848084dad441b76ba330c5bbe2f673e4f39a1dc697914e7e |
|
MD5 | c4d5f6163f882b042f840ad1b82a032b |
|
BLAKE2b-256 | 2b2e2ddce08fc7a309e13a540bb1b09ee5451190b16bde018352dbae66894fad |