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
- One or both:
- vin: your Tesla's Vehicle Identification Number
- server: The Teslemetry server to connect to
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 callback with async_add_listener
, which will connect when added and disconnect when removed.
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()
def callback(event):
print(event["data"])
remove = stream.async_add_listener(callback)
print("Running")
await asyncio.sleep(60)
remove()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for teslemetry_stream-0.1.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b5f69527f63abdf6ed835bbb446c2dd45c117e10e434026c164166d48c051951 |
|
MD5 | 064b97cd62420bee6006638c8687fdd8 |
|
BLAKE2b-256 | 2a261e9be0f9772848ab383457990491fbc2aef542c9ff5358cc10491b1f341f |