or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

authentication.mdenergy-products.mdindex.mdutilities.mdvehicle-control.md
tile.json

tessl/pypi-teslapy

A Python module to use the Tesla Motors Owner API for monitoring and controlling Tesla vehicles, Powerwall batteries, and solar panels remotely

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/teslapy@2.9.x

To install, run

npx @tessl/cli install tessl/pypi-teslapy@2.9.0

index.mddocs/

TeslaPy

A Python implementation based on unofficial documentation of the client side interface to the Tesla Motors Owner API, which provides functionality to monitor and control Tesla products remotely including vehicles, Powerwall batteries, and solar panels.

Package Information

  • Package Name: TeslaPy
  • Language: Python
  • Installation: pip install teslapy 'urllib3<2'

Core Imports

import teslapy

Basic Usage

import teslapy

# Create Tesla session with your email
with teslapy.Tesla('elon@tesla.com') as tesla:
    # Get list of vehicles
    vehicles = tesla.vehicle_list()
    
    # Wake up the first vehicle
    vehicles[0].sync_wake_up()
    
    # Send a command (open front trunk)
    vehicles[0].command('ACTUATE_TRUNK', which_trunk='front')
    
    # Get vehicle data
    vehicles[0].get_vehicle_data()
    print(vehicles[0]['vehicle_state']['car_version'])

Architecture

TeslaPy follows a hierarchical object model that mirrors Tesla's product ecosystem:

  • Tesla Session: Main authentication and API session manager extending OAuth2Session
  • Vehicle Objects: Individual Tesla vehicles with control and monitoring capabilities
  • Product Objects: Base class for energy products (Powerwall, solar panels)
  • Battery Objects: Powerwall energy storage systems extending Product
  • SolarPanel Objects: Solar panel installations extending Product

The library implements Tesla's OAuth 2 Single Sign-On service with automatic token refresh, provides both synchronous API calls and streaming capabilities for real-time data, and includes comprehensive error handling with custom exception classes.

Capabilities

Authentication and Session Management

Core authentication functionality using Tesla's OAuth 2 SSO service with support for multiple authentication methods, token caching, and automatic refresh capabilities.

class Tesla(OAuth2Session):
    def __init__(self, email, verify=True, proxy=None, retry=0, timeout=10, 
                 user_agent=None, authenticator=None, cache_file='cache.json', 
                 cache_loader=None, cache_dumper=None, sso_base_url=None, 
                 code_verifier=None, app_user_agent=None, **kwargs): ...
    
    def fetch_token(self, token_url='oauth2/v3/token', **kwargs): ...
    def refresh_token(self, token_url='oauth2/v3/token', **kwargs): ...
    def logout(self, sign_out=False): ...

Authentication

Vehicle Control and Monitoring

Comprehensive vehicle control functionality including wake-up, status monitoring, climate control, charging management, location tracking, and command execution.

class Vehicle(JsonDict):
    def sync_wake_up(self, timeout=60, interval=2, backoff=1.15): ...
    def get_vehicle_data(self, endpoints='location_data;charge_state;climate_state;vehicle_state;gui_settings;vehicle_config'): ...
    def command(self, name, **kwargs): ...
    def stream(self, callback=None, retry=0, indefinitely=False, **kwargs): ...

Vehicle Control

Energy Product Management

Management functionality for Tesla energy products including Powerwall batteries and solar panel installations with status monitoring, configuration, and control capabilities.

class Battery(Product):
    def set_operation(self, mode): ...
    def set_backup_reserve_percent(self, percent): ...
    def get_tariff(self): ...
    def set_tariff(self, tariff_data): ...

class SolarPanel(Product):
    def get_site_data(self): ...

Energy Products

Data Processing and Utilities

Utility functions for data processing, unit conversion, VIN decoding, option code lookup, and error handling with custom exception classes.

class JsonDict(dict):
    def __str__(self): ...

class VehicleError(Exception): ...
class ProductError(Exception): ...

def decode_vin(self): ...
def decode_option(cls, code): ...

Utilities

Types

class Tesla(OAuth2Session):
    """Main session manager for Tesla Motors Owner API"""

class Vehicle(JsonDict):
    """Vehicle class with dictionary access and API request support"""

class Product(JsonDict):
    """Base product class for energy products"""

class Battery(Product):
    """Powerwall battery class"""

class SolarPanel(Product):
    """Solar panel class"""

class JsonDict(dict):
    """Pretty printing dictionary with JSON string representation"""

class VehicleError(Exception):
    """Vehicle-specific exception class"""

class ProductError(Exception):
    """Product-specific exception class"""