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
from tesla_fleet_api.exceptions import TeslaFleetError
async def main():
async with aiohttp.ClientSession() as session:
api = TeslaFleetApi(
access_token="<access_token>",
session=session,
region="na",
)
try:
data = await api.vehicle.list()
print(data)
except TeslaFleetError as e:
print(e)
asyncio.run(main())
TeslaFleetOAuth
This extends TeslaFleetApi to support OAuth, and requires a client_id, and either a refresh_token or initial authentication code.
from tesla_fleet_api import TeslaFleetOAuth
from tesla_fleet_api.exceptions import TeslaFleetError
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",
)
try:
data = await api.vehicle.list()
print(data)
except TeslaFleetError as e:
print(e)
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,
)
try:
data = await api.vehicle.list()
print(data)
except TeslaFleetError as e:
print(e)
asyncio.run(main())
Tessie
This extends TeslaFleetApi to send requests through Tessie, which manages all aspects of Tesla OAuth. This class only requires an access_token from Tessie.
import asyncio
import aiohttp
from tesla_fleet_api import Tessie
from tesla_fleet_api.exceptions import TeslaFleetError
async def main():
async with aiohttp.ClientSession() as session:
api = Tessie(
access_token="<access_token>",
session=session,
)
try:
data = await api.vehicle.list()
print(data)
except TeslaFleetError as e:
print(e)
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.8.4.tar.gz
.
File metadata
- Download URL: tesla_fleet_api-0.8.4.tar.gz
- Upload date:
- Size: 52.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78467c4ab8be90a02d6e231530f6d162f567ec042fdd1a69757a2ac86ff0f1c1 |
|
MD5 | b3a014d69fee0fbb93fcc3e3b428035d |
|
BLAKE2b-256 | cc7cbe33274c86155f40e0ddfed244217737d265bd1caf466badb0888d902bce |
File details
Details for the file tesla_fleet_api-0.8.4-py3-none-any.whl
.
File metadata
- Download URL: tesla_fleet_api-0.8.4-py3-none-any.whl
- Upload date:
- Size: 64.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3b6b325730f65bb43026f1ffada645287ef4bac432f96f613db059d633405bf |
|
MD5 | 5ceaaab0cf8307d4b7e38ecdc13fdda7 |
|
BLAKE2b-256 | 3c02363d2b0ea4266c29e3925b46d6b7c5e5131842241f7633a0a339b008e395 |