Connection
To work with the API, first create a session. A session can be configured
using a config file or by providing your client_id and client_secret
directly.
We recommend using a config file. Your credentials and authentication settings then live outside your code, so changing them never requires a code change.
Get the required credentials by creating an OAuth client at auth.volueinsight.com (see the documentation for details).
Using a config file (recommended)
Section titled “Using a config file (recommended)”Create a config file (e.g. config.ini). The simplest way is to copy the
sample config file
and insert your client_id and client_secret:
[common]urlbase = https://data-forecasts.volue.comauth_type = OAuthtimeout = 300
[OAuth]id = client_idsecret = client_secretauth_urlbase = https://auth.volueinsight.comThen pass the file path when creating the session:
import volue_insight_timeseriesconfig_file_path = 'path/to/your/config.ini'session = volue_insight_timeseries.Session(config_file=config_file_path)timeout is in seconds and defaults to 300.
Directly using client ID and secret
Section titled “Directly using client ID and secret”You can also pass credentials directly:
import volue_insight_timeseriessession = volue_insight_timeseries.Session( client_id='client id', client_secret='client secret', timeout=300)The timeout parameter is optional and defaults to 300 seconds.
Connection settings
Section titled “Connection settings”Proxy and CA bundle from environment variables
Section titled “Proxy and CA bundle from environment variables”The library responds to the standard environment variables
(HTTPS_PROXY, REQUESTS_CA_BUNDLE, etc.) if they are present.
Your own requests session
Section titled “Your own requests session”Pass your own requests.Session when you need a proxy, a CA bundle, a client
certificate or a larger connection pool, and cannot set them through
environment variables. All requests, authentication included, are sent
through it.
import requestsimport volue_insight_timeseries
http_session = requests.Session()http_session.proxies = {'https': 'http://proxy.example.com:8080'}http_session.verify = '/path/to/ca-bundle.pem'
session = volue_insight_timeseries.Session( config_file='config.ini', requests_session=http_session)Retries
Section titled “Retries”By default, a request that times out, fails to connect, or gets a 408 or 5xx
response is retried 4 times, with 0.5 seconds between attempts. Change the
number with retries, or pass a urllib3 Retry for other rules, such as
backoff:
import volue_insight_timeseriesfrom urllib3.util import Retry
session = volue_insight_timeseries.Session(config_file='config.ini', retries=2)
session = volue_insight_timeseries.Session( config_file='config.ini', retries=Retry(total=5, backoff_factor=1, status_forcelist=[502, 503, 504], allowed_methods=None, raise_on_status=False))retries=0 turns retries off. Use it when your own requests_session already
retries through a urllib3 Retry on its adapters; otherwise requests are
retried at both levels.