Python SDK to ensure excellent user experience for developers and data scientists working with the Cognite Data Platform.
In order to start using the Python SDK, you need
- Python3 and pip
- An API key. Never include the API key directly in the code or upload the key to github. Instead, set the API key as an environment variable. See the usage example for how to authenticate with the API key.
This is how you set the API key as an environment variable on Mac OS and Linux:
$ export COGNITE_API_KEY=<your API key>
On Windows, you can follows these instructions to set the API key as an environment variable.
$ pip install cognite-sdk
Simple script to download and plot one year of hourly aggregates.
import os
import matplotlib.pyplot as plt
from cognite.config import configure_session
from cognite.v05.timeseries import get_datapoints
# Set API key and project for current session
configure_session(api_key=os.getenv('COGNITE_API_KEY'), project='akerbp')
# Retrieve one year of hourly aggreagets for timeseries 'equipment_x'
ts = 'equipment_x'
datapoints = get_datapoints(ts, start='52w-ago', aggregates=['avg'], granularity='1h')
# Convert to pandas dataframe
dataframe = datapoints.to_pandas()
# Plot the dataframe
dataframe.plot(x='timestamp')
plt.show()
Public examples will come in the examples folder in this repository. This will include examples for:
- Retrieval of timeseries data, using aggregates, granularity, etc.
- Different methods for retrieving data and navigating the data set
- How to get events and why events are useful
- How to use functionality which is in the public API, but not yet incorporated into the SDK, using requests
Check out the documentation below, including the public API guide.
If you work at Cognite, you can find examples of code use in the repository ML-examples.
Want to contribute? Check out CONTRIBUTING.
Apache 2.0