thorcast_api_client 0.1.2__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.
- thorcast_api_client/__init__.py +0 -0
- thorcast_api_client/auth.py +34 -0
- thorcast_api_client/client.py +56 -0
- thorcast_api_client/config.py +5 -0
- thorcast_api_client/exceptions.py +19 -0
- thorcast_api_client-0.1.2.dist-info/METADATA +15 -0
- thorcast_api_client-0.1.2.dist-info/RECORD +8 -0
- thorcast_api_client-0.1.2.dist-info/WHEEL +4 -0
|
File without changes
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
from thorcast_api_client.config import API_BASE_URL
|
|
3
|
+
|
|
4
|
+
class AuthManager:
|
|
5
|
+
"""Gère l'authentification et le rafraîchissement du token JWT."""
|
|
6
|
+
|
|
7
|
+
def __init__(self, identifier: str, password: str):
|
|
8
|
+
self.identifier = identifier
|
|
9
|
+
self.password = password
|
|
10
|
+
self.token = None
|
|
11
|
+
self.refresh_token = None
|
|
12
|
+
self.is_active = None
|
|
13
|
+
self.user_id = None
|
|
14
|
+
|
|
15
|
+
def authenticate(self):
|
|
16
|
+
"""Récupère un token JWT"""
|
|
17
|
+
url = f"{API_BASE_URL}/backend/auth/token/"
|
|
18
|
+
payload = {"email": self.identifier, "password": self.password}
|
|
19
|
+
|
|
20
|
+
response = requests.post(url, json=payload)
|
|
21
|
+
if response.status_code == 200:
|
|
22
|
+
data = response.json()
|
|
23
|
+
self.token = data["access"]
|
|
24
|
+
self.refresh_token = data["refresh"]
|
|
25
|
+
self.is_active = data.get("is_active", None)
|
|
26
|
+
self.user_id = data.get("user_id", None)
|
|
27
|
+
else:
|
|
28
|
+
raise Exception(f"Erreur d'authentification: {response.text}")
|
|
29
|
+
|
|
30
|
+
def get_headers(self):
|
|
31
|
+
"""Retourne les headers avec le token d'accès"""
|
|
32
|
+
if not self.token:
|
|
33
|
+
raise Exception("Token non défini, veuillez vous authentifier.")
|
|
34
|
+
return {"Authorization": f"Bearer {self.token}"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
from thorcast_api_client.auth import AuthManager
|
|
3
|
+
from thorcast_api_client.config import API_BASE_URL
|
|
4
|
+
from thorcast_api_client.exceptions import APIClientError, AuthenticationError, RateLimitExceeded, ServerError
|
|
5
|
+
|
|
6
|
+
class ThorCastClient:
|
|
7
|
+
"""Client pour interagir avec l'API ThorCast."""
|
|
8
|
+
|
|
9
|
+
def __init__(self, username: str, password: str):
|
|
10
|
+
self.auth = AuthManager(username, password)
|
|
11
|
+
self.auth.authenticate()
|
|
12
|
+
|
|
13
|
+
def _request(self, method: str, endpoint: str, **kwargs):
|
|
14
|
+
"""Méthode générique pour effectuer une requête."""
|
|
15
|
+
url = f"{API_BASE_URL}{endpoint}"
|
|
16
|
+
headers = self.auth.get_headers()
|
|
17
|
+
|
|
18
|
+
response = requests.request(method, url, headers=headers, **kwargs)
|
|
19
|
+
|
|
20
|
+
if response.status_code == 401:
|
|
21
|
+
raise AuthenticationError(401, "Echec d'authentification, token invalide.")
|
|
22
|
+
elif response.status_code == 429:
|
|
23
|
+
raise RateLimitExceeded(429, "Limite de requêtes dépassée.")
|
|
24
|
+
elif response.status_code >= 500:
|
|
25
|
+
raise ServerError(response.status_code, "Erreur interne du serveur.")
|
|
26
|
+
elif not response.ok:
|
|
27
|
+
raise APIClientError(response.status_code, "Erreur inconnue.")
|
|
28
|
+
|
|
29
|
+
return response.json()
|
|
30
|
+
|
|
31
|
+
def get_lt_curves_versions(self, prms: list):
|
|
32
|
+
"""Liste les versions disponibles des courbes de charge LT."""
|
|
33
|
+
endpoint = f"/backend/thorcast/v1/lt_curves/versions/?prms={','.join(prms)}"
|
|
34
|
+
return self._request("GET", endpoint)
|
|
35
|
+
|
|
36
|
+
def get_lt_curves(self, prms: list, sd: str, ed: str, versions: list = None, tz: str = "UTC"):
|
|
37
|
+
"""Récupère les courbes de charge LT."""
|
|
38
|
+
endpoint = f"/backend/thorcast/v1/lt_curves/?prms={','.join(prms)}&sd={sd}&ed={ed}&tz={tz}"
|
|
39
|
+
if versions:
|
|
40
|
+
endpoint += f"&versions={','.join(versions)}"
|
|
41
|
+
return self._request("GET", endpoint)
|
|
42
|
+
|
|
43
|
+
def get_historical_curves(self, prms: list, sd: str, ed: str, tz: str = "UTC"):
|
|
44
|
+
"""Récupère les courbes de charge historiques."""
|
|
45
|
+
endpoint = f"/backend/thorcast/v1/historical_load_curves/?prms={','.join(prms)}&sd={sd}&ed={ed}&tz={tz}"
|
|
46
|
+
return self._request("GET", endpoint)
|
|
47
|
+
|
|
48
|
+
def get_catalog_versions(self, catalogs: list, sd: str, ed: str):
|
|
49
|
+
"""Liste les versions disponibles des courbes de charge LT."""
|
|
50
|
+
endpoint = f"/backend/thorcast/v1/catalog_curves/versions/?catalogs={','.join(catalogs)}&sd={sd}&ed={ed}"
|
|
51
|
+
return self._request("GET", endpoint)
|
|
52
|
+
|
|
53
|
+
def get_catalog_curves(self, ids: list, tz: str = "UTC"):
|
|
54
|
+
"""Récupère les courbes de charge catalog."""
|
|
55
|
+
endpoint = f"/backend/thorcast/v1/catalog_curves/?ids={','.join(ids)}&tz={tz}"
|
|
56
|
+
return self._request("GET", endpoint)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
class APIClientError(Exception):
|
|
2
|
+
"""Exception générique pour les erreurs API."""
|
|
3
|
+
|
|
4
|
+
def __init__(self, status_code, message):
|
|
5
|
+
self.status_code = status_code
|
|
6
|
+
self.message = message
|
|
7
|
+
super().__init__(f"API Error {status_code}: {message}")
|
|
8
|
+
|
|
9
|
+
class AuthenticationError(APIClientError):
|
|
10
|
+
"""Erreur spécifique à l'authentification (ex: JWT expiré, mauvais identifiants)."""
|
|
11
|
+
pass
|
|
12
|
+
|
|
13
|
+
class RateLimitExceeded(APIClientError):
|
|
14
|
+
"""Erreur lorsque la limite de requêtes est dépassée."""
|
|
15
|
+
pass
|
|
16
|
+
|
|
17
|
+
class ServerError(APIClientError):
|
|
18
|
+
"""Erreur interne du serveur API."""
|
|
19
|
+
pass
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: thorcast_api_client
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary: Un client Python pour interagir avec l'API ThorCast
|
|
5
|
+
Author: JBCAYRE
|
|
6
|
+
Author-email: jcayre@mint.eco
|
|
7
|
+
Requires-Python: >=3.8,<4.0
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Requires-Dist: requests (>=2.26.0,<3.0.0)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
thorcast_api_client/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
thorcast_api_client/auth.py,sha256=BK0JY2W2uJ9CBEAbCTZJfeWcCg9wkXBZG0Lt42s6S4g,1303
|
|
3
|
+
thorcast_api_client/client.py,sha256=4k5cwm7J8R9BKqThNstUfLX88OWMC30BPDdewspWRoU,2805
|
|
4
|
+
thorcast_api_client/config.py,sha256=wITbKmrJAQ6aefoLc49mWaIajldD_VqvO-I0kwseXnE,155
|
|
5
|
+
thorcast_api_client/exceptions.py,sha256=bzoZtKJiCQwxvtx3wG5pt8ePhHovsje2NdVSxYUTNU0,633
|
|
6
|
+
thorcast_api_client-0.1.2.dist-info/METADATA,sha256=RjDkpQG9XAwVGuwS9oBcfDbiEI7YWSj38JOhwHUY-vA,592
|
|
7
|
+
thorcast_api_client-0.1.2.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
|
|
8
|
+
thorcast_api_client-0.1.2.dist-info/RECORD,,
|