Skip to main content

A python wrapper around the UTS REST API.

Project description

UTS-PYTHON-REST-API

A python wrapper around the UTS REST API.

Find out how to get started using UltraTimeSeries in our Website: https://twoimpulse.com/ultratimeseries/

How to use

This is a simple guide on how to get started using UltraTimeSeries (UTS) Python REST API.

The motives behind this wrapper around UltraTimeSeries (UTS) REST API was to reduce even more the complexity of the system and make it as accessible as possible. We assembled this simple introductory script in order to teach you how to get data flowing as soon as possible. The operations used assume familiarity with the UltraTimeSeries data model and concepts.

1 - Introduction

To start interacting with UltraTimeSeries (UTS) we need to have access to an instance either locally or remotely. For this example script we also used a .CSV file named records containing readings from the value of Ethereum, the popular digital currency, over time. Start by importing this package

import uts

2 - Instanciate a Node object

To get it startad we’ll need to indicate Python where is this UltraTimeSeries instance running, we’ll need to instanciate a UTS object that indicates where the instance is running, both the URL and the Host.

node = uts.UTS(URL,Host)
node = uts.UTS('http://localhost:8080','localhost')

#OR

node = uts.UTS()
#This is also valid for the given parameters since the values are defaulted to:
#URL = 'http://localhost:8080'
#Host = 'localhost'

If Authentication is enabled, make sure to Login, this only needs to be done once.

node.login('my_api_key')

3 - Actor Insertion

An actor is an entity capable of producing/generating data. Actors have only two properties: Key - a unique and unequivocal way to identify this actor, is property is mandatory. Created - a system property with the actors' database write date, this property cannot be changed by developers. Creating an actor involves calling actorCreate(actorKey)

#The Subject in the messages we got from the .CSV file came as 'ETHEUR'
#Let's create an actor with the same key
actors = node.Actors()
actors.AddActor('ETHEUR')
node.actorCreate(actors)

4 - Message Insertion

Messages like actors are one of the atomic units in UltraTimeSeries. A message should be seen as a single event whereas a list of events is a time series. Message can be added individually or as a collection. Adding multiple messages in one go is more efficient than iterating and adding a single at a time. For this example a Message follows this structure:

#unique identifier of the actor who produced this data
actor = 'ETHEUR'

#name of the time series, the action that we're monitoring
action = 'Value'

#a dimension is a measure of a physical variable (without numerical values)...
#while a unit is a way to assign a number or measurement to that dimension by identifying the dimension and the unit the system can now do
#automatic conversion (e.g meters to yards) 
#when combined they become a measure
measure = uts.CurrencyEuro()

#unit of measure actual value
#This value is set as an example since we will be reading it from the messages
value = 3000

#date when the event occured, must be in Coordinated Universal Time (UTC)
#This value is set as an example since we will be reading it from the messages
date = '2021-08-25T22:55:57.8253388Z'

#Feed from the records.csv and populate the database with Messages:
#Insert messages in the database
with open('records.csv','r') as records:
   content = csv.reader(records)
   next(content)
   #Instanciate a Messages object
   messages = node.Messages()
   #Create the messages you pretend to insert
   for line in content:
       #addMessage takes as arguments, the actor, action, measure, value and date respectively
       messages.addMessage(line[0],'Value',uts.CurrencyEuro(),line[1],line[2])
   node.messageCreate(messages)

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

ultratimeseries-api-1.0.5.tar.gz (34.4 kB view details)

Uploaded Source

Built Distribution

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

ultratimeseries_api-1.0.5-py3-none-any.whl (21.1 kB view details)

Uploaded Python 3

File details

Details for the file ultratimeseries-api-1.0.5.tar.gz.

File metadata

  • Download URL: ultratimeseries-api-1.0.5.tar.gz
  • Upload date:
  • Size: 34.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.25.1 requests-toolbelt/0.9.1 urllib3/1.26.5 tqdm/4.61.1 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.5

File hashes

Hashes for ultratimeseries-api-1.0.5.tar.gz
Algorithm Hash digest
SHA256 47201ddace5898c3749924995733a0359d22ac7909c00a7a8257a3dec521437e
MD5 f8dc3bfefe4c94aae7b61d8173de196c
BLAKE2b-256 7315de6f25b421f853e0cdeee815850facd203b42c97d606b8f7f15e02fe15d1

See more details on using hashes here.

File details

Details for the file ultratimeseries_api-1.0.5-py3-none-any.whl.

File metadata

  • Download URL: ultratimeseries_api-1.0.5-py3-none-any.whl
  • Upload date:
  • Size: 21.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.25.1 requests-toolbelt/0.9.1 urllib3/1.26.5 tqdm/4.61.1 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.5

File hashes

Hashes for ultratimeseries_api-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 ee5106444a4f50c7a6b6bfbfa5eea8f74490c3d3ecf251dd8a6e1641179b9ed3
MD5 1b5480c5a44412114ce088bcdcbb0ac6
BLAKE2b-256 67cfab28caba442354b9664f4bfa9cb22d42a284b4f1442bfbfbfa5c453cc783

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