Coder Social home page Coder Social logo

teslemetry / python-tesla-fleet-api Goto Github PK

View Code? Open in Web Editor NEW
8.0 4.0 1.0 259 KB

Python library for Tesla Fleet API and Teslemetry

Home Page: https://teslemetry.com/docs

License: Apache License 2.0

Python 100.00%
tesla tesla-api tesla-fleet-api teslamotors teslemetry library

python-tesla-fleet-api's Introduction

Tesla Fleet Api

Python library for Tesla Fleet API and Teslemetry.

Currently does not support the end to end encrypted telemetry or command API.

Based on Tesla Developer documentation.

TeslaFleetApi

This is the base class, however can also be used directly if you have a valid user access_token.

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.vehicle.list()
            print(data)
        except TeslaFleetError as e:
            print(e)

asyncio.run(main())

TeslaFleetOAuth

This extends TeslaFleetApi to support OAuth, and requires a client_id, and either a refresh_token or initial authentication code.

from tesla_fleet_api import TeslaFleetOAuth
from tesla_fleet_api.exceptions import TeslaFleetError
import json

async def main():
    with open("auth.json", "r") as f:
        auth = json.load(f)
    async with aiohttp.ClientSession() as session:
        api = TeslaFleetOAuth(
            session,
            client_id=<client_id>,
            access_token=auth["access_token"],
            refresh_token=auth["refresh_token"],
            expires=auth["expires"],
            region="na",
        )
        try:
            data = await api.vehicle.list()
            print(data)
        except TeslaFleetError as e:
            print(e)

    with open("auth.json", "w") as f:
        json.dump(
            {
                "access_token": api.access_token,
                "refresh_token": api.refresh_token,
                "expires": api.expires,
            },
            f,
        )

asyncio.run(main())

Teslemetry

This extends TeslaFleetApi to send requests through Teslemetry, which manages all aspects of Tesla OAuth. This class only requires an access_token from the Teslemetry console.

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.vehicle.list()
            print(data)
        except TeslaFleetError as e:
            print(e)

asyncio.run(main())

Tessie

This extends TeslaFleetApi to send requests through Tessie, which manages all aspects of Tesla OAuth. This class only requires an access_token from Tessie.

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.vehicle.list()
            print(data)
        except TeslaFleetError as e:
            print(e)

asyncio.run(main())

python-tesla-fleet-api's People

Contributors

bre77 avatar yaleman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

yaleman

python-tesla-fleet-api's Issues

Question about Status of Vehicle Command Implementation

Thanks for your library.

I note you've stated "Currently does not support the end to end encrypted telemetry or command API." I assume part of what you're referring to here is the end-to-end protobuf-based SDK for vehicle commands for which there is currently only an official implementation in Golang (https://github.com/teslamotors/vehicle-command).

I was just wondering if you are considering or working on creating a Python SDK for this so this Golang proxy is not necessary. I have done some work on this and wanted to see if my effort is wasted. Thanks in advance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.