API to easily access Demeter REST API provided by Hidroconta S.A.U.
Project description
Integrations-PythonAPI
API Python para facilitar el acceso a los endpoints de la interfaz REST de Demeter
La API permite la gestión de grandes cantidades de datos mediante la librerÃa Pandas, siempre y cuando se utilice la siguiente directiva en las llamadas a los métodos:
# Pandas = True returns a pandas dataframe instead a json
La forma de usar la API es la siguiente:
- Importar los modulos deseados:
import hidroconta.api as demeter
import hidroconta.types as hidrotypes
import pandas as pd
import datetime
import hidroconta.endpoints as hidroenpoints
- Seleccionar el servidor con el cual se quiere comunicar (se puede modificar en todo momento):
# Set server
demeter.set_server(hidroendpoints.Server.MAIN)
- Realizar el login en dicho servidor
# Login
demeter.login('USERNAME', 'PASSWORD')
Una vez seguidos los anteriores pasos, se puede realizar cualquier consulta sobre el sistema. Algunas de ellas son:
- Búsqueda
# Search
df = demeter.search(text='SAT', element_types=[hidrotypes.Element.COUNTER, hidrotypes.Element.ANALOG_INPUT, hidrotypes.Element.RTU], status=hidrotypes.Status.ENABLED, pandas=True)
print(df)
- Obtención de historicos
# Get historics
df = demeter.get_historics(start_date=datetime.datetime.now(), end_date=datetime.datetime.now(), element_ids=[1000], subtype=hidrotypes.AnalogInputHist.subtype, subcode=[hidrotypes.AnalogInputHist.subcode], pandas=True)
print(df)
- Obtención de elementos
# Get
df = demeter.get_rtus(element_id=17512, pandas=True)
print(df)
La API define también una excepción especial cuando la llamada al endpoint de Demeter no devuelve el resultado esperado. La excepción de denomina "DemeterStatusCodeException" y contiene el código de error HTTP.
# Exception treatment
try:
df = demeter.get_rtus(element_id=17512, pandas=True)
except demeter.DemeterStatusCodeException as status_code:
print('Error {}'.format(status_code))
- Por último, se deberÃa hacer un logout en el servidor
demeter.logout()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hidroconta-1.1.0.tar.gz.
File metadata
- Download URL: hidroconta-1.1.0.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a9eae37078e2501cac21d5a38b421a0496e93358d4e96747dc6da412392c4767
|
|
| MD5 |
a0df68f2d00f2810095539cd97008823
|
|
| BLAKE2b-256 |
61405c321f1af2efec42f223383666ad3deefcc633aaca87dba6c524dfd86c29
|
File details
Details for the file hidroconta-1.1.0-py3-none-any.whl.
File metadata
- Download URL: hidroconta-1.1.0-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b09753218333deb069eb0299c5bc6bbde7ef914a7a6b884a29a7866a8dd13a61
|
|
| MD5 |
5a6c2cdc0b22410556f5e54d4a3a5dde
|
|
| BLAKE2b-256 |
f12e773a88632d836762c650d3e9093ded789567ac4a8ff1d46edb2406534123
|