tesla-fleet-api


Nametesla-fleet-api JSON
Version 1.2.2 PyPI version JSON
download
home_pageNone
SummaryTesla Fleet API library for Python
upload_time2025-07-14 23:20:12
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseNone
keywords
VCS
bugtrack_url
requirements aiohttp aiolimiter cryptography protobuf aiofiles bleak bleak-retry-connector
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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:

```bash
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:

```python
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:

```python
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](docs/fleet_api_vehicles.md).

### Fleet API for Energy Sites

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

```python
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](docs/fleet_api_energy_sites.md).

### 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:

```python
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](docs/fleet_api_signed_commands.md).

### Bluetooth for Vehicles

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

```python
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](docs/bluetooth_vehicles.md).

### Teslemetry

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

```python
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](docs/teslemetry.md).

### Tessie

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

```python
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](docs/tessie.md).

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "tesla-fleet-api",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": null,
    "author": null,
    "author_email": "Brett Adams <hello@teslemetry.com>",
    "download_url": "https://files.pythonhosted.org/packages/b7/1a/5a2be18492b43705a801a8df6389e52e377ee02894dcea2358ba4a2cd559/tesla_fleet_api-1.2.2.tar.gz",
    "platform": null,
    "description": "# Tesla Fleet API\n\nTesla 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.\n\n## Features\n\n- Fleet API for vehicles\n- Fleet API for energy sites\n- Fleet API with signed vehicle commands\n- Bluetooth for vehicles\n- Teslemetry integration\n- Tessie integration\n\n## Installation\n\nYou can install the library using pip:\n\n```bash\npip install tesla-fleet-api\n```\n\n## Usage\n\n### Authentication\n\nThe `TeslaFleetOAuth` class provides methods that help with authenticating to the Tesla Fleet API. Here's a basic example:\n\n```python\nimport asyncio\nimport aiohttp\nfrom tesla_fleet_api import TeslaFleetOAuth\n\nasync def main():\n    async with aiohttp.ClientSession() as session:\n        oauth = TeslaFleetOAuth(\n            session=session,\n            client_id=\"<client_id>\",\n            client_secret=\"<client_secret>\",\n            redirect_uri=\"<redirect_uri>\",\n        )\n\n        # Get the login URL and navigate the user to it\n        login_url = oauth.get_login_url(scopes=[\"openid\", \"email\", \"offline_access\"])\n        print(f\"Please go to {login_url} and authorize access.\")\n\n        # After the user authorizes access, they will be redirected to the redirect_uri with a code\n        code = input(\"Enter the code you received: \")\n\n        # Exchange the code for a refresh token\n        await oauth.get_refresh_token(code)\n        print(f\"Access token: {oauth.access_token}\")\n        print(f\"Refresh token: {oauth.refresh_token}\")\n        # Dont forget to store the refresh token so you can use it again later\n\nasyncio.run(main())\n```\n\n### Fleet API for Vehicles\n\nThe `TeslaFleetApi` class provides methods to interact with the Fleet API for vehicles. Here's a basic example:\n\n```python\nimport asyncio\nimport aiohttp\nfrom tesla_fleet_api import TeslaFleetApi\nfrom tesla_fleet_api.exceptions import TeslaFleetError\n\nasync def main():\n    async with aiohttp.ClientSession() as session:\n        api = TeslaFleetApi(\n            access_token=\"<access_token>\",\n            session=session,\n            region=\"na\",\n        )\n\n        try:\n            data = await api.vehicles.list()\n            print(data)\n        except TeslaFleetError as e:\n            print(e)\n\nasyncio.run(main())\n```\n\nFor more detailed examples, see [Fleet API for Vehicles](docs/fleet_api_vehicles.md).\n\n### Fleet API for Energy Sites\n\nThe `EnergySites` class provides methods to interact with the Fleet API for energy sites. Here's a basic example:\n\n```python\nimport asyncio\nimport aiohttp\nfrom tesla_fleet_api import TeslaFleetApi\nfrom tesla_fleet_api.exceptions import TeslaFleetError\n\nasync def main():\n    async with aiohttp.ClientSession() as session:\n        api = TeslaFleetApi(\n            access_token=\"<access_token>\",\n            session=session,\n            region=\"na\",\n        )\n\n        try:\n            energy_sites = await api.energySites.list()\n            print(energy_sites)\n        except TeslaFleetError as e:\n            print(e)\n\nasyncio.run(main())\n```\n\nFor more detailed examples, see [Fleet API for Energy Sites](docs/fleet_api_energy_sites.md).\n\n### Fleet API with Signed Vehicle Commands\n\nThe `VehicleSigned` class provides methods to interact with the Fleet API using signed vehicle commands. Here's a basic example:\n\n```python\nimport asyncio\nimport aiohttp\nfrom tesla_fleet_api import TeslaFleetApi\nfrom tesla_fleet_api.tesla.vehicle.signed import VehicleSigned\nfrom tesla_fleet_api.exceptions import TeslaFleetError\n\nasync def main():\n    async with aiohttp.ClientSession() as session:\n        api = TeslaFleetApi(\n            access_token=\"<access_token>\",\n            session=session,\n            region=\"na\",\n        )\n\n        try:\n            vehicle = VehicleSigned(api, \"<vin>\")\n            data = await vehicle.wake_up()\n            print(data)\n        except TeslaFleetError as e:\n            print(e)\n\nasyncio.run(main())\n```\n\nFor more detailed examples, see [Fleet API with Signed Vehicle Commands](docs/fleet_api_signed_commands.md).\n\n### Bluetooth for Vehicles\n\nThe `TeslaBluetooth` class provides methods to interact with Tesla vehicles using Bluetooth. Here's a basic example:\n\n```python\nimport asyncio\nfrom bleak import BleakScanner\nfrom tesla_fleet_api import TeslaBluetooth\n\nasync def main():\n    scanner = BleakScanner()\n    devices = await scanner.discover()\n    for device in devices:\n        if TeslaBluetooth().valid_name(device.name):\n            print(f\"Found Tesla vehicle: {device.name}\")\n\nasyncio.run(main())\n```\n\nFor more detailed examples, see [Bluetooth for Vehicles](docs/bluetooth_vehicles.md).\n\n### Teslemetry\n\nThe `Teslemetry` class provides methods to interact with the Teslemetry service. Here's a basic example:\n\n```python\nimport asyncio\nimport aiohttp\nfrom tesla_fleet_api import Teslemetry\nfrom tesla_fleet_api.exceptions import TeslaFleetError\n\nasync def main():\n    async with aiohttp.ClientSession() as session:\n        api = Teslemetry(\n            access_token=\"<access_token>\",\n            session=session,\n        )\n\n        try:\n            data = await api.vehicles.list()\n            print(data)\n        except TeslaFleetError as e:\n            print(e)\n\nasyncio.run(main())\n```\n\nFor more detailed examples, see [Teslemetry](docs/teslemetry.md).\n\n### Tessie\n\nThe `Tessie` class provides methods to interact with the Tessie service. Here's a basic example:\n\n```python\nimport asyncio\nimport aiohttp\nfrom tesla_fleet_api import Tessie\nfrom tesla_fleet_api.exceptions import TeslaFleetError\n\nasync def main():\n    async with aiohttp.ClientSession() as session:\n        api = Tessie(\n            access_token=\"<access_token>\",\n            session=session,\n        )\n\n        try:\n            data = await api.vehicles.list()\n            print(data)\n        except TeslaFleetError as e:\n            print(e)\n\nasyncio.run(main())\n```\n\nFor more detailed examples, see [Tessie](docs/tessie.md).\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Tesla Fleet API library for Python",
    "version": "1.2.2",
    "project_urls": {
        "Homepage": "https://github.com/Teslemetry/python-tesla-fleet-api"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "b7ad88fad6fe5e6a01e0d880a76b197fd0b81656144007811017ea553767f521",
                "md5": "b8e0b2f76b647920d59ca81932df3dba",
                "sha256": "9284fce91d794743f25f96e72b1c5dd2c77b950abf92368358dbbace33f09bab"
            },
            "downloads": -1,
            "filename": "tesla_fleet_api-1.2.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b8e0b2f76b647920d59ca81932df3dba",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 120139,
            "upload_time": "2025-07-14T23:20:10",
            "upload_time_iso_8601": "2025-07-14T23:20:10.715614Z",
            "url": "https://files.pythonhosted.org/packages/b7/ad/88fad6fe5e6a01e0d880a76b197fd0b81656144007811017ea553767f521/tesla_fleet_api-1.2.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "b71a5a2be18492b43705a801a8df6389e52e377ee02894dcea2358ba4a2cd559",
                "md5": "e521aeca6f6c8c891f66e43127c19e77",
                "sha256": "1bf68c575f8e00ecf2bc55a6bba2c82e8f845d5f59a101f78b10909a2c77fb2e"
            },
            "downloads": -1,
            "filename": "tesla_fleet_api-1.2.2.tar.gz",
            "has_sig": false,
            "md5_digest": "e521aeca6f6c8c891f66e43127c19e77",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 100119,
            "upload_time": "2025-07-14T23:20:12",
            "upload_time_iso_8601": "2025-07-14T23:20:12.509249Z",
            "url": "https://files.pythonhosted.org/packages/b7/1a/5a2be18492b43705a801a8df6389e52e377ee02894dcea2358ba4a2cd559/tesla_fleet_api-1.2.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-14 23:20:12",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Teslemetry",
    "github_project": "python-tesla-fleet-api",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "aiohttp",
            "specs": [
                [
                    "==",
                    "3.*"
                ]
            ]
        },
        {
            "name": "aiolimiter",
            "specs": [
                [
                    "==",
                    "1.*"
                ]
            ]
        },
        {
            "name": "cryptography",
            "specs": [
                [
                    "==",
                    "43.*"
                ]
            ]
        },
        {
            "name": "protobuf",
            "specs": [
                [
                    "==",
                    "6.31.1"
                ]
            ]
        },
        {
            "name": "aiofiles",
            "specs": [
                [
                    "==",
                    "24.*"
                ]
            ]
        },
        {
            "name": "bleak",
            "specs": [
                [
                    "==",
                    "0.22.*"
                ]
            ]
        },
        {
            "name": "bleak-retry-connector",
            "specs": [
                [
                    "==",
                    "3.9.*"
                ]
            ]
        }
    ],
    "lcname": "tesla-fleet-api"
}
        
Elapsed time: 0.65503s