This is an unofficial Python client for the Volvo Connected Vehicle API. It is based on the official API documentation.
Source: svrooij/py_volvo_connected
pip install volvo-connected
from kiota_http.httpx_request_adapter import HttpxRequestAdapter
from volvo_connected import (
StaticAccessTokenProvider,
# DynamicAccessTokenProvider,
VolvoAuthenticationProvider,
VolvoConnectedClient
)
# Create an access token provider using a static access token
access_token_provider = StaticAccessTokenProvider("YOUR_ACCESS_TOKEN")
# Or explore the DynamicAccessTokenProvider that allows you to auto refresh the token
# def access_token_function(url: str) -> str:
# # Implement your logic to get the access token using the URL
# return "your_dynamic_access_token"
# access_token_provider = DynamicAccessTokenProvider(access_token_function)
# Create an authentication provider using your VCC API key and the access token provider
auth_provider = VolvoAuthenticationProvider("YOUR_VCC_API_KEY", access_token_provider)
# Create a client with a request adapter that has the authentication provider
client = VolvoConnectedClient(HttpxRequestAdapter(auth_provider))
vehicles = await client.vehicles.get()
vehicle = await client.vehicles.by_vin("YV4952NA4F120DEMO").get()
fuel_resp = await client.vehicles.by_vin("YV4952NA4F120DEMO").fuel.get()
fuel_resp.data.fuel_amount.value
# or
fuel_resp.data.battery_charge_level.value
This client is genereted based on the (adjusted) OpenAPI specification. And everything is strong typed, so go ahead and explore the API.