Skip to main content

Easy access for TrackUnit REST API

Project description

TrackUnitPython

test lint Coverage Status

Python API for Trackunit

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
  • asyncio functions availeble
  • if data is cached it can process 12000 cached requests with 20 million data points in under 5 minutes.
  • uses sqlite to cache data efficiently
  • requests throttle function (Trackunit-API limits to 50 requests per second)
  • provides stream-based generators for processing of big data

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.TrackUnit import TrackUnit

# Create the API
# It loads the key from api.key by default
tu = TrackUnit()
# alternatively
tu = TrackUnit(api_key="<api-key>")

# 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
# By default it prints a progress bar when using this function.
# Returns an iterator allowing processing big data
for x, _id in tu.get_multi_history( ['123456', '234567'] , 365):
    print(x, _id)

Example async

import asyncio
from pytrackunit.TrackUnit import TrackUnit

async def main():
    # Create the API
    # It loads the key from api.key by default
    tu = TrackUnit(use_async_generator=True)

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

    # Get history is executing 'Report/UnitHistory'
    # Gets the history for the last 100 days
    history = await tu.async_get_history('123456',100)

    # Get extended data 'Report/UnitExtendedInfo'
    # Gets the history for the last 100 days
    data = await tu.async_get_candata('123456',100)

    # Get faults 'Report/UnitActiveFaults'
    # Gets the history for the last 100 days
    data = await tu.async_get_faults('123456',100)

    # The library supports processing multiple vehicles too
    # For memory intensive requests it supports preprocessing requests
    # By default it prints a progress bar when using this function.
    # Returns an iterator allowing processing big data
    # This is prefered if data gets bigger, because it only collects data when needed,
    # thus reducing needed memory
    async for x, _id in tu.get_multi_history( ['123456', '234567'] , 365):
        print(x, _id)

if __name__ == '__main__':
    asyncio.run(main())

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.4.1.tar.gz (26.8 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.4.1-py3-none-any.whl (27.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytrackunit-2.4.1.tar.gz
  • Upload date:
  • Size: 26.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for pytrackunit-2.4.1.tar.gz
Algorithm Hash digest
SHA256 bb77ec8ce90406f26ceb0fd2b6b379a2e79ae5756fa367e755deec7f7262ff2c
MD5 457757f4bc58daf8933982009a9dc42b
BLAKE2b-256 ee73a4831a37eedcf5fc0c9508bf707dafd42192d88ccc2acb5c2b7b5e2411ad

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytrackunit-2.4.1-py3-none-any.whl
  • Upload date:
  • Size: 27.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for pytrackunit-2.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b74dc9341f747e2385a3946ac3a8b27c153966a655f531b741e3dc2d58a3eb78
MD5 8648ac3b8e689109a6355b00e7bebdad
BLAKE2b-256 437851b06e8c838a0f2784e6dfb3002058e0e473a6abbf96a14cd75d97542442

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