dlt-source-elhub
A dlt source for Elhub's Energy Data API: your organisation's electricity metering points and their hourly metering values, authenticated through Maskinporten, into any dlt destination.
Records land as the API returns them — nothing renamed, nothing dropped, no invented child tables. Column names are the API's own, in dlt's usual snake_case. Reshaping belongs in your transform layer, where you can change it without waiting for a release.
The package handles the Maskinporten token, the headers Elhub insists on, envelope unwrapping and a cursor per metering point. It depends on dlt and PyJWT.
How to start
Before any code: your organisation needs a Maskinporten client with the scope elhub:enduser, which Elhub grants to an organisation number on request (Elhub's guide). The client gives you a client id, a key id and a private key.
uv add dlt-source-elhub "dlt[duckdb]" # any dlt destination works; DuckDB is the one below
Then two files in a .dlt/ directory beside your script.
.dlt/config.toml:
[sources.elhub]
user_agent = "my-company-elhub-pipeline" # Elhub refuses a request without one
.dlt/secrets.toml:
[sources.elhub.credentials]
client_id = "00000000-0000-0000-0000-000000000000"
kid = "00000000-0000-0000-0000-000000000000"
private_key = """-----BEGIN PRIVATE KEY-----
...
-----END PRIVATE KEY-----"""
Then one script, daily_load.py, on a timer:
import dlt
from dlt_source_elhub import elhub_source
pipeline = dlt.pipeline(pipeline_name="elhub", destination="duckdb", dataset_name="elhub_data")
pipeline.run(elhub_source())
The first run loads everything Elhub retains for every metering point it lists — three years and 41 days, one request per point — and every run after loads what was inserted since, per point. Schedule it after 09:00 Europe/Oslo, when Elhub has forwarded yesterday to end users; each grid company delivers at its own time before 07:00. Run it soon: Elhub deletes data older than three years and 41 days, so each day a first load waits, a day of history is gone.
A run lists the points with values in the last 24 hours, so a point the end user had earlier and has since lost is not among them. backfill.py over the whole retention finds those.
Two more examples, a page each: backfill.py re-loads one window for every point the end user had in it, without touching the cursors, and companies.py reads several companies with one client. From a checkout, run one with python examples/<name>.py.
What it loads
| Resource | Endpoint | Load strategy | Key |
|---|---|---|---|
metering_points |
GET /metering-points |
merge | id |
metering_values_hour |
GET /metering-points/{id} |
merge | meteringPointId, startTime, direction |
Both read the dataset METERING_VALUES_HOUR_RESTRICTED, the only one the elhub:enduser scope answers; the day, month and year datasets are 403 under it, so aggregate downstream.
Three things worth knowing before your first query:
metering_pointsis the list of ids, found the only way Elhub offers. There is no list endpoint; the dataset call without an id returns every point with values in the last 24 hours, or in the window you bind. A point lands as the API'sidandtype, with the values left to the other table. A point gone from the list keeps its row; its_dlt_load_idsays when it was last seen.metering_values_houris one row per value, with the point'sidasmeteringPointId.resolutionisPT60Mon most points andPT15Mon some, so never assume 24 rows a day.directionisOutfor consumption andInfor production, both loaded. A corrected value overwrites the old one, because the key is the interval, not the insert.- The cursor is per metering point, stored in dlt's resource state under the point's id. That is what makes a new point load its history on first contact, and several companies safe in one pipeline — how it works.
Configuring a resource
Each resource takes its endpoint's params in snake_case. A date is YYYY-MM-DD, read as midnight in Europe/Oslo; an ISO 8601 instant with an offset works too.
source = elhub_source(consumer_org="999999991")
source.metering_points.bind(metering_point_ids=["707057500000000001"])
source.metering_values_hour.bind(start_date="2026-10-01", end_date="2026-10-03")
pipeline.run(source)
| Param | What to know |
|---|---|
consumer_org |
On the source. The organisation number of a company that delegated the scope to your client's organisation in Altinn; the token is then issued on its behalf. Leave it out to read the client's own organisation. One source per company. |
initial_insert_date_time |
On the source. Where a point the pipeline has not seen starts: values inserted at or after this instant. Left out, everything Elhub retains. |
metering_point_ids |
On metering_points. Keep only these ids; metering_values_hour then reads only them. For one new point's history, or a backfill of a few. |
start_date, end_date |
On both resources. On metering_points they set the discovery window: the API lists at most a day per request, so a wider window is listed a day at a time, and finds every point the end user had in it. On metering_values_hour they make the request a backfill: the window is sent as given, and the stored cursor is neither read nor advanced. The end is exclusive on startTime in practice. |
insert_date_time |
On metering_values_hour. Sent instead of the cursor, which is then neither read nor advanced: values inserted at or after it, over the API's widest window when no dates are bound. |
params |
On every resource, merged into the query string last, so it wins over every named param. The escape hatch for a param the API grows later. |
user_agent, headers |
On the source. Elhub answers 403 to a request without a User-Agent; headers adds any other, such as X-Elhub-GLN under another scope. |
request_max_attempts, request_max_retry_delay |
On the source. How long a 429 or 5xx is retried: attempts per request, and the longest pause between them in seconds. The defaults outlast Elhub's rate limit as measured; if Elhub changes it, change these. |
Params can also be set in config, per resource:
[sources.elhub.metering_values_hour]
start_date = "2026-10-01"
end_date = "2026-10-03"
Compatibility
dlt-source-elhub |
Energy Data API |
|---|---|
| 0.1.x | v0 |
The API is v0, and Elhub says breaking changes may come. Built against the dated copy of its documentation in specs/ and run live against it, last on 2026-10-13, with the scope elhub:enduser. The elhub:thirdparty scope is not verified.
Read next
- API quirks worth knowing — what was measured against the live API: windows, the inclusive
insertDateTimefilter,204for empty, when yesterday arrives. - Reference — the cursor, backfilling, several companies, nesting, what the source does not expose, logging and column types.
- Changelog and contributing.
License
Apache-2.0. The files in specs/ are Elhub's own API documentation, included as the spec this package is built against. They are Elhub's material, and the licence does not extend to them.
Metadata
Release files for dlt-source-elhub 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dlt_source_elhub-0.3.0.tar.gz | 27.4 kB | With provenance | Details for dlt_source_elhub-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dlt_source_elhub-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for dlt_source_elhub-0.3.0-py3-none-any.whl |
Total release size: 43.4 kB
Release files / dlt_source_elhub-0.3.0.tar.gz
| Download URL | dlt_source_elhub-0.3.0.tar.gz |
|---|---|
| Size | 27.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
015b2066a1e82bc9bbc382595466158f397053d2687878dcedf169761c787274
|
|
BLAKE2b-256 checksum How to use checksums |
15423b2442a74d4d4a0a972714cf85b9e3ad7eab975519504bfad5bdbd223b2a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 10, 2026.
Transparency logRelease files / dlt_source_elhub-0.3.0-py3-none-any.whl
| Download URL | dlt_source_elhub-0.3.0-py3-none-any.whl |
|---|---|
| Size | 15.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0364445419b9ed86acf422877b63251f955ac1906eb39f95f460152a74672254
|
|
BLAKE2b-256 checksum How to use checksums |
ca92b21e9e984bf4a19f2e20aa25df1fcbe9c3689ccf830926ddea177701a920
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 10, 2026.
Transparency logSecurity for dlt-source-elhub 0.3.0
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.
Attestation for dlt_source_elhub-0.3.0.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 Nov 10, 2026.
Transparency logA 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.