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 demeterpy as demeter
import demeterapitypes as tp
import pandas as pd
import datetime
import endpoints
  • Seleccionar el servidor con el cual se quiere comunicar (se puede modificar en todo momento):
# Set server
demeter.set_server(endpoints.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=[tp.Element.COUNTER, tp.Element.ANALOG_INPUT, tp.Element.RTU], status=tp.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=tp.AnalogInputHist.subtype, subcode=[tp.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.0.tar.gz (5.5 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.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: hidroconta-1.0.0.tar.gz
  • Upload date:
  • Size: 5.5 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.0.tar.gz
Algorithm Hash digest
SHA256 a93117f195267068d2338d868dac3131c00c402a7b77dc367bff1beeab92f8d4
MD5 1be94b96b83f6edcfb95f485c2099a1a
BLAKE2b-256 1348a6aa5f9d873bf3ae5393bdf49437e31cdf2e600dcd4faeedda6d566dcc92

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hidroconta-1.0.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.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a140fdfe03f139c7f2606f232cae2660d744772957ca08d4bf314614d43708f2
MD5 da042d101c72cb0e52db2eeb1780088d
BLAKE2b-256 49da8d6ce4c10c81aa5f59e13492d947c95b6018dad4b271d5c6df98c7433f94

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