Skip to main content

A client library for the sparkworks rest api

Project description

A client library for accessing data through the SparkWorks Rest API.

SparkWorks Rest API Python Client

This Python package is automatically generated by the Swagger Codegen project:

  • API version: v2.0

  • Build package: io.swagger.codegen.languages.PythonClientCodegen For more information, please visit http://www.sparkworks.net/

Requirements.

Python 2.7 and 3.4+

Installation & Usage

pip install

pip install sparkworksrest

(you may need to run pip with root permission: sudo pip install sparkworksrest)

Then import the package:

import sparkworks_client

Python Client Documentation

Documentation for the client can be found on Github

Setting up the access to the SparkWorks Rest API

import sparkworks_client

# Configure OAuth2 access token for authorization: oauth2
configuration = sparkworks_client.Configuration("username", "password", "client_id", "client_secret")
configuration.connect()

# create an instance of the API class
api_client = sparkworks_client.ApiClient(configuration)

#initialize the clients needed
unit_api_instance = sparkworks_client.UnitApi(api_client)
group_api_instance = sparkworks_client.GroupApi(api_client)
phenomenon_api_instance = sparkworks_client.PhenomenonApi(api_client)
gateway_api_instance = sparkworks_client.GatewayApi(api_client)
resource_api_instance = sparkworks_client.ResourceApi(api_client)
command_api_instance = sparkworks_client.CommandApi(api_client)
registry_api_instance = sparkworks_client.RegistryApi(api_client)
data_api_instance = sparkworks_client.DataApi(api_client)
participatorySensing_api_instance = sparkworks_client.ParticipatorySensingApi(api_client)

Examples

Example 1: List Resources and Access Resource Data

import time

import sparkworks_client

# Configure OAuth2 access token for authorization: oauth2
configuration = sparkworks_client.Configuration("username", "password", "client_id", "client_secret")
configuration.connect()
print("access_token: " + configuration.access_token)

# create an instance of the API class

api_client = sparkworks_client.ApiClient(configuration)

resource_api_instance = sparkworks_client.ResourceApi(api_client)
unit_api_instance = sparkworks_client.UnitApi(api_client)
phenomenon_api_instance = sparkworks_client.PhenomenonApi(api_client)
data_api_instance = sparkworks_client.DataApi(api_client)

# list all Resources
resources = resource_api_instance.get_resources()

print("====resource====")
# retrieve resource by uuid
resource = resource_api_instance.get_resource_by_uuid(resources[0].uuid)
print(resource)

print("====phenomenon====")
phenomenon = phenomenon_api_instance.get_phenomenon_by_uuid(resource.phenomenon_uuid)
print(phenomenon)

print("====unit====")
unit = unit_api_instance.get_unit_by_uuid(resource.unit_uuid)
print(unit)

time_from = (int(round(time.time())) - 5 * 60 * 60) * 1000
time_to = int(round(time.time())) * 1000

print("====data 5min====")
# retrieve data - granularity 5min
data = data_api_instance.query_time_range({
    "queries": [
        {
            "from": time_from,
            "to": time_to,
            "granularity": "5min",
            "resourceUuid": resource.uuid
        }
    ]
})

for d in data.results.values():
    for datum in d.data:
        print("5min", datum)

print("====data hour====")
# retrieve data - granularity hour
data = data_api_instance.query_time_range({
    "queries": [
        {
            "from": time_from,
            "to": time_to,
            "granularity": "hour",
            "resourceUuid": resource.uuid
        }
    ]
})

for d in data.results.values():
    for datum in d.data:
        print("hour", datum)

Example 2: List Groups and Group Resources

import sparkworks_client

# Configure OAuth2 access token for authorization: oauth2
configuration = sparkworks_client.Configuration("username", "password", "client_id", "client_secret")
configuration.connect()
print("access_token: " + configuration.access_token)

# create an instance of the API class

api_client = sparkworks_client.ApiClient(configuration)

resource_api_instance = sparkworks_client.ResourceApi(api_client)
group_api_instance = sparkworks_client.GroupApi(api_client)

print("====groups====")
# list all groups
groups = group_api_instance.get_all_groups()
for group in groups:
    print(group)

print("====group[0].resources====")
# retrieve resources by group uuid
resources = group_api_instance.get_group_resources(groups[0].uuid)
for resource in resources:
    print(resource)

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

sparkworksrest-1.0.15.tar.gz (57.0 kB view details)

Uploaded Source

File details

Details for the file sparkworksrest-1.0.15.tar.gz.

File metadata

  • Download URL: sparkworksrest-1.0.15.tar.gz
  • Upload date:
  • Size: 57.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.2

File hashes

Hashes for sparkworksrest-1.0.15.tar.gz
Algorithm Hash digest
SHA256 ec6ae93fae48db1f8aa9a81bccb2ea841b25eab3722624e629c016ec2c46b741
MD5 0a0f2b22e91dc11ccf643b27481b2f3b
BLAKE2b-256 a3450c12696be961ef714fadf182e655789e7c2ab92119c408c7a00f37d9268c

See more details on using hashes here.

Supported by

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