pythehagueparking
Async client library for the Parkeren Den Haag API, designed for Home Assistant custom integrations but usable in any asyncio project.
Features
- Async-only HTTP calls via aiohttp
- Auth helper with automatic re-login on 401/403
- Typed dataclass models with parsed fields
- Caller-owned aiohttp session (no session management in the library)
- Caller-provided API base URL (use
DEFAULT_BASE_URLfor production)
Installation
python -m pip install pythehagueparking
Quick start
from aiohttp import ClientSession
from pythehagueparking import Auth, DEFAULT_BASE_URL, TheHagueParkingAPI
async def main() -> None:
async with ClientSession() as session:
auth = Auth(
session,
username="user",
password="pass",
base_url=DEFAULT_BASE_URL,
)
api = TheHagueParkingAPI(auth)
account = await api.async_get_account()
reservations = await api.async_list_reservations()
favorites = await api.async_list_favorites()
print(account, reservations, favorites)
API reference
API methods:
async_get_account() -> Account: Fetch account details.async_list_reservations() -> list[Reservation]: List reservations.async_create_reservation(name, license_plate, reservation_starts_at, reservation_ends_at) -> Reservation: Create a reservation (timestamps are ISO 8601Zstrings).async_set_reservation_end_time(reservation_id, *, end_time) -> Reservation: Update a reservation end time (ISO 8601Zstring).async_delete_reservation(reservation_id) -> None: Delete a reservation.async_list_favorites() -> list[Favorite]: List favorites.async_create_favorite(name, license_plate) -> Favorite: Create a favorite.async_update_favorite(favorite_id, name, license_plate) -> Favorite: Update a favorite.async_delete_favorite(favorite_id) -> None: Delete a favorite.
Example usage:
from datetime import UTC, datetime, timedelta
from aiohttp import ClientSession
from pythehagueparking import Auth, DEFAULT_BASE_URL, TheHagueParkingAPI
async with ClientSession() as session:
api = TheHagueParkingAPI(
Auth(session, "user", "pass", base_url=DEFAULT_BASE_URL)
)
starts_at = datetime.now(tz=UTC).replace(microsecond=0)
ends_at = (starts_at + timedelta(hours=2)).replace(microsecond=0)
starts_at_iso = starts_at.isoformat(timespec="seconds").replace("+00:00", "Z")
ends_at_iso = ends_at.isoformat(timespec="seconds").replace("+00:00", "Z")
extended_ends_at_iso = (
(ends_at + timedelta(hours=1))
.replace(microsecond=0)
.isoformat(timespec="seconds")
.replace("+00:00", "Z")
)
reservation = await api.async_create_reservation(
name="My Car",
license_plate="12-AB-34",
reservation_starts_at=starts_at_iso,
reservation_ends_at=ends_at_iso,
)
await api.async_set_reservation_end_time(
reservation.id,
end_time=extended_ends_at_iso,
)
await api.async_delete_reservation(reservation.id)
from pythehagueparking import __version__
print("pythehagueparking", __version__)
from aiohttp import ClientSession
from pythehagueparking import Auth, DEFAULT_BASE_URL, TheHagueParkingAPI
async with ClientSession() as session:
api = TheHagueParkingAPI(
Auth(session, "user", "pass", base_url=DEFAULT_BASE_URL)
)
favorites = await api.async_list_favorites()
if favorites:
favorite = favorites[0]
await api.async_update_favorite(
favorite.id,
name="My Car",
license_plate=favorite.license_plate,
)
from aiohttp import ClientSession
from pythehagueparking import Auth, DEFAULT_BASE_URL, RateLimitError, TheHagueParkingAPI
async with ClientSession() as session:
api = TheHagueParkingAPI(
Auth(session, "user", "pass", base_url=DEFAULT_BASE_URL)
)
try:
await api.async_list_reservations()
except RateLimitError as err:
print("Retry after:", err.retry_after)
API notes
- Start and end times are ISO 8601 UTC strings ending with
Z(seconds precision). - Naive timestamps (without
Z/offset) are treated as UTC. - Incoming timestamps are normalized to ISO 8601 UTC strings ending with
Z. - Provide
permit_media_type_idtoAuthto sendx-permit-media-type-idheaders when required.
Session ownership
- You always pass your own
aiohttp.ClientSession. - The library never creates or closes sessions.
Model fields and mapping
- Public methods return typed dataclasses with fields mapped from API payloads.
- Each model exposes parsed values instead of raw payload dictionaries.
Field mapping:
-
Account
id: intremaining_time: int(wasdebit_minutes)active_reservation_count: int(wasreservation_count)
-
Zone
id: intname: strstart_time: str(ISO 8601 UTC,Z)end_time: str(ISO 8601 UTC,Z)
-
Reservation
id: intlicense_plate: strname: strstart_time: str(ISO 8601 UTC,Z)end_time: str(ISO 8601 UTC,Z)
-
Favorite
id: intlicense_plate: strname: str
Compatibility notes
- Python 3.13.2+ is required, matching Home Assistant 2025.12.
- Async-only (
aiohttp); no synchronous wrapper is provided.
Error handling
AuthErrorfor authentication failures or expired sessionsParkingConnectionErrorfor network errors and timeoutsRateLimitErrorfor HTTP 429 responses (seeretry_after)ParseErrorfor unexpected response payloadsaiohttp.ClientResponseErrorfor HTTP status errors (raise_for_status)
Development
python -m pip install -e '.[test,dev]'
pytest
ruff check .
mypy
License
MIT License. See LICENSE and NOTICE.
Support
For questions or issues, open a GitHub issue: https://github.com/sir-Unknown/pythehagueparking/issues
Metadata
Release files for pythehagueparking 0.3.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pythehagueparking-0.3.3.tar.gz | 10.9 kB | With provenance | Details for pythehagueparking-0.3.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pythehagueparking-0.3.3-py3-none-any.whl | Python 3 | none | any | Details for pythehagueparking-0.3.3-py3-none-any.whl |
Total release size: 22.1 kB
Release files / pythehagueparking-0.3.3.tar.gz
| Download URL | pythehagueparking-0.3.3.tar.gz |
|---|---|
| Size | 10.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e8cdd01c3561779404c4427ebc36d8f564e14f349f1d596dd4e11e71895ca858
|
|
BLAKE2b-256 checksum How to use checksums |
c7e548b65a504b594e5ace8fea214aa91599821279c3e39d8a025c4aabd7e9ba
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 25, 2025.
Transparency logRelease files / pythehagueparking-0.3.3-py3-none-any.whl
| Download URL | pythehagueparking-0.3.3-py3-none-any.whl |
|---|---|
| Size | 11.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ac900f2be24def5f603e87394363de72f92099a13a05c99cd2349e04e9df9b48
|
|
BLAKE2b-256 checksum How to use checksums |
de1dda170b96e5a7ddd7c9ef9e7170a6890b728af66b27a610c1a530aac5010e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 25, 2025.
Transparency logSecurity for pythehagueparking 0.3.3
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for pythehagueparking-0.3.3.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 25, 2025.
Transparency logA 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.