Skip to content

Connect

pingthings.timeseries.connect

connect(
    profile: Optional[str] = None,
    endpoint: Optional[str] = None,
    apikey: Optional[str] = None,
    concurrency_limit: Optional[int] = None,
) -> Client

Connect to the timeseries platform.

Connecting to the platform for commercial customers

If you are a commercial customer and are using the PingThings JupyterHub/Lab environment to work with the timeseries platform, the relevant connection information has already been added to your session in the form of environment variables. All you need to do to connect to the platform is the following:

import pingthings as pt
conn = pt.timeseries.connect()

Choosing a concurrency limit

The default concurrency limit is defined in pingthings.timeseries.constants. If the environment variable is not set, it will use this default value. Using a large concurrency limit has the ability to cause large memory consumption, and if the job gets killed, it can also lead to a hard to kill zombie process. Most users will probably be fine with the default concurrency limit, but feel free to explore larger values.

PARAMETER DESCRIPTION

profile

The name of a profile containing the required connection information as found in the user's predictive grid credentials file ${HOME}/.predictivegrid/credentials.yaml.

TYPE: Optional[str] DEFAULT: None

endpoint

The address and port of the cluster to connect to, e.g. 192.168.1.1:4411, if not set, will look for the environment variable $BTRDB_ENDPOINTS

TYPE: Optional[str] DEFAULT: None

apikey

The API key used to authenticate requests, if not set, the key is looked up from the environment variable $BTRDB_API_KEY.

TYPE: Optional[str] DEFAULT: None

concurrency_limit

The maximum number of concurrent database requests to have in flight at any one time, if not set, will be inferred from environment variable $PINGTHINGS_CONCURRENCY_LIMIT or the default limit defined in pingthings.timeseries.constants.DEFAULT_CONCURRENCY_LIMIT.

TYPE: Optional[int] DEFAULT: None

RETURNS DESCRIPTION
Client

A timeseries client.

Examples:

Connecting to the timeseries platform as a commercial customer in the PingThings provided JupyterHub/Lab environment. This behavior also works if you have the environment variables set, refer to the above docstring for more information.

import pingthings as pt
conn = pt.timeseries.connect()

Connecting to the timeseries platform when you know your api key and FQDN endpoint.

import pingthings as pt
my_key = "ABC123"
my_endpoint = "example.com:4411"

conn = pt.timeseries.connect(apikey=my_key, endpoint=my_endpoint)

Connecting to the platform when you have a populated ${HOME}/.predictivegrid/credentials.yaml file with profiles.

import pingthings as pt
conn = pt.timeseries.connect(profile='my_server')

pingthings.timeseries.async_connect async

async_connect(
    profile: Optional[str] = None,
    endpoints: Optional[str] = None,
    apikey: Optional[str] = None,
    concurrency_limit: Optional[int] = None,
) -> AsyncClient

Connect to the timeseries platform and return an asynchronous client.

Advanced user feature

For most customers, using the synchronous client (which will leverage the asynchronous client under the hood) will be sufficient. If you need to leverage the asynchronous functions yourself, this function can be useful.

Connecting to the platform for commercial customers

If you are a commercial customer and are using the PingThings JupyterHub/Lab environment to work with the timeseries platform, the relevant connection information has already been added to your session in the form of environment variables. All you need to do to connect to the platform is the following:

import pingthings as pt
async_conn = await pt.timeseries.async_connect()

Choosing a concurrency limit

The default concurrency limit is defined in pingthings.timeseries.constants. If the environment variable is not set, it will use this default value. Using a large concurrency limit has the ability to cause large memory consumption, and if the job gets killed, it can also lead to a hard to kill zombie process. Most users will probably be fine with the default concurrency limit, but feel free to explore larger values.

PARAMETER DESCRIPTION

profile

The name of a profile containing the required connection information as found in the user's predictive grid credentials file ${HOME}/.predictivegrid/credentials.yaml.

TYPE: Optional[str] DEFAULT: None

endpoints

The address and port of the cluster to connect to, e.g. 192.168.1.1:4411, if not set, will look for the environment variable $BTRDB_ENDPOINTS

TYPE: Optional[str] DEFAULT: None

apikey

The API key used to authenticate requests, if not set, the key is looked up from the environment variable $BTRDB_API_KEY.

TYPE: Optional[str] DEFAULT: None

concurrency_limit

The maximum number of concurrent database requests to have in flight at any one time, if not set, will be inferred from environment variable $PINGTHINGS_CONCURRENCY_LIMIT.

TYPE: Optional[int] DEFAULT: None

RETURNS DESCRIPTION
AsyncClient

A timeseries client.

Examples:

Connecting to the timeseries platform as a commercial customer in the PingThings provided JupyterHub/Lab environment This behavior also works if you have the environment variables set, refer to the above docstring for more information.

>>> import pingthings as pt
>>> conn = await pt.timeseries.async_connect()

Connecting to the timeseries platform when you know your api key and FQDN endpoint.

>>> import pingthings as pt
>>> my_key = "ABC123"
>>> my_endpoint = "example.com:4411"
>>> conn = await pt.timeseries.async_connect(apikey=my_key, endpoint=my_endpoint)

Connecting to the platform when you have a populated ${HOME}/.predictivegrid/credentials.yaml file with profiles.

>>> import pingthings as pt
>>> conn = await pt.timeseries.async_connect(profile='my_server')