Connect
pingthings.timeseries.connect
¶
connect(
profile: Optional[str] = None,
endpoint: Optional[str] = None,
concurrency_limit: Optional[int] = None,
) -> Client
Connect to the timeseries platform.
Security best practice
To prevent accidental leakage of user credentials by hardcoded apikeys, this option has been removed from the function argument.
Your apikey must be included in the environment variable $BTRDB_API_KEY, and is set by default when you login to the PredictiveGrid JupyterHub environment.
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 |
|---|---|
|
The name of a profile containing the required connection information as found in the user's predictive grid credentials file |
|
The address and port of the cluster to connect to, e.g. |
|
The maximum number of concurrent database requests to have in flight at any one time, if not set, will be inferred from environment variable |
| 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 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,
concurrency_limit: Optional[int] = None,
) -> AsyncClient
Connect to the timeseries platform and return an asynchronous client.
Security best practice
To prevent accidental leakage of user credentials by hardcoded apikeys, this option has been removed from the function argument.
Your apikey must be included in the environment variable $BTRDB_API_KEY, and is set by default when you login to the PredictiveGrid JupyterHub environment.
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 |
|---|---|
|
The name of a profile containing the required connection information as found in the user's predictive grid credentials file |
|
The address and port of the cluster to connect to, e.g. |
|
The maximum number of concurrent database requests to have in flight at any one time, if not set, will be inferred from environment variable |
| 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 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')