Setup

Install the Ottimate Python SDK, exchange your credentials for an access token, and create an authenticated client.

Prerequisites

  • Python 3.8 or later
  • An Ottimate API key, OAuth client ID, and client secret. See Authentication for how to obtain them.

Install the package

The SDK is published to PyPI as ottimate-sdk. Install it into a virtual environment:

$python3 -m venv venv
$source venv/bin/activate
$pip install ottimate-sdk==0.1.7

The distribution is named ottimate-sdk, but the import name is ottimate:

1from ottimate import Ottimate

Configure your credentials

Keep credentials out of source control. Create a .env file alongside your script:

OTTIMATE_API_KEY="your_api_key"
OTTIMATE_CLIENT_ID="your_client_id"
OTTIMATE_CLIENT_SECRET="your_client_secret"
OTTIMATE_ACCOUNT_ID="racc_..."
OTTIMATE_COMPANY_ID="your_company_id"
OTTIMATE_LOCATION_ID="your_location_id"

Load them with any loader you prefer. The examples below use python-dotenv, which you can add with pip install python-dotenv:

1import os
2from dotenv import load_dotenv
3
4load_dotenv()
5
6api_key = os.environ["OTTIMATE_API_KEY"]
7client_id = os.environ["OTTIMATE_CLIENT_ID"]
8client_secret = os.environ["OTTIMATE_CLIENT_SECRET"]
9
10# Account IDs are strings prefixed with `racc_`; company and location IDs are integers
11ottimate_account_id = os.environ["OTTIMATE_ACCOUNT_ID"]
12ottimate_company_id = int(os.environ["OTTIMATE_COMPANY_ID"])
13ottimate_location_id = int(os.environ["OTTIMATE_LOCATION_ID"])

These variable names are the ones used by the rest of the pages in this section.

Choose an environment

Select the target environment with the OttimateEnvironment enum rather than hardcoding a URL. Both values already include the required /v1 path segment.

ValueBase URL
OttimateEnvironment.SANDBOXhttps://sandbox-api.ottimate.com/v1
OttimateEnvironment.PRODUCTIONhttps://api.ottimate.com/v1

PRODUCTION is the default. Start against SANDBOX while you build — see Sandbox Environment.

Authenticate and create the client

Authentication is a two-step exchange. First create a short-lived client that carries only your API key and call the OAuth endpoint. Then create the client you will actually use, passing the returned access token as a bearer token.

1from ottimate import Ottimate, OttimateEnvironment
2
3ENVIRONMENT = OttimateEnvironment.SANDBOX
4
5# 1. Exchange client credentials for an access token
6auth_client = Ottimate(environment=ENVIRONMENT, api_key=api_key)
7
8token_response = auth_client.oauth.post_oauth_token(
9 client_id=client_id,
10 client_secret=client_secret,
11 scope="accounts.can_access_dashboard",
12)
13access_token = token_response.access_token
14
15# 2. Create the authenticated client
16client = Ottimate(
17 environment=ENVIRONMENT,
18 api_key=api_key,
19 api_version="1.0.0",
20 headers={"Authorization": f"Bearer {access_token}"},
21)

The token response also exposes token_type, expires_in, and scope. Tokens expire, so cache the token and repeat step 1 when expires_in elapses or a request returns 401. See Authentication for details.

Verify the client works

Fetch the companies on your account as a smoke test:

1companies = client.accounts.get_accounts_id_companies(id=ottimate_account_id)
2print(companies)

The client object created here is the one used by every other page in this section.

Optional settings

ParameterPurpose
base_urlOverride the environment with an explicit URL. Takes precedence over environment.
api_versionPin the API version header. Defaults to the latest supported version.
timeoutPer-request timeout in seconds. Defaults to 60.
headersAdditional headers sent with every request.
httpx_clientSupply your own configured httpx.Client.

Async usage

For asyncio applications, import AsyncOttimate instead. It takes the same arguments and exposes the same methods as coroutines:

1from ottimate import AsyncOttimate, OttimateEnvironment
2
3client = AsyncOttimate(
4 environment=OttimateEnvironment.SANDBOX,
5 api_key=api_key,
6 headers={"Authorization": f"Bearer {access_token}"},
7)
8
9companies = await client.accounts.get_accounts_id_companies(id=ottimate_account_id)