Async client for YCLIENTS API
Project description
YCLIENTS API async client
Important. This library is not official!
Asynchronous client for interacting with the YCLIENTS API.
To work with the YCLIENTS API, you will need a partner token (Bearer), which can be obtained by following the link.
Installing
Python version required: >= 3.10.*
- Installing with pip:
pip3 install yclients-aio-client
- Also, you can install from source with:
git clone https://github.com/akimrx/yclients-aio-client --recursive
cd yclients-aio-client
make install
or
git clone https://github.com/akimrx/yclients-aio-client --recursive
cd yclients-aio-client
python3 setup.py install
Getting started
Backoff strategy
Each HTTP request, in case of failure, will be repeated a limited number of times, using an exponential backoff strategy with jitter.
The number of attempts, the delay time between them and the jitter range can be changed using environment variables.
YCLIENTS_BACKOFF_MAX_TRIES
— Maximum number of total call attempts if the HTTP request failedYCLIENTS_BACKOFF_JITTER
— Enables jitter if True is passedYCLIENTS_BACKOFF_BASE_DELAY
– Basic delay between attempts (dynamic when jitter is on)YCLIENTS_BACKOFF_EXPO_FACTOR
– Multiplier for exponential backoff
You can use an additional backoff for your methods through the decorator yclients_aio_client.utils.decorators.backoff
, however, it is not necessary to decore already decorated default cases:
- Internal Server Errors, i.e. 5xx HTTP-codes
- Network Errors, i.e. DNS, connect and socket fails
Sync usage
If your code is synchronous and you don't want to use async for some reason, you can wrap the func calls with asyncio.run
.
import asyncio
from typing import Coroutine, Any
from yclients_aio_client import AsyncYclientsClient
partner_token = "xxxxxxxxxxxxxxxxxxxx"
yclients = AsyncYclientsClient(partner_token=partner_token, raise_client_errors=True)
def _(coroutine: Coroutine) -> Any:
"""Wrapper for run async fucntion synchronous."""
return asyncio.run(coroutine)
def authenticate_user(user: str, password: str) -> str:
"""Get user token by user:password pair."""
result = _(yclients.auth.get_user_token(user, password))
return result.data.user_token
Logging
This library uses the logging
module.
Example of usage:
import logging
logging.basicConfig(
level=logging.INFO,
format='[%(levelname)s] %(message)s'
)
logger = logging.getLogger(__name__)
Change library log level:
import logging
logging.getLogger("yclients_aio_client").setLevel(logging.ERROR)
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
Hashes for yclients-aio-client-0.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa030a69af53195c2f770791f792d730f5b0b2e1752e0d1baf1452e3af85a352 |
|
MD5 | 1e128dde4ef94355b59f2bd69a703dcd |
|
BLAKE2b-256 | 5d3c73c7754262d6faf5d8e8de1b75bb8f523a019086d2a11e288dfdca1a4226 |
Hashes for yclients_aio_client-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 528e3caf415e29195de2ed5e6ce118e39e15d3cb1bbfc44957c8e09e14a9ddca |
|
MD5 | 61ed26446ba8a511ff946da3cb08a67e |
|
BLAKE2b-256 | 122812a0a8ac68c9fb9eb4a872e910108fa44a5a6ad10371d6d2f1ad713d0819 |