Skip to main content

Tesla Fleet API library for Python

Project description

Tesla Fleet API

Tesla Fleet API is a Python library that provides an interface to interact with Tesla's Fleet API, including signed commands and encrypted local Bluetooth (BLE) communication. It also supports interactions with Teslemetry and Tessie services.

Features

  • Fleet API for vehicles
  • Fleet API for energy sites
  • Fleet API with signed vehicle commands
  • Bluetooth for vehicles
  • Teslemetry integration
  • Tessie integration

Installation

You can install the library using pip:

pip install tesla-fleet-api

Usage

Authentication

The TeslaFleetOAuth class provides methods that help with authenticating to the Tesla Fleet API. Here's a basic example:

import asyncio
import aiohttp
from tesla_fleet_api import TeslaFleetOAuth

async def main():
    async with aiohttp.ClientSession() as session:
        oauth = TeslaFleetOAuth(
            session=session,
            client_id="<client_id>",
            client_secret="<client_secret>",
            redirect_uri="<redirect_uri>",
        )

        # Get the login URL and navigate the user to it
        login_url = oauth.get_login_url(scopes=["openid", "email", "offline_access"])
        print(f"Please go to {login_url} and authorize access.")

        # After the user authorizes access, they will be redirected to the redirect_uri with a code
        code = input("Enter the code you received: ")

        # Exchange the code for a refresh token
        await oauth.get_refresh_token(code)
        print(f"Access token: {oauth.access_token}")
        print(f"Refresh token: {oauth.refresh_token}")
        # Dont forget to store the refresh token so you can use it again later

asyncio.run(main())

Fleet API for Vehicles

The TeslaFleetApi class provides methods to interact with the Fleet API for vehicles. Here's a basic example:

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.vehicles.list()
            print(data)
        except TeslaFleetError as e:
            print(e)

asyncio.run(main())

For more detailed examples, see Fleet API for Vehicles.

Fleet API for Energy Sites

The EnergySites class provides methods to interact with the Fleet API for energy sites. Here's a basic example:

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:
            energy_sites = await api.energySites.list()
            print(energy_sites)
        except TeslaFleetError as e:
            print(e)

asyncio.run(main())

For more detailed examples, see Fleet API for Energy Sites.

Fleet API with Signed Vehicle Commands

The VehicleSigned class provides methods to interact with the Fleet API using signed vehicle commands. Here's a basic example:

import asyncio
import aiohttp
from tesla_fleet_api import TeslaFleetApi
from tesla_fleet_api.tesla.vehicle.signed import VehicleSigned
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:
            vehicle = VehicleSigned(api, "<vin>")
            data = await vehicle.wake_up()
            print(data)
        except TeslaFleetError as e:
            print(e)

asyncio.run(main())

For more detailed examples, see Fleet API with Signed Vehicle Commands.

Bluetooth for Vehicles

The TeslaBluetooth class provides methods to interact with Tesla vehicles using Bluetooth. Here's a basic example:

import asyncio
from bleak import BleakScanner
from tesla_fleet_api import TeslaBluetooth

async def main():
    scanner = BleakScanner()
    devices = await scanner.discover()
    for device in devices:
        if TeslaBluetooth().valid_name(device.name):
            print(f"Found Tesla vehicle: {device.name}")

asyncio.run(main())

For more detailed examples, see Bluetooth for Vehicles.

Teslemetry

The Teslemetry class provides methods to interact with the Teslemetry service. Here's a basic example:

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.vehicles.list()
            print(data)
        except TeslaFleetError as e:
            print(e)

asyncio.run(main())

For more detailed examples, see Teslemetry.

Tessie

The Tessie class provides methods to interact with the Tessie service. Here's a basic example:

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.vehicles.list()
            print(data)
        except TeslaFleetError as e:
            print(e)

asyncio.run(main())

For more detailed examples, see Tessie.

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-1.4.2.tar.gz (105.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tesla_fleet_api-1.4.2-py3-none-any.whl (125.4 kB view details)

Uploaded Python 3

File details

Details for the file tesla_fleet_api-1.4.2.tar.gz.

File metadata

  • Download URL: tesla_fleet_api-1.4.2.tar.gz
  • Upload date:
  • Size: 105.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tesla_fleet_api-1.4.2.tar.gz
Algorithm Hash digest
SHA256 afcafe480914345f6e02046f09c8e7ec283a4b6287cea2a81596a509d101fa3c
MD5 3e53430cf6730021497eb1b18356bfd9
BLAKE2b-256 1645f21d53e18ae272096cb2b5e9d7956c5cff07812335735b7ebffecb4df581

See more details on using hashes here.

Provenance

The following attestation bundles were made for tesla_fleet_api-1.4.2.tar.gz:

Publisher: python-publish.yml on Teslemetry/python-tesla-fleet-api

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tesla_fleet_api-1.4.2-py3-none-any.whl.

File metadata

  • Download URL: tesla_fleet_api-1.4.2-py3-none-any.whl
  • Upload date:
  • Size: 125.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tesla_fleet_api-1.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0f24ddc97eedc16597f5d93ee991d7aebd8d467016b5ec4bf06513286d76344b
MD5 e87a1fe3ff3687da47ef8f9f2f1eb99a
BLAKE2b-256 90878728b726a409665bc9c7f50db7ab173d56086049021737a690ec20e2890d

See more details on using hashes here.

Provenance

The following attestation bundles were made for tesla_fleet_api-1.4.2-py3-none-any.whl:

Publisher: python-publish.yml on Teslemetry/python-tesla-fleet-api

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page