Async/sync Python client for the 24.energa.pl self-care portal
Project description
energa-api
Python client library for the 24.energa.pl self-care portal. Reverse-engineered from browser traffic. Supports both async and sync usage.
Features
- Authentication via OIDC Authorization Code + PKCE (Keycloak)
- Automatic token refresh
- List clients and accounts
- Fetch account balance
- List invoices (with date range and pagination)
- Download invoice PDFs
Installation
From PyPI
pip install energa24-api
From source (with uv)
git clone https://github.com/vincentto13/energa24-api
cd energa-api
uv sync
Configuration
Copy .env.example and fill in your credentials:
cp .env.example .env
# edit .env
Usage
Async
from energa import EnergaClient
async with EnergaClient("user@example.com", "password") as client:
for account in client.accounts:
balance = await client.get_balance(account.account_number)
print(balance.balance, "PLN")
invoices = await client.get_invoices(account.account_number)
for inv in invoices:
print(inv.invoice_number, inv.amount, "PLN")
# Download a PDF
pdf = await client.download_invoice(account.account_number, inv.dms_id)
Sync
from energa import EnergaClientSync
with EnergaClientSync("user@example.com", "password") as client:
balance = client.get_balance(account_number)
invoices = client.get_invoices(account_number)
pdf = client.download_invoice(account_number, dms_id)
Development
MCP server — local setup with Claude Code
1. Install the MCP extra
uv sync --extra mcp
2. Export your credentials
export ENERGA_USERNAME=you@example.com
export ENERGA_PASSWORD=your-password
Or persist them in ~/.bashrc / ~/.zshrc so they're always available.
3. Verify the server starts
uv run python -m energa.mcp_server
The process should start and wait for MCP input on stdin (no output is normal — that's correct stdio behaviour). Press Ctrl+C to stop.
4. Connect Claude Code
The repo includes a .mcp.json that points Claude Code at the server automatically.
Open Claude Code from this project directory — it will pick up .mcp.json and prompt you to approve the server on first use.
Check the connection inside a Claude Code session:
/mcp
You should see energa listed as connected with 4 tools.
Running the smoke test (live API)
ENERGA_USERNAME=you@example.com ENERGA_PASSWORD=secret uv run scripts/smoke_test.py
Or with a .env file:
uv run --env-file .env scripts/smoke_test.py
Running the test suite
uv run --group dev pytest
MCP Server
The library ships an MCP server that exposes your Energa account as tools for Claude and other MCP-compatible AI assistants.
Install
pip install energa24-api[mcp]
Available tools
| Tool | Description |
|---|---|
list_accounts |
List all accounts and meters (cached, no network request) |
get_balance |
Get current balance for an account |
get_invoices |
List invoices with optional date range and pagination |
download_invoice |
Download a PDF invoice — saves to a temp file and returns the path |
Run standalone
ENERGA_USERNAME=you@example.com ENERGA_PASSWORD=secret uv run python -m energa.mcp_server
Claude Desktop configuration
Add to ~/config/claude/claude_desktop_config.json:
{
"mcpServers": {
"energa": {
"command": "uv",
"args": ["run", "--project", "/path/to/energa-api", "python", "-m", "energa.mcp_server"],
"env": {
"ENERGA_USERNAME": "you@example.com",
"ENERGA_PASSWORD": "your-password"
}
}
}
}
Note: The access token expires after 5 minutes and is refreshed automatically. The refresh token expires after 30 minutes of inactivity — if that happens, restart the server.
Example prompts
Ask Claude naturally:
- "What's my Energa balance?"
- "Show me my last 3 invoices"
- "List all my electricity accounts and their meter addresses"
- "Download the latest invoice for account 1234567890"
- "Do I have any unpaid invoices?"
Acknowledgements
This library was built with the help of Claude (Anthropic's AI assistant). Claude assisted with reverse-engineering the authentication flow from browser HAR captures, designing the library architecture, implementing the async/sync client, and writing the test suite.
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 energa24_api-0.2.0.tar.gz.
File metadata
- Download URL: energa24_api-0.2.0.tar.gz
- Upload date:
- Size: 95.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fc2fb240c0835e807d8cd3c879c7c80dcb3fe9d65ba7b840fc12dfecd3f45c34
|
|
| MD5 |
08812caf5ef53aa07824a47b73f86d4b
|
|
| BLAKE2b-256 |
18056ca5009fcb14009b0d9e54f53216646b91bcfe3be82d141c6d76775065f6
|
Provenance
The following attestation bundles were made for energa24_api-0.2.0.tar.gz:
Publisher:
publish.yml on vincentto13/energa24-api
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
energa24_api-0.2.0.tar.gz -
Subject digest:
fc2fb240c0835e807d8cd3c879c7c80dcb3fe9d65ba7b840fc12dfecd3f45c34 - Sigstore transparency entry: 1181978006
- Sigstore integration time:
-
Permalink:
vincentto13/energa24-api@98b0007ae4ade46350e8803f404137b5057d0510 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/vincentto13
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@98b0007ae4ade46350e8803f404137b5057d0510 -
Trigger Event:
release
-
Statement type:
File details
Details for the file energa24_api-0.2.0-py3-none-any.whl.
File metadata
- Download URL: energa24_api-0.2.0-py3-none-any.whl
- Upload date:
- Size: 15.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4b1ff6524d51ac865e7c9749723646a7331ed0abe8ef33fcb2fc057f123f894d
|
|
| MD5 |
ca3d7b4932bed0140a84fd0e0e3811ca
|
|
| BLAKE2b-256 |
2253caffb65c4fa3dc0538ccbe5c61465bac19025ebf933e86ce7d2ce0c5fad6
|
Provenance
The following attestation bundles were made for energa24_api-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on vincentto13/energa24-api
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
energa24_api-0.2.0-py3-none-any.whl -
Subject digest:
4b1ff6524d51ac865e7c9749723646a7331ed0abe8ef33fcb2fc057f123f894d - Sigstore transparency entry: 1181978011
- Sigstore integration time:
-
Permalink:
vincentto13/energa24-api@98b0007ae4ade46350e8803f404137b5057d0510 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/vincentto13
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@98b0007ae4ade46350e8803f404137b5057d0510 -
Trigger Event:
release
-
Statement type: