Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hidroconta-1.1.0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hidroconta-1.1.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

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

Hashes for hidroconta-1.1.0.tar.gz
Algorithm Hash digest
SHA256 a9eae37078e2501cac21d5a38b421a0496e93358d4e96747dc6da412392c4767
MD5 a0df68f2d00f2810095539cd97008823
BLAKE2b-256 61405c321f1af2efec42f223383666ad3deefcc633aaca87dba6c524dfd86c29

See more details on using hashes here.

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

Hashes for hidroconta-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b09753218333deb069eb0299c5bc6bbde7ef914a7a6b884a29a7866a8dd13a61
MD5 5a6c2cdc0b22410556f5e54d4a3a5dde
BLAKE2b-256 f12e773a88632d836762c650d3e9093ded789567ac4a8ff1d46edb2406534123

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page