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
from tesla_fleet_api.exceptions import 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 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
Built Distribution
File details
Details for the file tesla_fleet_api-0.2.0.tar.gz
.
File metadata
- Download URL: tesla_fleet_api-0.2.0.tar.gz
- Upload date:
- Size: 22.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a538bfb8fdc3edfc4841cac753f7d7d0557079b3d31e8df22eca593125731965 |
|
MD5 | 200106aa3ca0d025586c27686f0fff4a |
|
BLAKE2b-256 | 09f9ac521d0839b97b87b8356f6a96c6597e15b6b7f70693d470fbe8c16829e1 |
Provenance
File details
Details for the file tesla_fleet_api-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: tesla_fleet_api-0.2.0-py3-none-any.whl
- Upload date:
- Size: 27.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c84c624653374f8fe4b8c31e253f05ea9d076643443b135ef063cb959cf07623 |
|
MD5 | 73b5fda4524f67c62fbcc1079ce53ed9 |
|
BLAKE2b-256 | 01a3aad59f0993d019e8033beb7ef86e414f7bf8900aa9b0efe520b6f6789024 |