Python library (tesla_fleet_api) providing async interfaces for Tesla Fleet API, Teslemetry, and Tessie services, plus BLE communication. Published to PyPI as tesla-fleet-api.
# Install dependencies
uv sync
# Type checking (strict mode)
uv run pyright tesla_fleet_api
# Linting
uv run ruff check tesla_fleet_api
uv run ruff format tesla_fleet_apiNo test suite exists in this repo.
- Tesla Fleet: https://developer.tesla.com/docs/fleet-api/endpoints/vehicle-endpoints
- Tessie: https://developer.tessie.com/llms.txt
- Teslemetry: http://api.teslemetry.com/openapi.yaml
Three API client classes all inherit from TeslaFleetApi:
Tesla (base - tesla/tesla.py)
└── TeslaFleetApi (tesla/fleet.py) - core HTTP client with _request(), access_token handling
├── TeslaFleetOAuth (tesla/oauth.py) - adds OAuth flow (login URL, token refresh)
├── Teslemetry (teslemetry/teslemetry.py) - fixed server, Teslemetry-specific endpoints
└── Tessie (tessie/tessie.py) - fixed server, Tessie-specific endpoints
Tesla base holds EC key management for signed commands. TeslaFleetApi provides the _request() method used by all submodules.
Vehicle commands have three implementations sharing the same method signatures, selected by how you create the vehicle:
Vehicle (vehicle/vehicle.py) - base with VIN and model detection
└── VehicleFleet (vehicle/fleet.py) - REST API commands (unsigned)
└── VehicleSigned (vehicle/signed.py) - signed command protocol via Fleet API
Commands (vehicle/commands.py) - protobuf-based signed command implementation (ABC)
└── VehicleSigned - multiple inheritance: Commands + VehicleFleet
└── VehicleBluetooth (vehicle/bluetooth.py) - BLE transport for signed commands
VehicleSigned uses multiple inheritance: Commands for signed command logic, VehicleFleet for data endpoints and fallback.
Vehicles (vehicle/vehicles.py) is a dict[str, Vehicle] with factory methods:
createFleet(vin)→VehicleFleetcreateSigned(vin)→VehicleSignedcreateBluetooth(vin)→VehicleBluetooth
Teslemetry/Tessie override Vehicles with their own vehicle classes (TeslemetryVehicle, TessieVehicle) extending VehicleFleet with service-specific commands (e.g., closure(), seat_heater() for Teslemetry; wake(), lock() for Tessie).
Each API client lazily attaches submodules in __init__ via class attributes on Tesla:
charging,energySites,user,partner,vehicles
Scope flags on TeslaFleetApi.__init__ control which submodules are instantiated.
exceptions.py maps HTTP status codes and error keys to specific exception classes. raise_for_status() parses responses and raises the appropriate exception. Signed command faults have separate hierarchies: TeslaFleetInformationFault, TeslaFleetMessageFault, SignedMessageInformationFault, WhitelistOperationStatus.
All exceptions inherit from TeslaFleetError(BaseException).
Generated protobuf files live in tesla/vehicle/proto/ and are excluded from ruff and pyright. Do not edit these directly.
- Type checking: pyright strict mode. Use
TYPE_CHECKINGguards for circular imports. - Linting: ruff (proto files excluded).
- Async: All API methods are
async. Usesaiohttpfor HTTP,aiofilesfor file I/O,bleakfor BLE. - Enums: Custom
StrEnum/IntEnuminconst.py(not stdlib).Regionis aLiteral["na", "eu", "cn"], not an enum. - Naming: camelCase for class instance attributes that mirror API structure (
energySites,createFleet). Snake_case for method names that are API endpoints.