Official Sage data client.
Project description
Sage Data Client
This is the official Sage Python data API client. Its main goal is to make writing queries and working with the results easy. It does this by:
- Providing a simple query function which talks to the data API.
- Providing the results in an easy to use Pandas data frame.
Installation
Sage Data Client can be installed with pip using:
pip3 install sage-data-client
If you prefer to install this package into a Python virtual environment or are unable to install it system wide, you can use the venv module as follows:
# 1. Create a new virtual environment called my-venv.
python3 -m venv my-venv
# 2. Activate the virtual environment
source my-venv/bin/activate
# 3. Install sage data client in the virtual environment
pip3 install sage-data-client
Note: If you are using Linux, you may need to install the python3-venv
package which is outside of the scope of this document.
Note: You will need to activate this virtual environment when opening a new terminal before running any Python scripts using Sage Data Client.
Usage Examples
Query API
import sage_data_client
# query and load data into pandas data frame
df = sage_data_client.query(
start="-1h",
filter={
"name": "env.temperature",
}
)
# print results in data frame
print(df)
# meta columns are expanded into meta.fieldname. for example, here we print the unique nodes
print(df["meta.vsn"].unique())
# print stats of the temperature data grouped by node + sensor.
print(df.groupby(["meta.vsn", "meta.sensor"]).value.agg(["size", "min", "max", "mean"]))
import sage_data_client
# query and load data into pandas data frame
df = sage_data_client.query(
start="-1h",
filter={
"name": "env.raingauge.*",
}
)
# print number of results of each name
print(df.groupby(["meta.vsn", "name"]).size())
Load results from file
If we have saved the results of a query to a file data.json
, we can also load using the load
function as follows:
import sage_data_client
# load results from local file
df = sage_data_client.load("data.json")
# print number of results of each name
print(df.groupby(["meta.vsn", "name"]).size())
Integration with Notebooks
Since we leverage the fantastic work provided by the Pandas library, performing things like looking at dataframes or creating plots is easy.
A basic example of querying and plotting data can be found here.
Additional Examples
Additional code examples can be found in the examples directory.
If you're interested in contributing your own examples, feel free to add them to examples/contrib and open a PR!
Reference
The query
function accepts the following arguments:
start
. Absolute or relative start timestamp. (required)end
. Absolute or relative end timestamp.head
. Limit results tohead
earliest values per series. (Only one ofhead
ortail
can be provided.)tail
. Limit results totail
latest values per series. (Only one ofhead
ortail
can be provided.)filter
. Key-value patterns to filter data on.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file sage_data_client-0.8.0.post1.tar.gz
.
File metadata
- Download URL: sage_data_client-0.8.0.post1.tar.gz
- Upload date:
- Size: 7.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e73eaae9da0f4d26596efcb7b4dfe4f363d383c5542fd01edcf0025a3533f563 |
|
MD5 | a72b2ab03a1996f172d3bf9fe58d9dfc |
|
BLAKE2b-256 | 5466709b1707e46bf4cd2d254f5a9e060a1bde7c4e28904c038bbf5eab08fe5d |
File details
Details for the file sage_data_client-0.8.0.post1-py3-none-any.whl
.
File metadata
- Download URL: sage_data_client-0.8.0.post1-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d63a650c137c4c54d3b696c05f3ddc8b668a75dd4a8b11ed5d2c516bbf9c762 |
|
MD5 | 9154d20cff791d7bf46a56ad19cec0f0 |
|
BLAKE2b-256 | 1bcdff2637edba2b57cb49833a3c8e90cb8dc4b49d53b50e36db64637311bfa4 |