Async Python client for the BMW CarData customer API (REST + MQTT streaming).
Project description
bmw_cardata - BMW CarData Python Library
Async Python client for the BMW CarData customer API (REST) and the customer MQTT streaming feed.
Authentication (OAuth 2.0 Device Code Flow with PKCE)
import asyncio
from bmw_cardata import DeviceCodeFlowClient
async def main() -> None:
async with DeviceCodeFlowClient(client_id="<your-client-id>") as auth:
device = await auth.request_device_code()
print(f"Open {device.verification_uri} and enter code {device.user_code}")
token = await auth.poll_for_token(device.device_code, interval=device.interval)
print("access_token:", token.access_token)
print("id_token:", token.id_token)
print("gcid:", token.gcid)
asyncio.run(main())
REST client
import asyncio
from bmw_cardata import CarDataClient
from bmw_cardata.models import CreateContainerRequest
async def main() -> None:
async with CarDataClient(access_token="<bearer-access-token>") as client:
containers = await client.list_containers()
for c in containers.containers:
print(c.container_id, c.name, c.state)
new = await client.create_container(
CreateContainerRequest(
name="my-container",
purpose="example",
technical_descriptors=["vehicle.powertrain.electric.battery.stateOfCharge"],
)
)
data = await client.get_telematic_data("WBA...", container_id=new.container_id or "")
for key, entry in data.telematic_data.items():
print(key, entry.value, entry.unit, entry.timestamp)
asyncio.run(main())
You can also pass an async callable that returns a fresh token (handy for refresh flows):
async def token_provider() -> str:
return await refresh_if_needed()
client = CarDataClient(access_token=token_provider)
Streaming (MQTT)
The customer MQTT broker authenticates with the user's gcid as username and
the OAuth id_token (issued with the openid scope) as password.
import asyncio
from bmw_cardata import StreamingClient
async def main() -> None:
async with StreamingClient(gcid="<gcid>", id_token="<id-token>") as stream:
async for message in stream.stream(): # all VINs of this gcid
print(message.vin, message.data)
asyncio.run(main())
To subscribe to a single VIN:
async for message in stream.stream(vin="WBA..."):
...
Endpoints covered
REST (CarDataClient):
list_containers,create_container,get_container,delete_containerget_mappingsget_basic_data(vin)get_telematic_data(vin, container_id)get_vehicle_image(vin)→ raw bytesget_smart_maintenance_tyre_diagnosis(vin)get_charging_history(vin, from_, to, next_token=...)get_location_based_charging_settings(vin, next_token=...)
Streaming (StreamingClient):
stream(vin=None)— async iterator ofStreamingMessage
Development
pip install -e .[dev]
ruff format src
ruff check src
ty check src
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bmw_cardata-0.1.0a0.tar.gz.
File metadata
- Download URL: bmw_cardata-0.1.0a0.tar.gz
- Upload date:
- Size: 22.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cb8db6d1ec201c59eddd217c32cb8fd85de2e28f5b5383e0b4d5ca0b83afc96a
|
|
| MD5 |
1754cae3097366c61f73779cfe105c53
|
|
| BLAKE2b-256 |
ebbadb28a62a4578ea3cbfafcae8e753d0c952058d1188606edb4792bd639a5e
|
Provenance
The following attestation bundles were made for bmw_cardata-0.1.0a0.tar.gz:
Publisher:
pypi.yaml on zweckj/bmw-cardata
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bmw_cardata-0.1.0a0.tar.gz -
Subject digest:
cb8db6d1ec201c59eddd217c32cb8fd85de2e28f5b5383e0b4d5ca0b83afc96a - Sigstore transparency entry: 1691922081
- Sigstore integration time:
-
Permalink:
zweckj/bmw-cardata@2fa5a0c28e4443245a273ac898d588aba96ed58d -
Branch / Tag:
refs/tags/v0.1.0a1 - Owner: https://github.com/zweckj
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yaml@2fa5a0c28e4443245a273ac898d588aba96ed58d -
Trigger Event:
release
-
Statement type:
File details
Details for the file bmw_cardata-0.1.0a0-py3-none-any.whl.
File metadata
- Download URL: bmw_cardata-0.1.0a0-py3-none-any.whl
- Upload date:
- Size: 21.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aba5e2bd4c799a0bd83ab410c8d775f30062cefc9ec243695369c9d2ba65bb33
|
|
| MD5 |
ebe86d045c5a3a40b951450cfac84e34
|
|
| BLAKE2b-256 |
aa809be2c797d5473b358042bf4d61cc207d9bd01230b382ae2d1e78f5dc351a
|
Provenance
The following attestation bundles were made for bmw_cardata-0.1.0a0-py3-none-any.whl:
Publisher:
pypi.yaml on zweckj/bmw-cardata
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bmw_cardata-0.1.0a0-py3-none-any.whl -
Subject digest:
aba5e2bd4c799a0bd83ab410c8d775f30062cefc9ec243695369c9d2ba65bb33 - Sigstore transparency entry: 1691922419
- Sigstore integration time:
-
Permalink:
zweckj/bmw-cardata@2fa5a0c28e4443245a273ac898d588aba96ed58d -
Branch / Tag:
refs/tags/v0.1.0a1 - Owner: https://github.com/zweckj
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yaml@2fa5a0c28e4443245a273ac898d588aba96ed58d -
Trigger Event:
release
-
Statement type: