Skip to main content

Easy access for TrackUnit REST API

Project description

TrackUnitPython

Python API for Trackunit

example workflow

example workflow

example workflow

What is this package

This packages contains some usefull functions for an easy interface to TrackUnit's REST API. For information to the data see here.

Features:

  • caches requests for faster access
  • for timespan's bigger than 30 days it sufficiantly devides it into allowed requests
  • processing big datasets more efficient by preprocessing per dataslice
  • makes use of asyncio
  • if data is cached it can process 12000 cached requests with 20 million data points in under 5 minutes.

For more features write an issue here. Pull requests are welcome.

How to use

Install

Install the package via pip

pip install pytrackunit

Create a file in your execution directory with the name api.key which contains your TrackUnit API token. If that doesnt work for you, you can set the token in the constructor by calling tu = TrackUnit(api_key="<your key>").

Example

from pytrackunit.helper import *
from pytrackunit.TrackUnit import TrackUnit

# Create the API
# It loads the key from api.key by default
tu = TrackUnit()

# Get all vehicles from trackunit
# This is executing the 'Unit' request 
vehicles = tu.get_unitlist()

# Get history is executing 'Report/UnitHistory'
# Gets the history for the last 100 days
history = tu.get_history(vehicles[0]['id'],100)

# Get extended data 'Report/UnitExtendedInfo'
# Gets the history for the last 100 days
data = tu.get_candata(vehicles[0]['id'],100)

# Get faults 'Report/UnitActiveFaults'
# Gets the history for the last 100 days
data = tu.get_faults(vehicles[0]['id'],100)

# The library supports processing multiple vehicles too
# For memory intensive requests it supports preprocessing requests
# Preprocessing is done with a function taking a list and a dict and returning a list.
# By default it prints a progress bar when using this function.
# Besides the data wich was returned by trackunit, process_slice gets some meta-
# data about the query which produced the _slice data.
units = ["123456","456789"]
def process_slice(_slice,meta):
    return list(map(lambda x: (meta["id"],x["time"],x["externalPower"]),_slice))
data = tu.get_multi_history( units, 365, process_slice)

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

pytrackunit-2.2.1.tar.gz (20.9 kB view details)

Uploaded Source

Built Distribution

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

pytrackunit-2.2.1-py3-none-any.whl (21.2 kB view details)

Uploaded Python 3

File details

Details for the file pytrackunit-2.2.1.tar.gz.

File metadata

  • Download URL: pytrackunit-2.2.1.tar.gz
  • Upload date:
  • Size: 20.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for pytrackunit-2.2.1.tar.gz
Algorithm Hash digest
SHA256 bae6e8cc2f5e453149ebbba330e29274fa595b4f14a3485431f2885a8847fcff
MD5 b5ba34b2f1b7c05d6f219ffa2d3a5295
BLAKE2b-256 e3ff5b592fa5c37d60c9e0c49dc0f0ae95b30d959e9dacba87a63d1d3a317ef4

See more details on using hashes here.

File details

Details for the file pytrackunit-2.2.1-py3-none-any.whl.

File metadata

  • Download URL: pytrackunit-2.2.1-py3-none-any.whl
  • Upload date:
  • Size: 21.2 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.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for pytrackunit-2.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 204fc357e7aed727c42d95c3f3729a5851b08109288b9e91e0e66fff89fcb730
MD5 12e70d77c294c4060a38e36396dd9318
BLAKE2b-256 45d7f6acce73210695a77bff2464a91c75eeb53e6e233462a417e2a420754267

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