beacontower 2026.11.23.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. beacontower-2026.11.23.1/LICENSE +21 -0
  2. beacontower-2026.11.23.1/PKG-INFO +296 -0
  3. beacontower-2026.11.23.1/README.md +265 -0
  4. beacontower-2026.11.23.1/pyproject.toml +113 -0
  5. beacontower-2026.11.23.1/setup.cfg +4 -0
  6. beacontower-2026.11.23.1/setup.py +13 -0
  7. beacontower-2026.11.23.1/src/beacontower/dataproviders/__init__.py +50 -0
  8. beacontower-2026.11.23.1/src/beacontower/dataproviders/client.py +432 -0
  9. beacontower-2026.11.23.1/src/beacontower/dataproviders/datamodel.py +155 -0
  10. beacontower-2026.11.23.1/src/beacontower/dataproviders/py.typed +0 -0
  11. beacontower-2026.11.23.1/src/beacontower/dataproviders/sources.py +213 -0
  12. beacontower-2026.11.23.1/src/beacontower/metadata/__init__.py +11 -0
  13. beacontower-2026.11.23.1/src/beacontower/metadata/client.py +405 -0
  14. beacontower-2026.11.23.1/src/beacontower/metadata/datamodel.py +381 -0
  15. beacontower-2026.11.23.1/src/beacontower/metadata/pagination.py +21 -0
  16. beacontower-2026.11.23.1/src/beacontower/metadata/py.typed +0 -0
  17. beacontower-2026.11.23.1/src/beacontower/timeseries/__init__.py +12 -0
  18. beacontower-2026.11.23.1/src/beacontower/timeseries/_api.py +300 -0
  19. beacontower-2026.11.23.1/src/beacontower/timeseries/_api_get.py +338 -0
  20. beacontower-2026.11.23.1/src/beacontower/timeseries/_postgres.py +442 -0
  21. beacontower-2026.11.23.1/src/beacontower/timeseries/client.py +212 -0
  22. beacontower-2026.11.23.1/src/beacontower/timeseries/datamodel.py +14 -0
  23. beacontower-2026.11.23.1/src/beacontower/timeseries/protocol.py +54 -0
  24. beacontower-2026.11.23.1/src/beacontower/timeseries/py.typed +0 -0
  25. beacontower-2026.11.23.1/src/beacontower/timeseries/utilities/__init__.py +10 -0
  26. beacontower-2026.11.23.1/src/beacontower/timeseries/utilities/data_transform.py +160 -0
  27. beacontower-2026.11.23.1/src/beacontower/timeseries/utilities/database_info.py +23 -0
  28. beacontower-2026.11.23.1/src/beacontower.egg-info/PKG-INFO +296 -0
  29. beacontower-2026.11.23.1/src/beacontower.egg-info/SOURCES.txt +31 -0
  30. beacontower-2026.11.23.1/src/beacontower.egg-info/dependency_links.txt +1 -0
  31. beacontower-2026.11.23.1/src/beacontower.egg-info/requires.txt +11 -0
  32. beacontower-2026.11.23.1/src/beacontower.egg-info/top_level.txt +1 -0
  33. beacontower-2026.11.23.1/tests/test_namespace.py +8 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Beacon Tower
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,296 @@
1
+ Metadata-Version: 2.4
2
+ Name: beacontower
3
+ Version: 2026.11.23.1
4
+ Summary: Python client for Beacon Tower: assets, models and devices, their timeseries, and the data provider's sources
5
+ Author: Glaze Holding AB
6
+ License-Expression: MIT
7
+ Project-URL: Repository, https://github.com/beacontower/python-packages-public
8
+ Project-URL: Examples, https://github.com/beacontower/python-packages-public/tree/main/beacontower/examples
9
+ Project-URL: Releases, https://github.com/beacontower/python-packages-public/releases
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3 :: Only
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Programming Language :: Python :: 3.14
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Typing :: Typed
18
+ Requires-Python: >=3.11
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Requires-Dist: pydantic~=2.9
22
+ Requires-Dist: httpx<1,>=0.27
23
+ Requires-Dist: pandas<4,>=2.2
24
+ Provides-Extra: postgres
25
+ Requires-Dist: psycopg[binary,pool]~=3.1; extra == "postgres"
26
+ Provides-Extra: dev
27
+ Requires-Dist: pytest<10,>=8; extra == "dev"
28
+ Requires-Dist: pytest-cov<8,>=5; extra == "dev"
29
+ Requires-Dist: psycopg[binary,pool]~=3.1; extra == "dev"
30
+ Dynamic: license-file
31
+
32
+ # beacontower
33
+
34
+ Python client for [Beacon Tower](https://github.com/beacontower): the assets, models,
35
+ devices and organizations of a tenant, the timeseries its assets report, and the data
36
+ provider's sources and their instances.
37
+
38
+ ```
39
+ pip install beacontower
40
+ ```
41
+
42
+ Python 3.11 to 3.14. Reading timeseries straight from the database also needs
43
+ `pip install "beacontower[postgres]"`.
44
+
45
+ ## What it is for
46
+
47
+ The package is for code that works with a Beacon Tower tenant's data from Python: ML
48
+ pipelines and data science first, and scripts and integrations next. It answers in pydantic
49
+ models and pandas DataFrames, so the data goes straight into analysis.
50
+
51
+ - **Metadata:** the organizations, assets, models (their DTDL: signals, units, types),
52
+ devices, enrollment groups, providers and the asset graph that the login may see.
53
+ - **Timeseries:** what assets report, read through the timeseries API or straight from
54
+ TimescaleDB. It gives averages and time-weighted averages per bin, the value as of
55
+ fixed times, raw readings, the latest value, and every reading of an asset.
56
+ - **Data providers:** the sources the data provider polls (weather, electricity prices,
57
+ exchange rates). It shows their state, and makes and removes their instances.
58
+
59
+ Everything is read-only, apart from making and removing data provider instances. It doesn't
60
+ cover the rest of the platform: registering or onboarding devices, writing telemetry,
61
+ users and permissions, dashboards, alarms or live streams. It has no async client.
62
+
63
+ ## Logging in
64
+
65
+ `BeaconTowerClient(url, user_name, password)` logs in with a user name and password, through
66
+ the API's password login (`/auth/ropc`), and logs in again when its token runs out. **The
67
+ account must not use MFA.** The password login has no field for a one-time code, so an
68
+ account with an authenticator set up can't log in through it. Use an account that is
69
+ exempt from MFA, such as the integration or ML user a tenant's administrator sets up with
70
+ the `mfa-exempt` role, and keep its password in a secret store, not in code.
71
+
72
+ The `url` is the address you open Beacon Tower at in a browser, and the client finds the API
73
+ from it. Every call answers with what that account may see.
74
+
75
+ ## Examples
76
+
77
+ [`examples/`](https://github.com/beacontower/python-packages-public/tree/main/beacontower/examples) has a short script for every operation. Each one finds its own
78
+ data from what the login can see, so you set the address and the account and run any of
79
+ them:
80
+
81
+ ```
82
+ export BEACONTOWER_URL=https://<your-beacon-tower> BEACONTOWER_USER=... BEACONTOWER_PASSWORD=...
83
+ python examples/login.py
84
+ ```
85
+
86
+ | Script | Shows |
87
+ |---|---|
88
+ | `login.py` | logging in, and where the API is |
89
+ | `organizations.py` | organizations, and the assets and models in each |
90
+ | `assets_and_models.py` | assets, a model, and the signals and properties it defines |
91
+ | `devices.py` | devices, enrollment groups and a group's devices |
92
+ | `providers.py` | the providers that bring data in |
93
+ | `graph.py` | the asset graph |
94
+ | `latest_values.py` | the newest reading of every signal of an asset |
95
+ | `averages.py` | hourly averages over a day |
96
+ | `time_weighted_average.py` | time-weighted averages |
97
+ | `values_at_times.py` | the value at fixed times |
98
+ | `raw_values.py` | every reading of a signal in a period |
99
+ | `dump_values.py` | every reading of an asset, all signals |
100
+ | `from_postgres.py` | the same reads straight from TimescaleDB |
101
+ | `data_provider_status.py` | which data provider sources are on, and their instances |
102
+ | `data_provider_instance.py` | making, reading and removing instances for Malmö's weather and SE4 prices (writes; asks for `--yes`) |
103
+
104
+ ## Metadata
105
+
106
+ ```python
107
+ from beacontower.metadata import BeaconTowerClient
108
+
109
+ bt = BeaconTowerClient("https://<your-beacon-tower>", "<user name>", "<password>")
110
+ bt.check_auth()
111
+
112
+ assets = bt.get_assets()
113
+ model = bt.get_dtdl_model(assets[0].model_id)
114
+ ```
115
+
116
+ The address is the one you open Beacon Tower at in a browser; the client finds the API
117
+ from it. The API's own address (`https://<host>/api/v1`) works as well; pass `resolve_url=False`
118
+ to have any address used exactly as given. For a deployment signed by its own
119
+ certificate authority, pass `verify="<path to its CA bundle>"`.
120
+
121
+ ## Timeseries
122
+
123
+ A `TelemetryClient` is created in one of two ways and used the same way afterwards.
124
+
125
+ ```python
126
+ from datetime import UTC, datetime, timedelta
127
+ from beacontower.timeseries import TelemetryClient
128
+
129
+ # Through the timeseries API: the same address and login as above.
130
+ telemetry = TelemetryClient.from_api("https://<your-beacon-tower>", "<user name>", "<password>")
131
+
132
+ # Or straight from the TimescaleDB, for those with access to it
133
+ # (pip install "beacontower[postgres]").
134
+ telemetry = TelemetryClient.from_postgres(host="...", login="...", password="...")
135
+
136
+ hourly = telemetry.get_values_range(
137
+ model_id=asset.model_id,
138
+ asset_id=asset.id,
139
+ timeseries_name="temperature",
140
+ dt_start=datetime(2026, 11, 2, tzinfo=UTC),
141
+ dt_end=datetime(2026, 11, 9, tzinfo=UTC),
142
+ bin_size=timedelta(hours=1),
143
+ do_average=True,
144
+ )
145
+ ```
146
+
147
+ | Method | Answers |
148
+ |---|---|
149
+ | `get_latest_value` | the newest reading at or before a time |
150
+ | `get_values_range` | per bin: the average (`do_average`), the time-weighted average (`do_twa`), or by default the reading as of each bin label; `raw_values` gives the readings themselves |
151
+ | `get_time_weighted_average` | per bin, each reading weighed by how long it stood |
152
+ | `dump_values` | every reading of an asset in a period |
153
+ | `check_connection` | raises unless the source is reachable with the credentials |
154
+
155
+ An existing `BeaconTowerClient` can be reused: `TelemetryClient.from_beacon_tower_client(bt)`.
156
+
157
+ The value a read falls back to (`default_if_none_value`, `default_value_if_none`) must be a finite
158
+ number, an int or a float. NaN, infinity or anything else raises `ValueError` or `TypeError` before
159
+ anything is read. Count empty bins with `cnt`, which `return_count=True` gives.
160
+
161
+ ### Where the two sources differ
162
+
163
+ The methods, arguments and shapes are the same, and for one component of numeric
164
+ telemetry the two give the same frames. They were compared read by read against
165
+ timeseries API 0.2.15. The answers differ in these cases:
166
+
167
+ | | Timeseries API | Database |
168
+ |---|---|---|
169
+ | Time-weighted average after now | No value: a bin that starts after the current time gets `default_if_none_value`, also when it holds future-dated readings | The last reading is held, and future-dated readings are weighed |
170
+ | Time-weighted average, start of the bins | `dt_start` must lie on the API's grid (whole multiples of the bin size from a Monday at midnight UTC), else `ValueError` | Counted from any `dt_start` |
171
+ | Time-weighted average, `how` | `"locf"` only | `"locf"` and `"linear"`; needs the `timescaledb_toolkit` extension |
172
+ | Component | One, the root unless `component_id` is given | Every component together |
173
+ | Types | `telemetry` unless `types` is given | Every type together |
174
+ | `dump_values` `type` column | The timeseries type, such as `telemetry` | The value's kind, such as `doublevalue` |
175
+
176
+ Both skip readings that hold no number (NaN, or a non-numeric value), read the period as
177
+ `[dt_start, dt_end)`, weigh a last bin that runs past `dt_end` to its own end, and label
178
+ bins in UTC. The averages and the value-at-time read are cut on the same fixed grid by
179
+ both.
180
+
181
+ ### Gateways without `timeseries/query`
182
+
183
+ Gateways released before the timeseries API's `timeseries/query` was routed answer it
184
+ 404. The client then reads through `timeseries/get` and `timeseries/get/last` instead,
185
+ until `do_reset`, and bins the readings itself as the API bins them.
186
+
187
+ This fallback is temporary: it will be removed from a later version of this package,
188
+ once gateways route `timeseries/query` (gateway 0.7.0-prod.5 and later do). Each switch to
189
+ it is logged as a warning on the `beacontower.timeseries` logger, which, like all of this
190
+ package's logging, is shown once the application configures logging (for instance with
191
+ `logging.basicConfig()`).
192
+
193
+ The frames are the same, as compared read by read against timeseries API 0.2.15, except
194
+ here:
195
+
196
+ | | Through `timeseries/get` |
197
+ |---|---|
198
+ | Model version | Not kept to: the readings of every model id are read, as with `match_model=False` |
199
+ | Component | A signal that a component other than the one read also reports is refused (`ValueError`) |
200
+ | Types | `telemetry` and `propertyReported` only; properties need timeseries API 0.2.16 |
201
+ | `dump_values` | Refused (`NotImplementedError`) |
202
+ | The reading before a period | Looked for at most ten years back |
203
+ | Now, for the time-weighted average | The client's clock |
204
+
205
+ A read takes more requests this way: the signal's newest reading, the period (in parts
206
+ where it holds more readings than one answer does), and for the value as of a time or a
207
+ time-weighted average whose period does not start with a reading, the reading before it.
208
+
209
+ ## Data providers
210
+
211
+ Beacon Tower's data provider brings in data no device measures: weather at a position
212
+ (Open-Meteo), day-ahead electricity prices in a bidding zone (ENTSO-E) and exchange rates
213
+ against SEK (the Riksbank). Each environment switches the sources on that it uses.
214
+ `DataProvidersClient` shows which ones are on, lists their instances, and makes and removes them,
215
+ all through the API.
216
+
217
+ ```python
218
+ from beacontower.dataproviders import DataProvidersClient, Entsoe, OpenMeteo, Riksbank
219
+
220
+ providers = DataProvidersClient(bt) # a BeaconTowerClient, as above
221
+
222
+ status = providers.status()
223
+ for source in status.sources:
224
+ print(source.name, source.state, source.detail, source.devices)
225
+ # openmeteo enabled Open-Meteo (...), every 01:00:00 {'ok': 3, 'pending': 0, ...}
226
+
227
+ # The weather in Malmö, and the day-ahead prices of bidding zone SE4.
228
+ weather = providers.ensure(OpenMeteo(latitude=55.605, longitude=13.0038, history_days=30), wait=True)
229
+ # Sweden's bidding zones: "SE1" (Luleå), "SE2" (Sundsvall), "SE3" (Stockholm), "SE4" (Malmö).
230
+ prices = providers.ensure(Entsoe(bidding_zone="SE4"), wait=True)
231
+ for instance in providers.instances():
232
+ print(instance.id, instance.settings, instance.health, instance.last_success_at)
233
+
234
+ providers.remove(weather.id) # stops polling; the asset and its data stay unless delete_asset=True
235
+ ```
236
+
237
+ An instance is a provider client provisioned with the source's settings, plus an asset with
238
+ the same id on the source's model, bound to the client's signals. The asset holds the data:
239
+ read it like any asset's (`asset_id` and `model_id` are on the instance).
240
+
241
+ | Method | Does |
242
+ |---|---|
243
+ | `status()` | whether the provider is registered and reporting, and per source its state (`enabled`, `disabled`, `invalid`, or `unknown` without a status device), what it polls, its instances by health, and whether the platform has its model |
244
+ | `instances(source=None)` | every instance, or one source's, with its settings, locked identity, `config_error`, last poll, history and units |
245
+ | `get(id)`, `find(source)` | one instance, by id or by its identity settings (an Open-Meteo position, an ENTSO-E zone) |
246
+ | `create(source, ...)` | the client, the asset, the binding, then the provisioning; undone when a step fails; `wait=True` returns after the first successful poll |
247
+ | `ensure(source, ...)` | `find`, else `create`: Open-Meteo bills per position, so reuse one |
248
+ | `remove(id, delete_asset=False)` | unprovisions (the provider stops polling) and deletes the client |
249
+ | `wait_for_first_poll(id)` | raises `InstanceConfigError` with the provider's reason when it does not poll the instance |
250
+ | `create_status_device()` | once per environment: the client the provider reports the sources' states to |
251
+
252
+ Settings are checked before anything is sent: a position in range, history up to 3660 days,
253
+ Open-Meteo variables the model has a channel for, an instance id without a dot. A source's
254
+ identity settings (an Open-Meteo position, an ENTSO-E zone) are locked by the provider at the
255
+ first successful poll; to change them, remove the instance and make another. The platform's
256
+ `enabled` flag on a client does not stop the provider from polling it; `remove` does.
257
+
258
+ ### Adding a source
259
+
260
+ Each source is a class. A new one subclasses `Source` with its tag name, its model and the
261
+ tags that identify an instance, and declares its settings as fields, named as its device tags
262
+ in snake_case. It registers itself: `instances()` reads it from then on, and `create` sends it.
263
+
264
+ ```python
265
+ from typing import ClassVar
266
+ from beacontower.dataproviders import Source
267
+
268
+ class Nordpool(Source):
269
+ name: ClassVar[str] = "nordpool"
270
+ model_id: ClassVar[str] = "dtmi:dataproviders_nordpool;1.1"
271
+ identity: ClassVar[tuple[str, ...]] = ("area",)
272
+
273
+ area: str
274
+ ```
275
+
276
+ A source the package has no class for is still listed by `status()` and `instances()`, its
277
+ settings as an `OtherSource` holding the tags as they are.
278
+
279
+ ### Testing against an environment
280
+
281
+ `tests/dataproviders/test_dataproviders_live.py` runs against a real Beacon Tower when
282
+ `BEACONTOWER_URL` (the API's address) and `BEACONTOWER_TOKEN` (or `BEACONTOWER_USER` and
283
+ `BEACONTOWER_PASSWORD`) are set; it makes one ENTSO-E instance, reads its prices back and removes
284
+ it. `BEACONTOWER_VERIFY=false` accepts a self-signed certificate, and `BEACONTOWER_ORGANIZATION`
285
+ names the organization when the login sees several.
286
+
287
+ ## Versions
288
+
289
+ Every merge to `main` is a release on PyPI. Versions follow calendar versioning,
290
+ `YYYY.M.D.Rev`: `2026.11.24.1` is the first release of that day, `2026.11.24.2` the second
291
+ (see `VERSIONING.md`). Each release is tagged `vYYYY.M.D.Rev` on GitHub, with its notes. An
292
+ install from a git checkout reports `0.0.0+local`, because there the commit is the version.
293
+
294
+ ## License
295
+
296
+ MIT, see `LICENSE`.
@@ -0,0 +1,265 @@
1
+ # beacontower
2
+
3
+ Python client for [Beacon Tower](https://github.com/beacontower): the assets, models,
4
+ devices and organizations of a tenant, the timeseries its assets report, and the data
5
+ provider's sources and their instances.
6
+
7
+ ```
8
+ pip install beacontower
9
+ ```
10
+
11
+ Python 3.11 to 3.14. Reading timeseries straight from the database also needs
12
+ `pip install "beacontower[postgres]"`.
13
+
14
+ ## What it is for
15
+
16
+ The package is for code that works with a Beacon Tower tenant's data from Python: ML
17
+ pipelines and data science first, and scripts and integrations next. It answers in pydantic
18
+ models and pandas DataFrames, so the data goes straight into analysis.
19
+
20
+ - **Metadata:** the organizations, assets, models (their DTDL: signals, units, types),
21
+ devices, enrollment groups, providers and the asset graph that the login may see.
22
+ - **Timeseries:** what assets report, read through the timeseries API or straight from
23
+ TimescaleDB. It gives averages and time-weighted averages per bin, the value as of
24
+ fixed times, raw readings, the latest value, and every reading of an asset.
25
+ - **Data providers:** the sources the data provider polls (weather, electricity prices,
26
+ exchange rates). It shows their state, and makes and removes their instances.
27
+
28
+ Everything is read-only, apart from making and removing data provider instances. It doesn't
29
+ cover the rest of the platform: registering or onboarding devices, writing telemetry,
30
+ users and permissions, dashboards, alarms or live streams. It has no async client.
31
+
32
+ ## Logging in
33
+
34
+ `BeaconTowerClient(url, user_name, password)` logs in with a user name and password, through
35
+ the API's password login (`/auth/ropc`), and logs in again when its token runs out. **The
36
+ account must not use MFA.** The password login has no field for a one-time code, so an
37
+ account with an authenticator set up can't log in through it. Use an account that is
38
+ exempt from MFA, such as the integration or ML user a tenant's administrator sets up with
39
+ the `mfa-exempt` role, and keep its password in a secret store, not in code.
40
+
41
+ The `url` is the address you open Beacon Tower at in a browser, and the client finds the API
42
+ from it. Every call answers with what that account may see.
43
+
44
+ ## Examples
45
+
46
+ [`examples/`](https://github.com/beacontower/python-packages-public/tree/main/beacontower/examples) has a short script for every operation. Each one finds its own
47
+ data from what the login can see, so you set the address and the account and run any of
48
+ them:
49
+
50
+ ```
51
+ export BEACONTOWER_URL=https://<your-beacon-tower> BEACONTOWER_USER=... BEACONTOWER_PASSWORD=...
52
+ python examples/login.py
53
+ ```
54
+
55
+ | Script | Shows |
56
+ |---|---|
57
+ | `login.py` | logging in, and where the API is |
58
+ | `organizations.py` | organizations, and the assets and models in each |
59
+ | `assets_and_models.py` | assets, a model, and the signals and properties it defines |
60
+ | `devices.py` | devices, enrollment groups and a group's devices |
61
+ | `providers.py` | the providers that bring data in |
62
+ | `graph.py` | the asset graph |
63
+ | `latest_values.py` | the newest reading of every signal of an asset |
64
+ | `averages.py` | hourly averages over a day |
65
+ | `time_weighted_average.py` | time-weighted averages |
66
+ | `values_at_times.py` | the value at fixed times |
67
+ | `raw_values.py` | every reading of a signal in a period |
68
+ | `dump_values.py` | every reading of an asset, all signals |
69
+ | `from_postgres.py` | the same reads straight from TimescaleDB |
70
+ | `data_provider_status.py` | which data provider sources are on, and their instances |
71
+ | `data_provider_instance.py` | making, reading and removing instances for Malmö's weather and SE4 prices (writes; asks for `--yes`) |
72
+
73
+ ## Metadata
74
+
75
+ ```python
76
+ from beacontower.metadata import BeaconTowerClient
77
+
78
+ bt = BeaconTowerClient("https://<your-beacon-tower>", "<user name>", "<password>")
79
+ bt.check_auth()
80
+
81
+ assets = bt.get_assets()
82
+ model = bt.get_dtdl_model(assets[0].model_id)
83
+ ```
84
+
85
+ The address is the one you open Beacon Tower at in a browser; the client finds the API
86
+ from it. The API's own address (`https://<host>/api/v1`) works as well; pass `resolve_url=False`
87
+ to have any address used exactly as given. For a deployment signed by its own
88
+ certificate authority, pass `verify="<path to its CA bundle>"`.
89
+
90
+ ## Timeseries
91
+
92
+ A `TelemetryClient` is created in one of two ways and used the same way afterwards.
93
+
94
+ ```python
95
+ from datetime import UTC, datetime, timedelta
96
+ from beacontower.timeseries import TelemetryClient
97
+
98
+ # Through the timeseries API: the same address and login as above.
99
+ telemetry = TelemetryClient.from_api("https://<your-beacon-tower>", "<user name>", "<password>")
100
+
101
+ # Or straight from the TimescaleDB, for those with access to it
102
+ # (pip install "beacontower[postgres]").
103
+ telemetry = TelemetryClient.from_postgres(host="...", login="...", password="...")
104
+
105
+ hourly = telemetry.get_values_range(
106
+ model_id=asset.model_id,
107
+ asset_id=asset.id,
108
+ timeseries_name="temperature",
109
+ dt_start=datetime(2026, 11, 2, tzinfo=UTC),
110
+ dt_end=datetime(2026, 11, 9, tzinfo=UTC),
111
+ bin_size=timedelta(hours=1),
112
+ do_average=True,
113
+ )
114
+ ```
115
+
116
+ | Method | Answers |
117
+ |---|---|
118
+ | `get_latest_value` | the newest reading at or before a time |
119
+ | `get_values_range` | per bin: the average (`do_average`), the time-weighted average (`do_twa`), or by default the reading as of each bin label; `raw_values` gives the readings themselves |
120
+ | `get_time_weighted_average` | per bin, each reading weighed by how long it stood |
121
+ | `dump_values` | every reading of an asset in a period |
122
+ | `check_connection` | raises unless the source is reachable with the credentials |
123
+
124
+ An existing `BeaconTowerClient` can be reused: `TelemetryClient.from_beacon_tower_client(bt)`.
125
+
126
+ The value a read falls back to (`default_if_none_value`, `default_value_if_none`) must be a finite
127
+ number, an int or a float. NaN, infinity or anything else raises `ValueError` or `TypeError` before
128
+ anything is read. Count empty bins with `cnt`, which `return_count=True` gives.
129
+
130
+ ### Where the two sources differ
131
+
132
+ The methods, arguments and shapes are the same, and for one component of numeric
133
+ telemetry the two give the same frames. They were compared read by read against
134
+ timeseries API 0.2.15. The answers differ in these cases:
135
+
136
+ | | Timeseries API | Database |
137
+ |---|---|---|
138
+ | Time-weighted average after now | No value: a bin that starts after the current time gets `default_if_none_value`, also when it holds future-dated readings | The last reading is held, and future-dated readings are weighed |
139
+ | Time-weighted average, start of the bins | `dt_start` must lie on the API's grid (whole multiples of the bin size from a Monday at midnight UTC), else `ValueError` | Counted from any `dt_start` |
140
+ | Time-weighted average, `how` | `"locf"` only | `"locf"` and `"linear"`; needs the `timescaledb_toolkit` extension |
141
+ | Component | One, the root unless `component_id` is given | Every component together |
142
+ | Types | `telemetry` unless `types` is given | Every type together |
143
+ | `dump_values` `type` column | The timeseries type, such as `telemetry` | The value's kind, such as `doublevalue` |
144
+
145
+ Both skip readings that hold no number (NaN, or a non-numeric value), read the period as
146
+ `[dt_start, dt_end)`, weigh a last bin that runs past `dt_end` to its own end, and label
147
+ bins in UTC. The averages and the value-at-time read are cut on the same fixed grid by
148
+ both.
149
+
150
+ ### Gateways without `timeseries/query`
151
+
152
+ Gateways released before the timeseries API's `timeseries/query` was routed answer it
153
+ 404. The client then reads through `timeseries/get` and `timeseries/get/last` instead,
154
+ until `do_reset`, and bins the readings itself as the API bins them.
155
+
156
+ This fallback is temporary: it will be removed from a later version of this package,
157
+ once gateways route `timeseries/query` (gateway 0.7.0-prod.5 and later do). Each switch to
158
+ it is logged as a warning on the `beacontower.timeseries` logger, which, like all of this
159
+ package's logging, is shown once the application configures logging (for instance with
160
+ `logging.basicConfig()`).
161
+
162
+ The frames are the same, as compared read by read against timeseries API 0.2.15, except
163
+ here:
164
+
165
+ | | Through `timeseries/get` |
166
+ |---|---|
167
+ | Model version | Not kept to: the readings of every model id are read, as with `match_model=False` |
168
+ | Component | A signal that a component other than the one read also reports is refused (`ValueError`) |
169
+ | Types | `telemetry` and `propertyReported` only; properties need timeseries API 0.2.16 |
170
+ | `dump_values` | Refused (`NotImplementedError`) |
171
+ | The reading before a period | Looked for at most ten years back |
172
+ | Now, for the time-weighted average | The client's clock |
173
+
174
+ A read takes more requests this way: the signal's newest reading, the period (in parts
175
+ where it holds more readings than one answer does), and for the value as of a time or a
176
+ time-weighted average whose period does not start with a reading, the reading before it.
177
+
178
+ ## Data providers
179
+
180
+ Beacon Tower's data provider brings in data no device measures: weather at a position
181
+ (Open-Meteo), day-ahead electricity prices in a bidding zone (ENTSO-E) and exchange rates
182
+ against SEK (the Riksbank). Each environment switches the sources on that it uses.
183
+ `DataProvidersClient` shows which ones are on, lists their instances, and makes and removes them,
184
+ all through the API.
185
+
186
+ ```python
187
+ from beacontower.dataproviders import DataProvidersClient, Entsoe, OpenMeteo, Riksbank
188
+
189
+ providers = DataProvidersClient(bt) # a BeaconTowerClient, as above
190
+
191
+ status = providers.status()
192
+ for source in status.sources:
193
+ print(source.name, source.state, source.detail, source.devices)
194
+ # openmeteo enabled Open-Meteo (...), every 01:00:00 {'ok': 3, 'pending': 0, ...}
195
+
196
+ # The weather in Malmö, and the day-ahead prices of bidding zone SE4.
197
+ weather = providers.ensure(OpenMeteo(latitude=55.605, longitude=13.0038, history_days=30), wait=True)
198
+ # Sweden's bidding zones: "SE1" (Luleå), "SE2" (Sundsvall), "SE3" (Stockholm), "SE4" (Malmö).
199
+ prices = providers.ensure(Entsoe(bidding_zone="SE4"), wait=True)
200
+ for instance in providers.instances():
201
+ print(instance.id, instance.settings, instance.health, instance.last_success_at)
202
+
203
+ providers.remove(weather.id) # stops polling; the asset and its data stay unless delete_asset=True
204
+ ```
205
+
206
+ An instance is a provider client provisioned with the source's settings, plus an asset with
207
+ the same id on the source's model, bound to the client's signals. The asset holds the data:
208
+ read it like any asset's (`asset_id` and `model_id` are on the instance).
209
+
210
+ | Method | Does |
211
+ |---|---|
212
+ | `status()` | whether the provider is registered and reporting, and per source its state (`enabled`, `disabled`, `invalid`, or `unknown` without a status device), what it polls, its instances by health, and whether the platform has its model |
213
+ | `instances(source=None)` | every instance, or one source's, with its settings, locked identity, `config_error`, last poll, history and units |
214
+ | `get(id)`, `find(source)` | one instance, by id or by its identity settings (an Open-Meteo position, an ENTSO-E zone) |
215
+ | `create(source, ...)` | the client, the asset, the binding, then the provisioning; undone when a step fails; `wait=True` returns after the first successful poll |
216
+ | `ensure(source, ...)` | `find`, else `create`: Open-Meteo bills per position, so reuse one |
217
+ | `remove(id, delete_asset=False)` | unprovisions (the provider stops polling) and deletes the client |
218
+ | `wait_for_first_poll(id)` | raises `InstanceConfigError` with the provider's reason when it does not poll the instance |
219
+ | `create_status_device()` | once per environment: the client the provider reports the sources' states to |
220
+
221
+ Settings are checked before anything is sent: a position in range, history up to 3660 days,
222
+ Open-Meteo variables the model has a channel for, an instance id without a dot. A source's
223
+ identity settings (an Open-Meteo position, an ENTSO-E zone) are locked by the provider at the
224
+ first successful poll; to change them, remove the instance and make another. The platform's
225
+ `enabled` flag on a client does not stop the provider from polling it; `remove` does.
226
+
227
+ ### Adding a source
228
+
229
+ Each source is a class. A new one subclasses `Source` with its tag name, its model and the
230
+ tags that identify an instance, and declares its settings as fields, named as its device tags
231
+ in snake_case. It registers itself: `instances()` reads it from then on, and `create` sends it.
232
+
233
+ ```python
234
+ from typing import ClassVar
235
+ from beacontower.dataproviders import Source
236
+
237
+ class Nordpool(Source):
238
+ name: ClassVar[str] = "nordpool"
239
+ model_id: ClassVar[str] = "dtmi:dataproviders_nordpool;1.1"
240
+ identity: ClassVar[tuple[str, ...]] = ("area",)
241
+
242
+ area: str
243
+ ```
244
+
245
+ A source the package has no class for is still listed by `status()` and `instances()`, its
246
+ settings as an `OtherSource` holding the tags as they are.
247
+
248
+ ### Testing against an environment
249
+
250
+ `tests/dataproviders/test_dataproviders_live.py` runs against a real Beacon Tower when
251
+ `BEACONTOWER_URL` (the API's address) and `BEACONTOWER_TOKEN` (or `BEACONTOWER_USER` and
252
+ `BEACONTOWER_PASSWORD`) are set; it makes one ENTSO-E instance, reads its prices back and removes
253
+ it. `BEACONTOWER_VERIFY=false` accepts a self-signed certificate, and `BEACONTOWER_ORGANIZATION`
254
+ names the organization when the login sees several.
255
+
256
+ ## Versions
257
+
258
+ Every merge to `main` is a release on PyPI. Versions follow calendar versioning,
259
+ `YYYY.M.D.Rev`: `2026.11.24.1` is the first release of that day, `2026.11.24.2` the second
260
+ (see `VERSIONING.md`). Each release is tagged `vYYYY.M.D.Rev` on GitHub, with its notes. An
261
+ install from a git checkout reports `0.0.0+local`, because there the commit is the version.
262
+
263
+ ## License
264
+
265
+ MIT, see `LICENSE`.