# tdorssers/teslapy architecture

> Architecture diagram of the GitHub repository tdorssers/teslapy, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tdorssers/teslapy
- Repository: https://github.com/tdorssers/teslapy

## Overview

TeslaPy is a Python client for Tesla’s Owner API, with CLI, menu, and desktop GUI front ends. The main workflow is user authentication through Tesla SSO, token reuse/refresh, product discovery, and product-specific data retrieval or commands; vehicle telemetry can also arrive over a streaming connection. The library additionally supports battery and solar products, charging history/sites, vehicle metadata, and configurable authentication/cache behavior. The core excerpt is partial, so some internal links and product details are represented only where the README documents them; unsampled behavior is not inferred.

Main entry points: [`teslapy/__init__.py`](https://github.com/tdorssers/teslapy/blob/master/teslapy/__init__.py) (Tesla session), [`cli.py`](https://github.com/tdorssers/teslapy/blob/master/cli.py) (CLI), [`gui.py`](https://github.com/tdorssers/teslapy/blob/master/gui.py) (Desktop GUI), [`menu.py`](https://github.com/tdorssers/teslapy/blob/master/menu.py) (Console menu)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["User interfaces"]
  node_cli["CLI<br/>[cli.py]"]
  node_gui["Desktop GUI<br/>[gui.py]"]
  node_menu["Console menu<br/>[menu.py]"]
end

subgraph group_identity["Authentication and transport"]
  node_tesla["Tesla session<br/>[__init__.py]"]
  node_auth_flow["SSO and tokens<br/>[__init__.py]"]
  node_token_cache[("Token cache<br/>[__init__.py]")]
  node_http_transport["HTTP transport<br/>[__init__.py]"]
end

subgraph group_products["Tesla products"]
  node_endpoint_catalog["Endpoint catalog<br/>[endpoints.json]"]
  node_product_objects["Product objects<br/>[__init__.py]"]
  node_battery_solar["Battery and solar data<br/>[__init__.py]"]
end

subgraph group_vehicle["Vehicle capabilities"]
  node_vehicle_data["Vehicle data and status<br/>[__init__.py]"]
  node_vehicle_commands["Vehicle commands<br/>[__init__.py]"]
  node_vehicle_stream["Vehicle streaming<br/>[__init__.py]"]
  node_vehicle_metadata["Option and VIN data<br/>[__init__.py]"]
  node_option_catalog["Option descriptions<br/>[option_codes.json]"]
  node_charging_services["Charging and service<br/>[__init__.py]"]
end

node_cli_user(("CLI user"))
node_gui_user(("GUI user"))
node_menu_user(("Menu user"))
node_sso{{"Tesla SSO"}}
node_owner_api{{"Tesla Owner API"}}
node_stream_service{{"Vehicle streaming"}}

node_cli_user -->|"uses"| node_cli
node_gui_user -->|"uses"| node_gui
node_menu_user -->|"uses"| node_menu
node_cli -->|"creates session"| node_tesla
node_gui -->|"uses session"| node_tesla
node_menu -->|"creates session"| node_tesla
node_tesla -->|"manages auth"| node_auth_flow
node_auth_flow -->|"requests tokens"| node_sso
node_auth_flow -->|"loads and saves"| node_token_cache
node_tesla -->|"sends requests"| node_http_transport
node_http_transport -->|"calls API"| node_owner_api
node_tesla -->|"loads endpoints"| node_endpoint_catalog
node_tesla -->|"discovers products"| node_product_objects
node_product_objects -->|"provides vehicle methods"| node_vehicle_data
node_product_objects -->|"provides product methods"| node_battery_solar
node_vehicle_data -->|"requests vehicle data"| node_owner_api
node_vehicle_commands -->|"sends commands"| node_owner_api
node_vehicle_stream -->|"subscribes telemetry"| node_stream_service
node_vehicle_stream -->|"updates vehicle"| node_vehicle_data
node_vehicle_metadata -->|"looks up codes"| node_option_catalog
node_charging_services -->|"requests details"| node_owner_api
node_cli -->|"invokes commands"| node_vehicle_commands
node_menu -->|"invokes commands"| node_vehicle_commands
node_gui -->|"refreshes dashboard"| node_vehicle_data

click node_cli "https://github.com/tdorssers/teslapy/blob/master/cli.py"
click node_gui "https://github.com/tdorssers/teslapy/blob/master/gui.py"
click node_menu "https://github.com/tdorssers/teslapy/blob/master/menu.py"
click node_tesla "https://github.com/tdorssers/teslapy/blob/master/teslapy/__init__.py"
click node_auth_flow "https://github.com/tdorssers/teslapy/blob/master/teslapy/__init__.py"
click node_token_cache "https://github.com/tdorssers/teslapy/blob/master/teslapy/__init__.py"
click node_http_transport "https://github.com/tdorssers/teslapy/blob/master/teslapy/__init__.py"
click node_endpoint_catalog "https://github.com/tdorssers/teslapy/blob/master/teslapy/endpoints.json"
click node_product_objects "https://github.com/tdorssers/teslapy/blob/master/teslapy/__init__.py"
click node_vehicle_data "https://github.com/tdorssers/teslapy/blob/master/teslapy/__init__.py"
click node_vehicle_commands "https://github.com/tdorssers/teslapy/blob/master/teslapy/__init__.py"
click node_vehicle_stream "https://github.com/tdorssers/teslapy/blob/master/teslapy/__init__.py"
click node_vehicle_metadata "https://github.com/tdorssers/teslapy/blob/master/teslapy/__init__.py"
click node_option_catalog "https://github.com/tdorssers/teslapy/blob/master/teslapy/option_codes.json"
click node_battery_solar "https://github.com/tdorssers/teslapy/blob/master/teslapy/__init__.py"
click node_charging_services "https://github.com/tdorssers/teslapy/blob/master/teslapy/__init__.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_gui,node_menu,node_cli_user,node_gui_user,node_menu_user toneBlue
class node_tesla,node_auth_flow,node_token_cache,node_http_transport toneAmber
class node_endpoint_catalog,node_product_objects,node_battery_solar,node_owner_api toneMint
class node_vehicle_data,node_vehicle_commands,node_vehicle_stream,node_vehicle_metadata,node_option_catalog,node_charging_services toneRose
class node_sso,node_stream_service toneIndigo
```

## Components

### User interfaces

- [CLI](https://github.com/tdorssers/teslapy/blob/master/cli.py): `cli.py`
- [Desktop GUI](https://github.com/tdorssers/teslapy/blob/master/gui.py): `gui.py`
- [Console menu](https://github.com/tdorssers/teslapy/blob/master/menu.py): `menu.py`

### Authentication and transport

- [Tesla session](https://github.com/tdorssers/teslapy/blob/master/teslapy/__init__.py): `teslapy/__init__.py`
- [SSO and tokens](https://github.com/tdorssers/teslapy/blob/master/teslapy/__init__.py): `teslapy/__init__.py`
- [Token cache](https://github.com/tdorssers/teslapy/blob/master/teslapy/__init__.py): `teslapy/__init__.py`
- [HTTP transport](https://github.com/tdorssers/teslapy/blob/master/teslapy/__init__.py): `teslapy/__init__.py`

### Tesla products

- [Endpoint catalog](https://github.com/tdorssers/teslapy/blob/master/teslapy/endpoints.json): `teslapy/endpoints.json`
- [Product objects](https://github.com/tdorssers/teslapy/blob/master/teslapy/__init__.py): `teslapy/__init__.py`
- [Battery and solar data](https://github.com/tdorssers/teslapy/blob/master/teslapy/__init__.py): `teslapy/__init__.py`

### Vehicle capabilities

- [Vehicle data and status](https://github.com/tdorssers/teslapy/blob/master/teslapy/__init__.py): `teslapy/__init__.py`
- [Vehicle commands](https://github.com/tdorssers/teslapy/blob/master/teslapy/__init__.py): `teslapy/__init__.py`
- [Vehicle streaming](https://github.com/tdorssers/teslapy/blob/master/teslapy/__init__.py): `teslapy/__init__.py`
- [Option and VIN data](https://github.com/tdorssers/teslapy/blob/master/teslapy/__init__.py): `teslapy/__init__.py`
- [Option descriptions](https://github.com/tdorssers/teslapy/blob/master/teslapy/option_codes.json): `teslapy/option_codes.json`
- [Charging and service](https://github.com/tdorssers/teslapy/blob/master/teslapy/__init__.py): `teslapy/__init__.py`

### Other components

- **CLI user**
- **GUI user**
- **Menu user**
- **Tesla SSO**
- **Tesla Owner API**
- **Vehicle streaming**

## Connections

- CLI user → CLI: uses (evidence: `cli.py`)
- GUI user → Desktop GUI: uses (evidence: `gui.py`)
- Menu user → Console menu: uses (evidence: `menu.py`)
- CLI → Tesla session: creates session (evidence: `cli.py`)
- Desktop GUI → Tesla session: uses session (evidence: `gui.py`)
- Console menu → Tesla session: creates session (evidence: `menu.py`)
- Tesla session → SSO and tokens: manages auth (evidence: `teslapy/__init__.py`)
- SSO and tokens → Tesla SSO: requests tokens (evidence: `README.md`)
- SSO and tokens → Token cache: loads and saves (evidence: `teslapy/__init__.py`)
- Tesla session → HTTP transport: sends requests (evidence: `teslapy/__init__.py`)
- HTTP transport → Tesla Owner API: calls API (evidence: `README.md`)
- Tesla session → Endpoint catalog: loads endpoints (evidence: `teslapy/__init__.py`)
- Tesla session → Product objects: discovers products (evidence: `cli.py`)
- Product objects → Vehicle data and status: provides vehicle methods (evidence: `README.md`)
- Product objects → Battery and solar data: provides product methods (evidence: `cli.py`)
- Vehicle data and status → Tesla Owner API: requests vehicle data (evidence: `README.md`)
- Vehicle commands → Tesla Owner API: sends commands (evidence: `README.md`)
- Vehicle streaming → Vehicle streaming: subscribes telemetry (evidence: `teslapy/__init__.py`)
- Vehicle streaming → Vehicle data and status: updates vehicle (evidence: `README.md`)
- Option and VIN data → Option descriptions: looks up codes (evidence: `teslapy/__init__.py`)
- Charging and service → Tesla Owner API: requests details (evidence: `README.md`)
- CLI → Vehicle commands: invokes commands (evidence: `cli.py`)
- Console menu → Vehicle commands: invokes commands (evidence: `menu.py`)
- Desktop GUI → Vehicle data and status: refreshes dashboard (evidence: `gui.py`)
