Skip to main content

Async client for YCLIENTS API

Project description

YCLIENTS API async client

PyPI - Python Version PyPi Package Codecov Codacy Badge Tests Build

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 failed
  • YCLIENTS_BACKOFF_JITTER — Enables jitter if True is passed
  • YCLIENTS_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

See full example

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yclients-aio-client-0.0.1.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

yclients_aio_client-0.0.1-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file yclients-aio-client-0.0.1.tar.gz.

File metadata

  • Download URL: yclients-aio-client-0.0.1.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for yclients-aio-client-0.0.1.tar.gz
Algorithm Hash digest
SHA256 fa030a69af53195c2f770791f792d730f5b0b2e1752e0d1baf1452e3af85a352
MD5 1e128dde4ef94355b59f2bd69a703dcd
BLAKE2b-256 5d3c73c7754262d6faf5d8e8de1b75bb8f523a019086d2a11e288dfdca1a4226

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for yclients_aio_client-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 528e3caf415e29195de2ed5e6ce118e39e15d3cb1bbfc44957c8e09e14a9ddca
MD5 61ed26446ba8a511ff946da3cb08a67e
BLAKE2b-256 122812a0a8ac68c9fb9eb4a872e910108fa44a5a6ad10371d6d2f1ad713d0819

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