Getting Started¶
Warning
Calcbench data is not free and API access is not included in the standard Calcbench subscription. Talk to us@calcbench.com before you start coding.
Installing the Client¶
Install the Calcbench client from pip:
$ pip install calcbench-api-client
Obtain Credentials¶
The API uses the same credentials as calcbench.com. If you do not have Calcbench credentials you can sign up for free two-week trial @ https://www.calcbench.com/join.
Save Credentials¶
Credentials can be stored in the “CALCBENCH_USERNAME” and “CALCBENCH_PASSWORD” environment variables OR set the calcbench_api credentials on your Keychain|Secret Service|Windows Credential Locker
Set Credentials At Runtime¶
Call cb.set_credentials(”user@calcbench.com”, “password”)
On an interactive shell the package will ask for credentials as input
Set Credentials¶
- calcbench.set_credentials(cb_username, cb_password)¶
Set your calcbench credentials.
Call this before any other Calcbench functions.
Alternatively set the
CALCBENCH_USERNAME
andCALCBENCH_PASSWORD
environment variables OR set the calcbench_api credentials on your Keychain|Secret Service|Windows Credential Locker- Parameters:
cb_username (str) – Your calcbench.com email address
cb_password (str) – Your calcbench.com password
Usage:
>>> calcbench.set_credentials("andrew@calcbench.com", "NotMyRealPassword")
Error Retry¶
- calcbench.enable_backoff(backoff_on=True, giveup=<function <lambda>>)¶
Re-try failed requests with exponential back-off
Requires the backoff package.
pip install backoff
If processes make many requests, failures are inevitable. Call this to retry failed requests.
By default gives up immediately if the server returns 404
- Parameters:
backoff_on (
bool
) – toggle backoffgiveup (
Callable
[[RequestException
],bool
]) – function that handles exception and decides whether to continue or not.
- Usage::
>>> calcbench.enable_backoff(giveup=lambda e: e.response and e.response.status_code == 404)
Network Proxy¶
- calcbench.set_proxies(proxies)¶
Set proxies used for requests. See https://requests.readthedocs.io/en/master/user/advanced/#proxies
Logging¶
- calcbench.turn_on_logging(level=10, timezone='US/Eastern')¶
Turn on verbose logging
- Return type:
Logger