leneda-client 0.2.0__py3-none-any.whl → 0.3.0__py3-none-any.whl

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.
leneda/client.py CHANGED
@@ -7,11 +7,12 @@ energy consumption and production data for electricity and gas.
7
7
 
8
8
  import json
9
9
  import logging
10
- from datetime import datetime
10
+ from datetime import datetime, timedelta
11
11
  from typing import Any, Dict, List, Optional, Union
12
12
 
13
13
  import requests
14
14
 
15
+ from .exceptions import ForbiddenException, InvalidMeteringPointException, UnauthorizedException
15
16
  from .models import (
16
17
  AggregatedMeteringData,
17
18
  MeteringData,
@@ -70,6 +71,12 @@ class LenedaClient:
70
71
 
71
72
  Returns:
72
73
  The JSON response from the API
74
+
75
+ Raises:
76
+ UnauthorizedException: If the API returns a 401 status code
77
+ ForbiddenException: If the API returns a 403 status code
78
+ requests.exceptions.RequestException: For other request errors
79
+ json.JSONDecodeError: If the response cannot be parsed as JSON
73
80
  """
74
81
  url = f"{self.BASE_URL}/{endpoint}"
75
82
 
@@ -87,6 +94,14 @@ class LenedaClient:
87
94
  )
88
95
 
89
96
  # Check for HTTP errors
97
+ if response.status_code == 401:
98
+ raise UnauthorizedException(
99
+ "API authentication failed. Please check your API key and energy ID."
100
+ )
101
+ if response.status_code == 403:
102
+ raise ForbiddenException(
103
+ "Access forbidden. This may be due to Leneda's geoblocking or other access restrictions."
104
+ )
90
105
  response.raise_for_status()
91
106
 
92
107
  # Parse the response
@@ -234,3 +249,44 @@ class LenedaClient:
234
249
  response_data = self._make_request(method="POST", endpoint=endpoint, json_data=data)
235
250
 
236
251
  return response_data
252
+
253
+ def test_metering_point(self, metering_point_code: str) -> bool:
254
+ """
255
+ Test if a metering point code is valid and accessible.
256
+
257
+ This method checks if a metering point code is valid by making a request
258
+ for aggregated metering data. If the unit property in the response is null,
259
+ it indicates that the metering point is invalid or not accessible.
260
+
261
+ Args:
262
+ metering_point_code: The metering point code to test
263
+
264
+ Returns:
265
+ bool: True if the metering point is valid and accessible, False otherwise
266
+
267
+ Raises:
268
+ UnauthorizedException: If the API returns a 401 status code
269
+ ForbiddenException: If the API returns a 403 status code
270
+ requests.exceptions.RequestException: For other request errors
271
+ """
272
+ # Use arbitrary time window
273
+ end_date = datetime.now()
274
+ start_date = end_date - timedelta(weeks=4)
275
+
276
+ # Try to get aggregated data for electricity consumption
277
+ result = self.get_aggregated_metering_data(
278
+ metering_point_code=metering_point_code,
279
+ obis_code=ObisCode.ELEC_CONSUMPTION_ACTIVE,
280
+ start_date=start_date,
281
+ end_date=end_date,
282
+ aggregation_level="Month",
283
+ transformation_mode="Accumulation",
284
+ )
285
+
286
+ # If we get here and the unit is None, the metering point is invalid
287
+ if result.unit is None:
288
+ raise InvalidMeteringPointException(
289
+ f"Metering point {metering_point_code} is invalid or not accessible"
290
+ )
291
+
292
+ return True
leneda/exceptions.py ADDED
@@ -0,0 +1,27 @@
1
+ """
2
+ Custom exceptions for the Leneda API client.
3
+ """
4
+
5
+
6
+ class LenedaException(Exception):
7
+ """Base exception for all Leneda API client exceptions."""
8
+
9
+ pass
10
+
11
+
12
+ class UnauthorizedException(LenedaException):
13
+ """Raised when API authentication fails (401 Unauthorized)."""
14
+
15
+ pass
16
+
17
+
18
+ class ForbiddenException(LenedaException):
19
+ """Raised when access is forbidden (403 Forbidden), typically due to geoblocking or other access restrictions."""
20
+
21
+ pass
22
+
23
+
24
+ class InvalidMeteringPointException(LenedaException):
25
+ """Raised when a metering point code is invalid or not accessible."""
26
+
27
+ pass
leneda/version.py CHANGED
@@ -1,3 +1,3 @@
1
1
  """Version information."""
2
2
 
3
- __version__ = "0.2.0"
3
+ __version__ = "0.3.0"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: leneda-client
3
- Version: 0.2.0
3
+ Version: 0.3.0
4
4
  Summary: Python client for the Leneda energy data platform
5
5
  Home-page: https://github.com/fedus/leneda-client
6
6
  Author: fedus
@@ -21,6 +21,7 @@ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
21
  Classifier: Topic :: Utilities
22
22
  Requires-Python: >=3.8
23
23
  Description-Content-Type: text/markdown
24
+ License-File: LICENSE
24
25
  Requires-Dist: requests>=2.25.0
25
26
  Requires-Dist: python-dateutil>=2.8.2
26
27
  Dynamic: author
@@ -30,6 +31,7 @@ Dynamic: description
30
31
  Dynamic: description-content-type
31
32
  Dynamic: home-page
32
33
  Dynamic: keywords
34
+ Dynamic: license-file
33
35
  Dynamic: project-url
34
36
  Dynamic: requires-dist
35
37
  Dynamic: requires-python
@@ -37,9 +39,10 @@ Dynamic: summary
37
39
 
38
40
  # Leneda API Client
39
41
 
40
- [![PyPI version]](https://pypi.org/project/leneda-client/)
41
- [![Python versions]](https://pypi.org/project/leneda-client/)
42
- [![License]](https://github.com/fedus/leneda-client/blob/main/LICENSE)
42
+ [![PyPI version](https://img.shields.io/pypi/v/leneda-client.svg)](https://pypi.org/project/leneda-client/)
43
+ [![Python Versions](https://img.shields.io/pypi/pyversions/leneda-client)](https://pypi.org/project/leneda-client/)
44
+ [![License](https://img.shields.io/github/license/fedus/leneda-client)](https://github.com/fedus/leneda-client/blob/main/LICENSE)
45
+
43
46
 
44
47
  A Python client for interacting with the Leneda energy data platform API.
45
48
 
@@ -56,3 +59,33 @@ This client provides a simple interface to the Leneda API, which allows users to
56
59
 
57
60
  ```bash
58
61
  pip install leneda-client
62
+ ```
63
+
64
+ ## Trying it out
65
+
66
+ ```bash
67
+ $ export LENEDA_ENERGY_ID='LUXE-xx-yy-1234'
68
+ $ export LENEDA_API_KEY='YOUR-API-KEY'
69
+ $ python examples/basic_usage.py --metering-point LU0000012345678901234000000000000
70
+ Example 1: Getting hourly electricity consumption data for the last 7 days
71
+ Retrieved 514 consumption measurements
72
+ Unit: kW
73
+ Interval length: PT15M
74
+ Metering point: LU0000012345678901234000000000000
75
+ OBIS code: ObisCode.ELEC_CONSUMPTION_ACTIVE
76
+
77
+ First 3 measurements:
78
+ Time: 2025-04-18T13:30:00+00:00, Value: 0.048 kW, Type: Actual, Version: 2, Calculated: False
79
+ Time: 2025-04-18T13:45:00+00:00, Value: 0.08 kW, Type: Actual, Version: 2, Calculated: False
80
+ Time: 2025-04-18T14:00:00+00:00, Value: 0.08 kW, Type: Actual, Version: 2, Calculated: False
81
+
82
+ Example 2: Getting monthly aggregated electricity consumption for 2025
83
+ Retrieved 4 monthly aggregations
84
+ Unit: kWh
85
+
86
+ Monthly consumption:
87
+ Period: 2024-12 to 2025-01, Value: 30.858 kWh, Calculated: False
88
+ Period: 2025-01 to 2025-02, Value: 148.985 kWh, Calculated: False
89
+ Period: 2025-02 to 2025-03, Value: 44.619 kWh, Calculated: False
90
+ Period: 2025-03 to 2025-04, Value: 29.662 kWh, Calculated: False
91
+ ```
@@ -0,0 +1,11 @@
1
+ leneda/__init__.py,sha256=-BHIXBfTTbX6EKDHr2Bq7rPzsPNYrrkgs9AJqWJR_1Q,732
2
+ leneda/client.py,sha256=X2seOTrUYLKuLxDJT6ryGdKfNelsOhVq7lenJjI3kmM,10825
3
+ leneda/exceptions.py,sha256=a84T3uSDQsMiKyFUZTbJTAp3hELfI1GQDriqv6aMDb8,600
4
+ leneda/models.py,sha256=jdU2cIZZDExUSiSfz9zaYjJepr0m3v_x5b1fyOaEI8Q,7930
5
+ leneda/obis_codes.py,sha256=VfsJQN1U80eZ5g1bIteDCLkkmBQ0AIkkm_zNAeM1Dog,7507
6
+ leneda/version.py,sha256=wtPxgfjm82dK-e3EK0shDP4_7DlFk8hkRkOIPd6mV58,50
7
+ leneda_client-0.3.0.dist-info/licenses/LICENSE,sha256=nAhDs625lK6v8oLqjWCABKBKlwxVoRDFXQvoZPfOtKQ,1062
8
+ leneda_client-0.3.0.dist-info/METADATA,sha256=RHArkKFQqY--FL7-RCwTUQTaJvMWLvdswIYbM-8Yr1U,3344
9
+ leneda_client-0.3.0.dist-info/WHEEL,sha256=wXxTzcEDnjrTwFYjLPcsW_7_XihufBwmpiBeiXNBGEA,91
10
+ leneda_client-0.3.0.dist-info/top_level.txt,sha256=PANScm25ep7WLjKiph0fhJPb8s_sa_uLHemnBpQBaJ8,7
11
+ leneda_client-0.3.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (78.1.1)
2
+ Generator: setuptools (80.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 fedus
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.
@@ -1,9 +0,0 @@
1
- leneda/__init__.py,sha256=-BHIXBfTTbX6EKDHr2Bq7rPzsPNYrrkgs9AJqWJR_1Q,732
2
- leneda/client.py,sha256=NFZczkNkvTBZOSU5FCQ9A_TE_x4s7eX9iKrWqzeubr4,8393
3
- leneda/models.py,sha256=jdU2cIZZDExUSiSfz9zaYjJepr0m3v_x5b1fyOaEI8Q,7930
4
- leneda/obis_codes.py,sha256=VfsJQN1U80eZ5g1bIteDCLkkmBQ0AIkkm_zNAeM1Dog,7507
5
- leneda/version.py,sha256=K2uqgpmNuApS_OV5kcSoshVG9LFQlr-es1HuZALwCq4,50
6
- leneda_client-0.2.0.dist-info/METADATA,sha256=CqBEdkRXJUCOk9qSKmv9ZBNIgzov_9mroXa5v7i_pcA,1994
7
- leneda_client-0.2.0.dist-info/WHEEL,sha256=lTU6B6eIfYoiQJTZNc-fyaR6BpL6ehTzU3xGYxn2n8k,91
8
- leneda_client-0.2.0.dist-info/top_level.txt,sha256=PANScm25ep7WLjKiph0fhJPb8s_sa_uLHemnBpQBaJ8,7
9
- leneda_client-0.2.0.dist-info/RECORD,,