helpjuice.client

Client

This module provides a Client object to interface with the Helpjuice API.

Module Contents

Classes

HelpjuiceAuth

Attaches API Key Authentication to the given Request object.

Client

Helpjuice Client.

TimeoutHTTPAdapter

The built-in HTTP Adapter for urllib3.

Attributes

logger

helpjuice.client.logger
class helpjuice.client.HelpjuiceAuth(api_key)

Bases: requests.auth.HTTPBasicAuth

Attaches API Key Authentication to the given Request object.

class helpjuice.client.Client(account, api_key, v='v3', timeout=5, total=5, backoff_factor=30)

Bases: requests.Session

Helpjuice Client.

Constructs a requests.Session for Helpjuice API requests with authorization, base URL, request timeouts, and request retries.

Parameters
  • account (str) – Helpjuice base address subdomain.

  • api_key (str) – Helpjuice API key.

  • version (str, optional) – Helpjuice API version. Defaults to “v3”.

  • timeout (int, optional) – TimeoutHTTPAdapter timeout value. Defaults to 5.

  • total (int, optional) – Retry total value. Defaults to 5.

  • backoff_factor (int, optional) – Retry backoff_factor value. Defaults to 30.

Usage:

from helpjuice import Client

helpjuice = Client(account="your-account", api_key="ffb722a62e8**********************")

# Get a single article
article = helpjuice.Article(id=1).get()

# Search for articles with pagination
for question in helpjuice.Search().get(query="foo", limit=1000, paginate=True):
    print(question)
request(method, path, *args, **kwargs)

Override Session request method to add retries and output JSON.

Parameters
  • method (str) – Method for the new Request object.

  • path (str) – Path from host for the new Request object.

Returns

Response JSON

Return type

dict

class helpjuice.client.TimeoutHTTPAdapter(timeout, *args, **kwargs)

Bases: requests.adapters.HTTPAdapter

The built-in HTTP Adapter for urllib3.

Provides a general-case interface for Requests sessions to contact HTTP and HTTPS urls by implementing the Transport Adapter interface. This class will usually be created by the Session class under the covers.

Parameters
  • pool_connections – The number of urllib3 connection pools to cache.

  • pool_maxsize – The maximum number of connections to save in the pool.

  • max_retries – The maximum number of retries each connection should attempt. Note, this applies only to failed DNS lookups, socket connections and connection timeouts, never to requests where data has made it to the server. By default, Requests does not retry failed connections. If you need granular control over the conditions under which we retry a request, import urllib3’s Retry class and pass that instead.

  • pool_block – Whether the connection pool should block for connections.

Usage:

>>> import requests
>>> s = requests.Session()
>>> a = requests.adapters.HTTPAdapter(max_retries=3)
>>> s.mount('http://', a)
send(request, **kwargs)

Override HTTPAdapter send method to add a default timeout.