Skip to main content

pychargefox

Async Python client for the Chargefox GraphQL API.

Install

pip install pychargefox

For local development, install the project into its virtual environment in editable mode:

python -m pip install --editable ".[dev]"

Example

import asyncio

from chargefox import Bounds, ChargefoxClient


async def main() -> None:
    async with ChargefoxClient() as client:
        stations = await client.get_charge_stations_by_bounds(
            Bounds(south=-32.5, west=115.0, north=-31.0, east=116.5)
        )

        for station in stations:
            print(station.name, station.status, station.online)
            for connector in station.connectors:
                plug_name = connector.plug.short_name if connector.plug else "Unknown"
                print(plug_name, connector.status)

                if connector.active_charge_session:
                    session = connector.active_charge_session
                    charge_rate_kw = (
                        session.charge_rate.value_kw if session.charge_rate else None
                    )
                    consumption_kwh = (
                        session.total_consumption / 1000
                        if session.total_consumption is not None
                        else None
                    )
                    print(session.current_state, charge_rate_kw, consumption_kwh)


asyncio.run(main())

The current public queries do not require authentication. A bearer token can still be supplied for endpoints that require one:

client = ChargefoxClient(bearer_token="YOUR_TOKEN")

Behaviour

  • get_locations_by_bounds() returns lightweight map summaries.
  • get_locations_with_details_by_bounds() returns hydrated locations with their stations, connectors, plugs, and active sessions.
  • get_charge_stations_by_bounds() collects station IDs from the lightweight summaries, then hydrates them through aliased root chargeStation(id) queries in batches of 10.
  • get_charge_stations(station_ids) exposes the same batching publicly. Callers can pass only the stations they need refreshed, such as stations that remain enabled in Home Assistant. Input IDs are deduplicated while preserving order.
  • Root station hydration returns rich station metadata, parent location details, pricing, idle fees, connectors, plugs, and active sessions. startMeterValue remains excluded from bulk polling because earlier session records caused HTTP 500 responses.
  • Batch hydration uses at most 5 concurrent requests by default. Successful aliases are retained from partial GraphQL responses, and failed aliases are retried individually. If a whole batch fails, its station IDs fall back to individual queries. If every requested station ultimately fails, the first error is raised.
  • HTTP 429 responses are retried three times by default. The client honors a numeric Retry-After header and otherwise uses 2/4/8-second exponential backoff.
  • Requests are paced through a client-wide gate at a minimum interval of 0.25 seconds. A 429 pauses all workers, preventing concurrent retries from extending the limit.
  • get_location(), get_charge_station(), and get_connector() support targeted polling.
  • Active-session consumption is returned by the API in Wh; divide it by 1000 for kWh.

The concurrency and batch limits can be configured with ChargefoxClient(max_concurrent_requests=5, station_batch_size=10, location_batch_size=10). The location batch size applies to get_locations_with_details_by_bounds(). Rate-limit behavior can be configured with ChargefoxClient(max_rate_limit_retries=3, rate_limit_retry_delay=2). Request pacing can be configured with ChargefoxClient(min_request_interval=0.5).

Development checks

python -m ruff format --check .
python -m ruff check .
python -m unittest discover -s tests -v
python -m coverage run -m unittest discover -s tests
python -m coverage report

Build a wheel into dist/ with:

python -m pip wheel . --no-deps --wheel-dir dist

Live integration test

Set CHARGEFOX_RUN_LIVE_TESTS=1, then run the normal test suite. The live tests use the public API without authentication and are skipped unless explicitly enabled.

py -m unittest discover -s tests

If you need to override the endpoint, set CHARGEFOX_GRAPHQL_URL as well.

The live tests cover lookup collections, lightweight map discovery, and resolving a full location and its stations from a map result. Connector status and active-session data are included with each full station and can be refreshed by polling the location, station, or connector methods.

Metadata

Release files for pychargefox 0.1.5

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

Source distribution (sdist)

Source distribution for pychargefox 0.1.5
File Size Uploaded Provenance Actions
pychargefox-0.1.5.tar.gz 15.7 kB Without provenance Details for pychargefox-0.1.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pychargefox 0.1.5
File Interpreter ABI Platform Actions
pychargefox-0.1.5-py3-none-any.whl Python 3 none any Details for pychargefox-0.1.5-py3-none-any.whl

Total release size: 28.6 kB

Release files / pychargefox-0.1.5.tar.gz

Download URL pychargefox-0.1.5.tar.gz
Size 15.7 kB
Tags Source
SHA-256 checksum
How to use checksums
c5f8cb815e487d5df0b013226d542db88998edc0c086aa45d288a6e8986a7f5f
BLAKE2b-256 checksum
How to use checksums
9a7e0bda152c5bdfd6b4e7ac923e1076b65ba329e6fd28dd5c7c57af79375eed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release files / pychargefox-0.1.5-py3-none-any.whl

Download URL pychargefox-0.1.5-py3-none-any.whl
Size 13.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4ce346296e5e5c4fd285fe4355ee188da63473bf1b1db1710daae38d2834cfc2
BLAKE2b-256 checksum
How to use checksums
a526fdfbbb43b36a4c814cda1e996d91459b6d972fe26210b5bc60a7be80f8c3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Security for pychargefox 0.1.5

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