Skip to main content

A Python client for EWIIs self-service portal

Project description

ewii-python

Unofficial client for Denmark’s EWII self-service portal

Query meters, daily kWh, contracts, and more from Python or expose them through a webserver.

📚 Public methods

Method Description
login() Interactive MitID login; copies cookies into your requests.Session.
get_consumption(from, to, meter_id) Array of daily kWh values.
get_individ_oplysninger() Personal/identity data.
get_aftaler() Active contracts.
get_info() Hidden JSON blob from /privat (addresses, meters, etc.).
_keep_alive() Lightweight ping to keep cookies fresh.

📦 Installation

pip install ewii
playwright install chromium

Script example

import json, requests
from datetime import date
from ewii import EwiiClient

client = EwiiClient()
client.login()

info = client.get_info()
meter = info["forbrugssteder"][0]["maalepunkter"][0]["maalepunktId"]

today = date.today(); first = today.replace(day=1)
print(client.get_consumption(first.isoformat(), today.isoformat(), meter))

🌐 Minimal FastAPI webserver

Create a python file called app.py

import json, threading, requests
from datetime import date
from fastapi import FastAPI, Query, HTTPException
from ewii import EwiiClient

KEEP_ALIVE_TIMER = 30
stop = threading.Event()
client = EwiiClient(requests.Session())

def keep_alive(evt):
    while not evt.wait(KEEP_ALIVE_TIMER):
        try:
            client._keep_alive()
            print("keep-alive")
        except Exception as e:
            print(e)

app = FastAPI(title="EWII API")

@app.on_event("startup")
def start():
    threading.Thread(target=keep_alive, args=(stop,), daemon=True).start()

@app.on_event("shutdown")
def done():
    stop.set()

@app.get("/consumption")
def consumption(meter_id: str, date_from: date, date_to: date):
    try:
        return client.get_consumption(date_from.isoformat(),
                                      date_to.isoformat(),
                                      meter_id)
    except Exception as e:
        raise HTTPException(502, str(e))

if __name__ == "__main__":
    import uvicorn

    uvicorn.run("app:app", host="127.0.0.1", port=8000, reload=True)

Open http://127.0.0.1:8000/docs for interactive Swagger UI. The background thread pings EWII every 5 minutes so the session stays alive.


Note This library is unofficial and not affiliated with EWII. Use responsibly and respect EWII’s terms of service.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ewii-0.2.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ewii-0.2.0-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file ewii-0.2.0.tar.gz.

File metadata

  • Download URL: ewii-0.2.0.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for ewii-0.2.0.tar.gz
Algorithm Hash digest
SHA256 4196c6d2412fee36bff88a7be4c02400c006347310ccd882446788a0edf62d7d
MD5 4151f63877f6bdd32e3d79bef60835d8
BLAKE2b-256 502b2d300fb72ab95354f6f8c9d2135f78dc39d7bd63b2ed788832cc6d1425e5

See more details on using hashes here.

File details

Details for the file ewii-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: ewii-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for ewii-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 438fa6da6ee17d6e3e4a5e25b7c4f019b03b3e76c47c915d822f48e5d0066392
MD5 6df201080d585a72f2037a115e6e05b1
BLAKE2b-256 06cfa5022bf44c73b5a5d710df3f26802a9fd2c8b4c1d0020083fa568d7d5c4b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page