Skip to main content

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:

  1. Providing a simple query function which talks to the data API.
  2. 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 to head earliest values per series. (Only one of head or tail can be provided.)
  • tail. Limit results to tail latest values per series. (Only one of head or tail can be provided.)
  • filter. Key-value patterns to filter data on.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sage_data_client-0.9.1.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sage_data_client-0.9.1-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file sage_data_client-0.9.1.tar.gz.

File metadata

  • Download URL: sage_data_client-0.9.1.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for sage_data_client-0.9.1.tar.gz
Algorithm Hash digest
SHA256 8d1b0e02afc085441542c567aa47a6c866859a7c86ca908e57b96f35affbb9f4
MD5 a5dea93558b36fa37688fa144ad49d02
BLAKE2b-256 4d7e36868a4b5dee741bd60738da0a56d5719510a6103afec6222de8d11516a7

See more details on using hashes here.

File details

Details for the file sage_data_client-0.9.1-py3-none-any.whl.

File metadata

File hashes

Hashes for sage_data_client-0.9.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a08efebe898010bc58418ec14c1374ff2337efc19dd6e379e4904b82264edaad
MD5 c3bbb103aa4a8a9b6f5b1f0b0ce106a5
BLAKE2b-256 bb8fa8b7f2baa3a04059f88afbf56f5ff668a6b9fa70e58c9668b681d27c2ea4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page