Skip to main content

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


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

Uploaded Source

Built Distribution

tesla_fleet_api-0.4.1-py3-none-any.whl (29.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tesla_fleet_api-0.4.1.tar.gz
  • Upload date:
  • Size: 23.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.8

File hashes

Hashes for tesla_fleet_api-0.4.1.tar.gz
Algorithm Hash digest
SHA256 d1e496ee30ddcf9ddeebc7eb1eb9b4a2c6c48e83595cd0fbaee20b761105730f
MD5 7a27ac88d6e866ca4ecafa77d60bcd96
BLAKE2b-256 cb010a71a61e9b381cb2499e36ffbed842358dbf65a9dca1f6e4d5c4c645d57f

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for tesla_fleet_api-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a7d182c1f01401a5d5d635d28577a4cb8cc6bd995bd812fd9a7b747afe6b550c
MD5 e781e64e38f461580e34dad88efc438f
BLAKE2b-256 f7637d00f929441064be81039fb73884bcfd486dc9ba4d4a8df360122dad9e6e

See more details on using hashes here.

Provenance

Supported by

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