nokey.helperFuncs package

Submodules

nokey.helperFuncs.get_api_list module

nokey.helperFuncs.get_api_list.get_api_list()[source]

Prints out the APIs in a visually pleasing format with headings for the categories and the individual APIs under the respective headings.

Parameters:

None

Returns:

A list of the apis supported by the nokey package.

Return type:

string

nokey.helperFuncs.make_request module

nokey.helperFuncs.make_request.add_params(params, params_list)[source]

Adds parameters to the params dictionary if their values are not None.

Parameters:
  • params (dict) – The dictionary to add parameters to.

  • params_list (list of tuples) – Each tuple contains (original_param_name, new_param_name).

nokey.helperFuncs.make_request.make_request(url, headers=None, payload=None)[source]

Make an HTTP request to the specified URL with optional headers and payload.

Parameters:
  • url (str) – The URL of the API endpoint.

  • headers (dict, optional) – Headers to be included in the request.

  • payload (dict, optional) – The payload to be sent in the request body.

Returns:

A dictionary containing the response data or error information.

Return type:

dict

nokey.helperFuncs.make_request.make_request_for_content(url, headers=None)[source]

Make a request to an API if the API call returns content other than in JSON format.

Parameters:

url (str) – The url of the API.

Returns:

Text in any format containing either the response data or an error message.

Return type:

string

nokey.helperFuncs.make_request.make_request_for_content_with_params(url, params, headers=None)[source]

Make a request to an API if the API call returns content other than in JSON format.

Parameters:

url (str) – The url of the API.

Returns:

Text in any format containing either the response data or an error message.

Return type:

string

nokey.helperFuncs.make_request.make_request_with_params(url, params, headers=None)[source]

Make a request to an API if the API call requires params.

Parameters:
  • url (str) – The url of the API.

  • params (dict) – The params to be included in the request.

Returns:

A dictionary containing either the response data or an error message.

Return type:

dict

nokey.helperFuncs.make_request.make_request_with_post_and_data(url, data)[source]

Make a request to an API if the API using the POST method.

Parameters:
  • url (str) – The url of the API.

  • data (dict) – The data to be included in the request.

Returns:

A dictionary containing either the response data or an error message.

Return type:

dict

nokey.helperFuncs.make_request.make_request_with_post_and_json(url, json)[source]

Make a request to an API if the API using the POST method.

Parameters:
  • url (str) – The url of the API.

  • data (dict) – The data to be included in the request.

Returns:

A dictionary containing either the response data or an error message.

Return type:

dict

nokey.helperFuncs.nokey_apis module

nokey.helperFuncs.throttler module

class nokey.helperFuncs.throttler.Throttler(rate_limit: int, period: int)[source]

Bases: object

A class to enforce rate limiting on function calls.

rate_limit

The maximum number of allowed calls within the period.

Type:

int

period

The time period in seconds during which the rate limit applies.

Type:

int

last_call

The time of the last function call.

Type:

float

num_calls

The number of calls made within the current period.

Type:

int

throttle()[source]

Enforce the rate limit. If the number of calls exceeds the rate limit within the period, this method will make the calling thread sleep until the period resets.

nokey.helperFuncs.throttler.throttle_class(rate_limit: int, period: int)[source]

Class decorator to apply throttling to all methods in the class.

Parameters:
  • rate_limit (int) – The maximum number of allowed calls within the period.

  • period (int) – The time period in seconds during which the rate limit applies.

Returns:

The decorated class with throttling applied to its methods.

Return type:

cls

Module contents