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.0.1.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.0.1-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file hidroconta-1.0.1.tar.gz.

File metadata

  • Download URL: hidroconta-1.0.1.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.0.1.tar.gz
Algorithm Hash digest
SHA256 eb84dc271514ddb93fa595165c4a04e831397f6d7746dcfab6687f8519b05c69
MD5 7fc71d8acb4c2b04778190ca95c58849
BLAKE2b-256 1c7fff30f21154c63dc38f6efdcff3160513f4435e97ac96c32d41e652e5e7e5

See more details on using hashes here.

File details

Details for the file hidroconta-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: hidroconta-1.0.1-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.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8cb5a7b3151ca2eb03abd039d51d59c063e9f046fef654c930261aa763308341
MD5 268c2bf3236560d05acf2835b06af4d4
BLAKE2b-256 cbed21fddf14faf817646fad483a0a8aa86f367b3086e528a30b0745db4acf1a

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