Skip to main content

PSA Connected Car API Client

API client for PSA group connected car service.

This is a rework of the wonderful PSA Car Controller by @flobz.

The goal is to extract the core functionality and provide it as a library to be used by systems like Home Assistant directly, without the need to run a separate server.

It builds upon some great libraries:

  • httpx for the asynchronous REST API requests
  • authlib to handle the Oauth2 authentication
  • msgspec for the decoding of the API response into python classes
  • pyaxmlparser, a lighter alternative to androguard, to get the needed information from the PSA android app

Installation

pip install psa-connected-car-client

Usage

A basic usage of the library can be found at tests/demo_cli.py.

Simple version

You can create the PSAClient using the create_psa_client function.

from psa_ccc import create_psa_client


async def main():
    client = await create_psa_client(brand, country_code, email, password)

The arguments are self-explanatory, but just in case:

  • brand is the car brand; possible values are:
    • Peugeot
    • Citroen
    • DS
    • Opel
    • Vauxhall
  • country_code is your 2 letter uppercase country code
  • email is the address you used to register to the "MyBrand" app
  • password is - you guessed it - the password for the app

Behind the scenes, this function will download the APK of the mobile app, extract the data needed to establish a connection to the PSA servers and save it in a config file. Subsequent runs of the function will read from that config file, if it exists.

You're now ready to use the client to talk to the PSA connected car service!

    user = await client.get_user()
    print("User:", user)
    vehicles = await client.get_vehicles()
    print("Vehicles:", vehicles)
    vehicle_id = vehicles[0].id
    vehicle = await client.get_vehicle(vehicle_id)
    print("First vehicle:", vehicle)
    alerts = await client.get_vehicle_alerts(vehicle_id)
    print("Vehicle alerts:", alerts)
    status = await client.get_vehicle_status(vehicle_id)
    print("Vehicle status:", status)
    maintenance = await client.get_vehicle_maintenance(vehicle_id)
    print("Vehicle maintenance:", maintenance)
    print(
        "Vehicle position:",
        status.last_position.geometry.coordinates,
        "last updated at",
        status.last_position.properties.updated_at,
    )

Customizable storage

the create_psa_client function accepts two optional parameters for choosing where to store the configuration and the auth tokens:

  • cache_storage accepts any implementation of the CacheStorage protocol. The library comes with the SimpleCacheStorage class that stores the files inside the given directory. This is the storage used in the simple version above, and uses the current working directory as storage.
  • token_storage accepts any implementation of the TokenStorage protocol. Again, the library has a MemoryTokenStorage class that keeps the token in memory (it is never written to disk). This is the default token storage for the simple version above.
from pathlib import Path
from psa_ccc import SimpleCacheStorage
from psa_ccc import MemoryTokenStorage
from psa_ccc import create_psa_client


async def main():
    storage = SimpleCacheStorage(Path(__file__).parent)
    token_storage = MemoryTokenStorage()
    client = await create_psa_client(
        brand, country_code, email, password, storage, token_storage
    )
    # do whatever you want with client...

Metadata

Release files for psa-connected-car-client 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for psa-connected-car-client 0.1.2
File Size Uploaded Provenance Actions
psa_connected_car_client-0.1.2.tar.gz 14.5 kB Without provenance Details for psa_connected_car_client-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for psa-connected-car-client 0.1.2
File Interpreter ABI Platform Actions
psa_connected_car_client-0.1.2-py3-none-any.whl Python 3 none any Details for psa_connected_car_client-0.1.2-py3-none-any.whl

Total release size: 29.8 kB

Release files / psa_connected_car_client-0.1.2.tar.gz

Download URL psa_connected_car_client-0.1.2.tar.gz
Size 14.5 kB
Tags Source
SHA-256 checksum
How to use checksums
1bae1f4a3cfe779788740ccd3987f8d8595d312e5178a4770b2219e70428901e
BLAKE2b-256 checksum
How to use checksums
21e79f17f18aac05029395bb4e36c0487dda6a8c47e2d83104d744086af59158
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.10.12 Linux/6.2.0-1015-azure

Release files / psa_connected_car_client-0.1.2-py3-none-any.whl

Download URL psa_connected_car_client-0.1.2-py3-none-any.whl
Size 15.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7d43d36b8efcc2a54c213a9f579ddb8326e5108d3c1a63c54f1cce4b0214a96e
BLAKE2b-256 checksum
How to use checksums
83dcda6071a37312d5728d51270380dc0ba883581234b6a35285f1674c95cd02
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.10.12 Linux/6.2.0-1015-azure

Security for psa-connected-car-client 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page