Sklik Client

class SklikClient(user_id=None, endpoint='https://api.sklik.cz/drak/json/v5/', max_retries=5, session=None)[source]

Client for accessing the Sklik API.

Performs authentication, session handling, and provides a generic call() method for calling any other operations in the API. This method can automatically inject session and user IDs as the first parameter.

Parameters:
  • user_id (int) – ID of the Sklik account.

  • endpoint (str) – Sklik API endpoint. Currently points to https://api.sklik.cz/drak/json/v5/.

  • max_retries (int) – Maximum number of retries

call(operation, *args, **kwargs)[source]

Performs the given API call and returns its result.

If the authenticated kwarg is set to True (or not given at all), this function passes the object with session (and userId, if it was set during the creation) as the first argument. You have to omit the argument when performing call.

Example:

>>> client = SklikClient(user_id=10)
>>> client.login('<api_token>')
>>> client.call('client.stats', {'dateFrom': '2020-01-01', 'dateTo': '2020-01-02', 'granularity': 'daily'})
{
    'status': 200,
    'statusMessage': 'OK',
    'report': [
        {
            'date': '20200101T00:00:00+0000',
            'impressions': 0,
            'clicks': 0,
            'ctr': 0,
            'cpc': 0,
            'price': 0,
            'avgPosition': 0.0,
            'conversions': 0,
            'conversionRatio': 0,
            'conversionAvgPrice': 0,
            'conversionValue': 0,
            'conversionAvgValue': 0,
            'conversionValueRatio': 0,
            'transactions': 0,
            'transactionAvgPrice': 0,
            'transactionAvgValue': 0,
            'transactionAvgCount': 0
        },
        {
            'date': '20200102T00:00:00+0000',
            'impressions': 0,
            'clicks': 0,
            'ctr': 0,
            'cpc': 0,
            'price': 0,
            'avgPosition': 0.0,
            'conversions': 0,
            'conversionRatio': 0,
            'conversionAvgPrice': 0,
            'conversionValue': 0,
            'conversionAvgValue': 0,
            'conversionValueRatio': 0,
            'transactions': 0,
            'transactionAvgPrice': 0,
            'transactionAvgValue': 0,
            'transactionAvgCount': 0
        }
    ]
}
Parameters:
  • operation – Name of the Sklik API operation to call, e.g. keywords.create.

  • args – Arguments of the operation. If authenticated is True (default), start with the second argument.

  • authenticated – If set to True (default value), session ID will be passed as the first parameter of the call.

  • include_user_id – If set to True (default value), user ID will be passed in the first parameter of the call.

Return type:

dict[str, Any]

Returns:

Response from the API as a dictionary.

Raises:

SklikCallError – if the operation did not succeed.

get_batch_limit(operation, default_limit=100)[source]

Gets the limit of report rows/request entities for the given operation.

This function retrieves the result of api.limits operation, caches it, and tries to look up the limit in the following order:

Given the operation in the format <entity>.<method> (e.g. keywords.update):

  1. <entity>.<method> (keywords.update)

  2. global.<method> (global.update)

  3. Return value of the default_limit parameter.

Parameters:
  • operation (str) – Name of the operation, e.g. keywords.create.

  • default_limit (int) – Default value to use when the Sklik API does not return any limit for the operation.

Return type:

int

Returns:

Limit for the given operation.

load_limits()[source]

Loads the batch operation limits using the api.limits call. Requires the client to be authenticated, because the api.limits call requires user authentication.

Return type:

dict[str, int]

property logged_in
Returns:

True if the client is logged in.

login(login_key)[source]

Logs into to the Sklik API and stores the session ID.

Parameters:

login_key (str) – Sklik API token.

Return type:

bool

Returns:

Always True. If the login is not successful, an exception is raised.

Raises:

SklikCallError – if the login did not succeed.

logout()[source]

Logs out of the Sklik API

Return type:

bool

Returns:

Always True. If the logout is not successful, an exception is raised.

Raises:

SklikCallError – if the logout did not succeed.

property user_id: int
Returns:

Current user ID.