Skip to main content

py-ppc-smgw

Async Python client for PPC Smart Meter Gateways (BSI TR-03109 / German Smart Meter Gateway, PPC vendor implementation).

Talks to the consumer-facing HAN-API of a PPC SMGW: Digest authentication, meter readings, firmware versions, historic export, reboot.

Status: alpha. Used as the upstream client for the ha-ppc-smgw Home Assistant integration. API surface is stable for the implemented methods, but not yet 1.0.

Installation

pip install py-ppc-smgw

Or with uv:

uv add py-ppc-smgw

Requires Python 3.13+.

Quick start

import asyncio
import logging

import httpx

from py_ppc_smgw import PPCSMGWClient


async def main() -> None:
    logger = logging.getLogger("py-ppc-smgw")

    async with httpx.AsyncClient(verify=False) as http:
        async with PPCSMGWClient(
            host="https://192.0.2.1",
            username="user",
            password="secret",
            httpx_client=http,
            logger=logger,
        ) as client:
            # Firmware versions
            for fw in await client.get_firmware_versions():
                print(f"{fw.component}: {fw.version}")

            # Meter readings (current values)
            meters = await client.get_meters()
            readings = await client.get_meter_reading(meters[0])
            for obis, reading in readings.items():
                print(f"{obis}: {reading.value} @ {reading.timestamp}")


asyncio.run(main())

The client is an async context manager — __aenter__ calls login() and __aexit__ calls logout(). The PPC SMGW only allows a single concurrent session per user, so always logging out is important.

Implemented API surface

Method Purpose
login() / logout() Session lifecycle (also handled by async with)
get_meters() List installed meters
get_meter_reading(meter) Current OBIS readings for a meter
export_meter_values(meter, from, to) Historic interval values
get_firmware_versions() swversions action
selftest() / reboot() Reboot the gateway via self-test

Stubbed (raise NotImplementedError):

  • get_tariff_profiles() — tariffform endpoint, planned
  • export_log_data(from, to) — log export, planned

Notes on gateway behaviour

  • Digest authentication with a fresh nonce per session. Stale nonces cached across HA-style 15-minute polls cause silent 200-but-empty responses on PPC firmware — the client always creates a fresh httpx.DigestAuth on every login().
  • Timestamps are local time, not UTC. The gateway returns naive datetimes in its own local zone. The library does not attach timezone info — consumers must localize at the boundary if needed.
  • Single session per user. Always log out (use async with and you get this for free).
  • Polling rate: 15-minute intervals are safe. Faster polling has been observed to crash the gateway (CGI process exhaustion, requires manual restart by the metering operator).

Development

git clone https://github.com/jannickfahlbusch/py-ppc-smgw
cd py-ppc-smgw
uv sync
uv run pytest
uv run ruff check py_ppc_smgw/ tests/
uv run mypy py_ppc_smgw/

License

Apache License 2.0 — see LICENSE.

Metadata

Release files for py-ppc-smgw 0.2.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 py-ppc-smgw 0.2.2
File Size Uploaded Provenance Actions
py_ppc_smgw-0.2.2.tar.gz 22.9 kB Without provenance Details for py_ppc_smgw-0.2.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for py-ppc-smgw 0.2.2
File Interpreter ABI Platform Actions
py_ppc_smgw-0.2.2-py3-none-any.whl Python 3 none any Details for py_ppc_smgw-0.2.2-py3-none-any.whl

Total release size: 38.2 kB

Release files / py_ppc_smgw-0.2.2.tar.gz

Download URL py_ppc_smgw-0.2.2.tar.gz
Size 22.9 kB
Tags Source
SHA-256 checksum
How to use checksums
02f1ac70eb17e5f4885280057339bddfb8f575c298c84b00fded54fcdc5e03b4
BLAKE2b-256 checksum
How to use checksums
ca22a0e696b507012b5cadd3f696d6bb173647d6b23b8ad287680fdf6c5f4029
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / py_ppc_smgw-0.2.2-py3-none-any.whl

Download URL py_ppc_smgw-0.2.2-py3-none-any.whl
Size 15.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1eabe5b3bfa9381514b05698d4f4f2f3ce4386399c1ce9cf58e92e05ca21295f
BLAKE2b-256 checksum
How to use checksums
b8e222b0c4563880445b1103c9537383860f3dac98fd5e8e8e16139a6ae42f1b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for py-ppc-smgw 0.2.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