Skip to main content

Teslemetry Streaming API library for Python

Project description

Teslemetry Stream Library

This is an asynchronous Python 3 library that connects to the Teslemetry Stream server and provides Tesla Fleet Telemetry using server side events.

Installation

pip install teslemetry-stream

Usage

The TeslemetryStream class requires:

  • session: an aiohttp.ClientSession
  • access_token: an access token from the Teslemetry console
  • vin: your Tesla's Vehicle Identification Number

The TeslemetryStream instance can then be configured with:

  • add_field(field, interval)
  • remove_field(field)
  • add_alert(alert)
  • remove_alert(alert)

The full list of possible values are provided in TeslemetryStream.Fields and TeslemetryStream.Alerts

To connect, either use async with on the instance, call connect(), or register an async callback on listen(), which will connect automatically.

Using connect() or listen() will require you to close the session manually using close().

Example

The following example puts the listening loop in the background, then stopping after 20 seconds.

async def main():
    async with aiohttp.ClientSession() as session:
        stream = TeslemetryStream(
            access_token="<token>",
            vin="<vin>",
            session=session,
        )
        await stream.connect()

        async def callback(event):
            print(event)

        asyncio.create_task(stream.listen(callback))

        await asyncio.sleep(20)
        await stream.close()

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

teslemetry_stream-0.0.5.tar.gz (9.8 kB view hashes)

Uploaded Source

Built Distribution

teslemetry_stream-0.0.5-py3-none-any.whl (10.3 kB view hashes)

Uploaded Python 3

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