Tesla Fleet API library for Python
Project description
tesla_fleet_api
Python library for Tesla Fleet API and Teslemetry.
Currently does not support the end to end encrypted telemetry or command API.
Based on Tesla Developer documentation.
TeslaFleetApi
This is the base class, however can also be used directly if you have a valid user access_token.
import asyncio
import aiohttp
from tesla_fleet_api import TeslaFleetApi, TeslaFleetError
async def main():
async with aiohttp.ClientSession() as session:
api = TeslaFleetApi(
access_token="<access_token>",
session=session,
region="na",
raise_for_status=True,
)
try:
data = await api.vehicle.list()
print(data)
except TeslaFleetError.Base as e:
print(e.message, e.error)
asyncio.run(main())
TeslaFleetOAuth
This extends TeslaFleetApi to support OAuth, and requires a client_id, and either a refresh_token or initial authentication code.
import json
async def main():
with open("auth.json", "r") as f:
auth = json.load(f)
async with aiohttp.ClientSession() as session:
api = TeslaFleetOAuth(
session,
client_id=<client_id>,
access_token=auth["access_token"],
refresh_token=auth["refresh_token"],
expires=auth["expires"],
region="na",
raise_for_status=True,
)
try:
data = await api.vehicle.list()
print(data)
except TeslaFleetError.Base as e:
print(e.message, e.error)
with open("auth.json", "w") as f:
json.dump(
{
"access_token": api.access_token,
"refresh_token": api.refresh_token,
"expires": api.expires,
},
f,
)
asyncio.run(main())
Teslemetry
This extends TeslaFleetApi to send requests through Teslemetry, which manages all aspects of Tesla OAuth. This class only requires an access_token from the Teslemetry console.
import asyncio
import aiohttp
from tesla_fleet_api import Teslemetry, TeslaFleetError
async def main():
async with aiohttp.ClientSession() as session:
api = Teslemetry(
access_token="<access_token>",
session=session,
raise_for_status=True,
)
try:
data = await api.vehicle.list()
print(data)
except TeslaFleetError.Base as e:
print(e.message, e.error)
asyncio.run(main())
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
tesla_fleet_api-0.1.1.tar.gz
(22.3 kB
view hashes)
Built Distribution
Close
Hashes for tesla_fleet_api-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63549d696a1d4ecccc41ff24996a8b40ffc9e014d9ecb6e83994d3a96b1b4241 |
|
MD5 | 12597a8110dd60cf06f8b5935604d18e |
|
BLAKE2b-256 | 3e0c9b8bbcefaca7ebd819f9d67a40c71f6986106d2ed7affc8823f1a5cd664a |