Skip to main content

Fluvius Energy API

Python wrapper for the Fluvius Energy API v3 (ESCO - Energy Service Company API).

Installation

pip install fluvius-energy-api

Or with uv:

uv add fluvius-energy-api

Configuration

The client requires OAuth2 credentials for Azure AD authentication. Two authentication methods are supported:

  • Certificate-based (production): Uses certificate thumbprint + private key
  • Client secret (sandbox): Uses a simple client secret

Common Environment Variables

These are shared between production and sandbox:

Variable Description
FLUVIUS_SUBSCRIPTION_KEY Azure API Management subscription key
FLUVIUS_CLIENT_ID Azure AD application (client) ID
FLUVIUS_TENANT_ID Azure AD tenant ID
FLUVIUS_SCOPE OAuth2 scope (e.g., api://your-app-id/.default)

Production (Certificate-based auth)

Variable Description
FLUVIUS_CERTIFICATE_THUMBPRINT Certificate thumbprint (hex format)
FLUVIUS_PRIVATE_KEY RSA private key in PEM format
FLUVIUS_PRIVATE_KEY_PATH Alternative: path to private key file

Sandbox (Client secret auth)

Variable Description
FLUVIUS_SANDBOX_CLIENT_SECRET Client secret for sandbox

Note: For sandbox, common values (subscription_key, client_id, tenant_id, scope, data_access_contract_number) automatically fall back to FLUVIUS_* if not set with FLUVIUS_SANDBOX_* prefix.

Data Access Contract

Variable Description
FLUVIUS_DATA_ACCESS_CONTRACT_NUMBER Data access contract number (required, typically constant per service provider)

Private Key Formats

The private key can be provided in three ways:

  1. Inline PEM: Set FLUVIUS_PRIVATE_KEY with the full PEM content
  2. Base64-encoded: Set FLUVIUS_PRIVATE_KEY with the PEM content encoded as base64
  3. File path: Set FLUVIUS_PRIVATE_KEY_PATH to point to a .pem file

Usage

Production (Certificate auth)

from fluvius_energy_api import FluviusEnergyClient, Environment

# Credentials loaded from FLUVIUS_* environment variables
with FluviusEnergyClient(environment=Environment.PRODUCTION) as client:
    response = client.get_mandates()
    for mandate in response.data.mandates:
        print(f"EAN: {mandate.ean}, Status: {mandate.status}")

Sandbox (Client secret auth)

from fluvius_energy_api import FluviusEnergyClient, FluviusCredentials, Environment

# Load credentials - falls back to FLUVIUS_* for common values,
# uses FLUVIUS_SANDBOX_CLIENT_SECRET for auth
sandbox_credentials = FluviusCredentials.from_env(prefix="FLUVIUS_SANDBOX")

with FluviusEnergyClient(credentials=sandbox_credentials, environment=Environment.SANDBOX) as client:
    response = client.get_mandates()
    print(f"Found {len(response.data.mandates)} mandates in sandbox")

Explicit Credentials

from fluvius_energy_api import FluviusEnergyClient, FluviusCredentials, Environment

# Production with certificate
prod_credentials = FluviusCredentials(
    subscription_key="your-subscription-key",
    client_id="your-client-id",
    tenant_id="your-tenant-id",
    scope="api://your-scope/.default",
    certificate_thumbprint="YOUR_CERTIFICATE_THUMBPRINT",
    private_key="-----BEGIN RSA PRIVATE KEY-----\n...\n-----END RSA PRIVATE KEY-----",
)

# Sandbox with client secret
sandbox_credentials = FluviusCredentials(
    subscription_key="your-subscription-key",
    client_id="your-client-id",
    tenant_id="your-tenant-id",
    scope="api://your-scope/.default",
    client_secret="your-client-secret",
)

with FluviusEnergyClient(credentials=prod_credentials, environment=Environment.PRODUCTION) as client:
    mandates = client.get_mandates()

Create Client Session

Create a session for end-users to grant data access:

from fluvius_energy_api import (
    FluviusEnergyClient,
    ClientSessionDataService,
    DataServiceType,
    Environment,
)

with FluviusEnergyClient(environment=Environment.PRODUCTION) as client:
    response = client.create_client_session(
        data_access_contract_number="3599900040",
        reference_number="my-unique-reference",
        flow="B2B",
        data_services=[
            ClientSessionDataService(
                data_service_type=DataServiceType.VH_DAG,
                data_period_from="2024-01-01T00:00:00Z",
            ),
            ClientSessionDataService(
                data_service_type=DataServiceType.VH_KWARTIER_UUR,
                data_period_from="2024-01-01T00:00:00Z",
            ),
        ],
        number_of_eans=5,
    )

    if response.data.status == "success":
        # Build the consent URL for end-users
        consent_url = f"https://mijn.fluvius.be/verbruik/dienstverlener?id={response.data.short_url_identifier}"
        print(f"Consent URL: {consent_url}")
        print(f"Valid until: {response.data.valid_to}")

Get Mandates

Retrieve mandates with optional filters:

from fluvius_energy_api import (
    FluviusEnergyClient,
    EnergyType,
    MandateStatus,
    DataServiceType,
    Environment,
)

with FluviusEnergyClient(environment=Environment.PRODUCTION) as client:
    # Get all mandates
    response = client.get_mandates()

    # Get mandates with filters
    response = client.get_mandates(
        ean="541448800000004312",
        energy_type=EnergyType.ELECTRICITY,
        status=MandateStatus.APPROVED,
        data_service_types=[DataServiceType.VH_DAG, DataServiceType.VH_KWARTIER_UUR],
    )

    for mandate in response.data.mandates:
        print(f"EAN: {mandate.ean}")
        print(f"Status: {mandate.status}")
        print(f"Energy type: {mandate.energy_type}")
        print(f"Data service: {mandate.data_service_type}")

Get Energy Data

Retrieve energy consumption/production data:

from datetime import datetime
from fluvius_energy_api import FluviusEnergyClient, PeriodType, Environment

with FluviusEnergyClient(environment=Environment.PRODUCTION) as client:
    response = client.get_energy(
        ean="541448800000004312",
        period_type=PeriodType.READ_TIME,
        granularity="daily",
        from_date=datetime(2024, 1, 1),
        to_date=datetime(2024, 6, 1),
    )

    headpoint = response.data.headpoint
    print(f"EAN: {headpoint.ean}")
    print(f"Energy type: {headpoint.energy_type}")

Postman Collection

A hand-crafted Postman collection is included in the postman/ directory covering authentication, client sessions, mandates, and energy data endpoints.

To generate the environment files from your .env:

python postman/generate_postman_env.py

This creates two files (gitignored):

  • postman/fluvius-sandbox.postman_environment.json -- client-secret auth
  • postman/fluvius-production.postman_environment.json -- certificate / JWT auth

Import the collection (postman/fluvius-energy-api.postman_collection.json) and the appropriate environment into Postman. The collection's pre-request script acquires tokens automatically.

The production client assertion is valid for 1 hour. Re-run the script for a fresh one -- the JWT is printed to stdout so you can copy-paste it directly into your already-imported Postman environment without re-importing the file.

Environments

The client supports two environments:

Environment Base URL Auth Method
Environment.PRODUCTION https://apihub.fluvius.be/esco-live/v3 Certificate
Environment.SANDBOX https://apihub.fluvius.be/esco-sbx/v3 Client secret
from fluvius_energy_api import FluviusEnergyClient, Environment

# Production
client = FluviusEnergyClient(environment=Environment.PRODUCTION)

# Sandbox
client = FluviusEnergyClient(environment=Environment.SANDBOX)

Error Handling

The client raises specific exceptions for different error scenarios:

from fluvius_energy_api import (
    FluviusEnergyClient,
    FluviusAPIError,
    AuthenticationError,
    ForbiddenError,
    NotFoundError,
    ValidationError,
    ServerError,
    ServiceUnavailableError,
    ConfigurationError,
    Environment,
)

try:
    with FluviusEnergyClient(environment=Environment.PRODUCTION) as client:
        response = client.get_mandates()
except ConfigurationError as e:
    print(f"Configuration error: {e}")
except AuthenticationError as e:
    print(f"Authentication failed: {e}")
except ForbiddenError as e:
    print(f"Access forbidden: {e}")
except NotFoundError as e:
    print(f"Resource not found: {e}")
except ValidationError as e:
    print(f"Validation error: {e}")
    if e.validation_errors:
        for error in e.validation_errors:
            print(f"  - {error}")
except ServerError as e:
    print(f"Server error: {e}")
except ServiceUnavailableError as e:
    print(f"Service unavailable: {e}")
except FluviusAPIError as e:
    print(f"API error: {e}")

Data Service Types

Available data service types:

Type Description
VH_DAG Daily consumption history
VH_KWARTIER_UUR Quarter-hourly/hourly consumption history
VH_ONBEPAALD Indefinite consumption history
IG Installation data

License

GNU AFFERO GENERAL PUBLIC LICENSE

Metadata

Release files for fluvius-energy-api 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 fluvius-energy-api 0.2.2
File Size Uploaded Provenance Actions
fluvius_energy_api-0.2.2.tar.gz 96.5 kB With provenance Details for fluvius_energy_api-0.2.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fluvius-energy-api 0.2.2
File Interpreter ABI Platform Actions
fluvius_energy_api-0.2.2-py3-none-any.whl Python 3 none any Details for fluvius_energy_api-0.2.2-py3-none-any.whl

Total release size: 130.7 kB

Release files / fluvius_energy_api-0.2.2.tar.gz

Download URL fluvius_energy_api-0.2.2.tar.gz
Size 96.5 kB
Tags Source
SHA-256 checksum
How to use checksums
96583a4010b77f53589479cad5f916b9edeb44d9abc0c8af6a4a97f834865608
BLAKE2b-256 checksum
How to use checksums
df718d1db5de85dc73ad6e6c5fb3b051ed8c0041e4ff61baf662c2fe032f9736
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 Feb 10, 2026.

Transparency log

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

Download URL fluvius_energy_api-0.2.2-py3-none-any.whl
Size 34.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9ef3a901a9e4a99bed217bff7b8a4aa853b6cfc66ed398d097232067979ba6e4
BLAKE2b-256 checksum
How to use checksums
d5741eb73c00f8ef4cb0b26dac2dca4afe168da70139d6ab1a26006e91643717
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 Feb 10, 2026.

Transparency log

Security for fluvius-energy-api 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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for fluvius_energy_api-0.2.2.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 Feb 10, 2026.

Transparency log

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.

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 release files Full provenance

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