|
| 1 | +Metadata-Version: 2.4 |
| 2 | +Name: tesla_fleet_api |
| 3 | +Version: 1.3.2 |
| 4 | +Summary: Tesla Fleet API library for Python |
| 5 | +Author-email: Brett Adams < [email protected]> |
| 6 | +License-Expression: Apache-2.0 |
| 7 | +Project-URL: Homepage, https://github.com/Teslemetry/python-tesla-fleet-api |
| 8 | +Classifier: Development Status :: 5 - Production/Stable |
| 9 | +Classifier: Programming Language :: Python :: 3 |
| 10 | +Classifier: Operating System :: OS Independent |
| 11 | +Requires-Python: >=3.10 |
| 12 | +Description-Content-Type: text/markdown |
| 13 | +License-File: LICENSE |
| 14 | +Requires-Dist: aiohttp |
| 15 | +Requires-Dist: aiofiles |
| 16 | +Requires-Dist: aiolimiter |
| 17 | +Requires-Dist: cryptography |
| 18 | +Requires-Dist: protobuf |
| 19 | +Requires-Dist: bleak |
| 20 | +Requires-Dist: bleak-retry-connector |
| 21 | +Dynamic: license-file |
| 22 | + |
| 23 | +# Tesla Fleet API |
| 24 | + |
| 25 | +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. |
| 26 | + |
| 27 | +## Features |
| 28 | + |
| 29 | +- Fleet API for vehicles |
| 30 | +- Fleet API for energy sites |
| 31 | +- Fleet API with signed vehicle commands |
| 32 | +- Bluetooth for vehicles |
| 33 | +- Teslemetry integration |
| 34 | +- Tessie integration |
| 35 | + |
| 36 | +## Installation |
| 37 | + |
| 38 | +You can install the library using pip: |
| 39 | + |
| 40 | +```bash |
| 41 | +pip install tesla-fleet-api |
| 42 | +``` |
| 43 | + |
| 44 | +## Usage |
| 45 | + |
| 46 | +### Authentication |
| 47 | + |
| 48 | +The `TeslaFleetOAuth` class provides methods that help with authenticating to the Tesla Fleet API. Here's a basic example: |
| 49 | + |
| 50 | +```python |
| 51 | +import asyncio |
| 52 | +import aiohttp |
| 53 | +from tesla_fleet_api import TeslaFleetOAuth |
| 54 | + |
| 55 | +async def main(): |
| 56 | + async with aiohttp.ClientSession() as session: |
| 57 | + oauth = TeslaFleetOAuth( |
| 58 | + session=session, |
| 59 | + client_id="<client_id>", |
| 60 | + client_secret="<client_secret>", |
| 61 | + redirect_uri="<redirect_uri>", |
| 62 | + ) |
| 63 | + |
| 64 | + # Get the login URL and navigate the user to it |
| 65 | + login_url = oauth.get_login_url(scopes=["openid", "email", "offline_access"]) |
| 66 | + print(f"Please go to {login_url} and authorize access.") |
| 67 | + |
| 68 | + # After the user authorizes access, they will be redirected to the redirect_uri with a code |
| 69 | + code = input("Enter the code you received: ") |
| 70 | + |
| 71 | + # Exchange the code for a refresh token |
| 72 | + await oauth.get_refresh_token(code) |
| 73 | + print(f"Access token: {oauth.access_token}") |
| 74 | + print(f"Refresh token: {oauth.refresh_token}") |
| 75 | + # Dont forget to store the refresh token so you can use it again later |
| 76 | + |
| 77 | +asyncio.run(main()) |
| 78 | +``` |
| 79 | + |
| 80 | +### Fleet API for Vehicles |
| 81 | + |
| 82 | +The `TeslaFleetApi` class provides methods to interact with the Fleet API for vehicles. Here's a basic example: |
| 83 | + |
| 84 | +```python |
| 85 | +import asyncio |
| 86 | +import aiohttp |
| 87 | +from tesla_fleet_api import TeslaFleetApi |
| 88 | +from tesla_fleet_api.exceptions import TeslaFleetError |
| 89 | + |
| 90 | +async def main(): |
| 91 | + async with aiohttp.ClientSession() as session: |
| 92 | + api = TeslaFleetApi( |
| 93 | + access_token="<access_token>", |
| 94 | + session=session, |
| 95 | + region="na", |
| 96 | + ) |
| 97 | + |
| 98 | + try: |
| 99 | + data = await api.vehicles.list() |
| 100 | + print(data) |
| 101 | + except TeslaFleetError as e: |
| 102 | + print(e) |
| 103 | + |
| 104 | +asyncio.run(main()) |
| 105 | +``` |
| 106 | + |
| 107 | +For more detailed examples, see [Fleet API for Vehicles](docs/fleet_api_vehicles.md). |
| 108 | + |
| 109 | +### Fleet API for Energy Sites |
| 110 | + |
| 111 | +The `EnergySites` class provides methods to interact with the Fleet API for energy sites. Here's a basic example: |
| 112 | + |
| 113 | +```python |
| 114 | +import asyncio |
| 115 | +import aiohttp |
| 116 | +from tesla_fleet_api import TeslaFleetApi |
| 117 | +from tesla_fleet_api.exceptions import TeslaFleetError |
| 118 | + |
| 119 | +async def main(): |
| 120 | + async with aiohttp.ClientSession() as session: |
| 121 | + api = TeslaFleetApi( |
| 122 | + access_token="<access_token>", |
| 123 | + session=session, |
| 124 | + region="na", |
| 125 | + ) |
| 126 | + |
| 127 | + try: |
| 128 | + energy_sites = await api.energySites.list() |
| 129 | + print(energy_sites) |
| 130 | + except TeslaFleetError as e: |
| 131 | + print(e) |
| 132 | + |
| 133 | +asyncio.run(main()) |
| 134 | +``` |
| 135 | + |
| 136 | +For more detailed examples, see [Fleet API for Energy Sites](docs/fleet_api_energy_sites.md). |
| 137 | + |
| 138 | +### Fleet API with Signed Vehicle Commands |
| 139 | + |
| 140 | +The `VehicleSigned` class provides methods to interact with the Fleet API using signed vehicle commands. Here's a basic example: |
| 141 | + |
| 142 | +```python |
| 143 | +import asyncio |
| 144 | +import aiohttp |
| 145 | +from tesla_fleet_api import TeslaFleetApi |
| 146 | +from tesla_fleet_api.tesla.vehicle.signed import VehicleSigned |
| 147 | +from tesla_fleet_api.exceptions import TeslaFleetError |
| 148 | + |
| 149 | +async def main(): |
| 150 | + async with aiohttp.ClientSession() as session: |
| 151 | + api = TeslaFleetApi( |
| 152 | + access_token="<access_token>", |
| 153 | + session=session, |
| 154 | + region="na", |
| 155 | + ) |
| 156 | + |
| 157 | + try: |
| 158 | + vehicle = VehicleSigned(api, "<vin>") |
| 159 | + data = await vehicle.wake_up() |
| 160 | + print(data) |
| 161 | + except TeslaFleetError as e: |
| 162 | + print(e) |
| 163 | + |
| 164 | +asyncio.run(main()) |
| 165 | +``` |
| 166 | + |
| 167 | +For more detailed examples, see [Fleet API with Signed Vehicle Commands](docs/fleet_api_signed_commands.md). |
| 168 | + |
| 169 | +### Bluetooth for Vehicles |
| 170 | + |
| 171 | +The `TeslaBluetooth` class provides methods to interact with Tesla vehicles using Bluetooth. Here's a basic example: |
| 172 | + |
| 173 | +```python |
| 174 | +import asyncio |
| 175 | +from bleak import BleakScanner |
| 176 | +from tesla_fleet_api import TeslaBluetooth |
| 177 | + |
| 178 | +async def main(): |
| 179 | + scanner = BleakScanner() |
| 180 | + devices = await scanner.discover() |
| 181 | + for device in devices: |
| 182 | + if TeslaBluetooth().valid_name(device.name): |
| 183 | + print(f"Found Tesla vehicle: {device.name}") |
| 184 | + |
| 185 | +asyncio.run(main()) |
| 186 | +``` |
| 187 | + |
| 188 | +For more detailed examples, see [Bluetooth for Vehicles](docs/bluetooth_vehicles.md). |
| 189 | + |
| 190 | +### Teslemetry |
| 191 | + |
| 192 | +The `Teslemetry` class provides methods to interact with the Teslemetry service. Here's a basic example: |
| 193 | + |
| 194 | +```python |
| 195 | +import asyncio |
| 196 | +import aiohttp |
| 197 | +from tesla_fleet_api import Teslemetry |
| 198 | +from tesla_fleet_api.exceptions import TeslaFleetError |
| 199 | + |
| 200 | +async def main(): |
| 201 | + async with aiohttp.ClientSession() as session: |
| 202 | + api = Teslemetry( |
| 203 | + access_token="<access_token>", |
| 204 | + session=session, |
| 205 | + ) |
| 206 | + |
| 207 | + try: |
| 208 | + data = await api.vehicles.list() |
| 209 | + print(data) |
| 210 | + except TeslaFleetError as e: |
| 211 | + print(e) |
| 212 | + |
| 213 | +asyncio.run(main()) |
| 214 | +``` |
| 215 | + |
| 216 | +For more detailed examples, see [Teslemetry](docs/teslemetry.md). |
| 217 | + |
| 218 | +### Tessie |
| 219 | + |
| 220 | +The `Tessie` class provides methods to interact with the Tessie service. Here's a basic example: |
| 221 | + |
| 222 | +```python |
| 223 | +import asyncio |
| 224 | +import aiohttp |
| 225 | +from tesla_fleet_api import Tessie |
| 226 | +from tesla_fleet_api.exceptions import TeslaFleetError |
| 227 | + |
| 228 | +async def main(): |
| 229 | + async with aiohttp.ClientSession() as session: |
| 230 | + api = Tessie( |
| 231 | + access_token="<access_token>", |
| 232 | + session=session, |
| 233 | + ) |
| 234 | + |
| 235 | + try: |
| 236 | + data = await api.vehicles.list() |
| 237 | + print(data) |
| 238 | + except TeslaFleetError as e: |
| 239 | + print(e) |
| 240 | + |
| 241 | +asyncio.run(main()) |
| 242 | +``` |
| 243 | + |
| 244 | +For more detailed examples, see [Tessie](docs/tessie.md). |
0 commit comments