Skip to main content

Energiinfo API package

Project description

energiinfo

The energiinfo is a python wrapper for energiinfo API

The background color is #ffffff for light mode and #000000 for dark mode. Simple code example:

from energiinfo.api import EnergiinfoClient
from datetime import datetime

siteid='13'
apiurl='https://api4.energiinfo.se'
username='username'
password='password'
# Initialize the api, this will not make an external call
api = EnergiinfoClient(apiurl,siteid)

# Authenticate against external api using username and password,
token = api.authenticate(username,password)
if api.getStatus() == "ERR":
  errorMessage = api.getErrorMessage();
  print(f"ErrorMessage: {errorMessage}")
  exit(0)
else:
    print(f"Successfully logged in token={token}")

# Initialize using token, this will make external call
token = api.get_access_token()
api = EnergiinfoClient(apiurl,'13',token)
if api.getStatus() == "OK":
  print(f"Token successfully authenticated")
else:
  errorMessage = api.getErrorMessage();
  print(f"Failed to initialize with token: {errorMessage}")
  exit(0)

# If you want a long-term token you need to call authenticateToken every now and then to validate token is still valid
# if not you may need to reauthenticate with username, password as above. the token if you plan on running this on a schedule
api.authenticateToken(token)
if api.getStatus() == "OK":
  print("====== avbrottsinfo ======")
  avbrottsinfo = api.get_interruptions()
  print(avbrottsinfo)
  print("====== meteringpoints ======")
  meter_list = api.get_metering_points()
  print(meter_list)
  print("====== invoices ======")
  invoices = api.get_invoices('2024')
  print(invoices)
  print("====== period 2023 ======")
  period_data = api.get_period_values(meter_list[0]['meteringpoint_id'], '2023', 'ActiveEnergy', 'month')
  print(period_data)
  # Sum up the energy usage for the day
  total = sum(float(value["value"]) for value in period_data)
  print(f"Total energy use for the year 2023  {total}")
  latest_hour_dict = max(period_data, key=lambda x: x['time'])
  print(f"Latest hour for 2023: {latest_hour_dict['time']}")
  print("====== period 202402 ======")
  period_data = api.get_period_values(meter_list[0]['meteringpoint_id'], '202402', 'ActiveEnergy', 'day')
  print(period_data)
  print("====== period 20240225 ======")
  period_data = api.get_period_values(meter_list[0]['meteringpoint_id'], '20240225', 'ActiveEnergy', 'hour')
  print(period_data)
  print("====== period 20240225-20240226 ======")
  period_data = api.get_period_values(meter_list[0]['meteringpoint_id'], '20240225-20240226', 'ActiveEnergy', 'hour')
  print(period_data)
  print("====== period 2024030800 ======")
  period_data = api.get_period_values(meter_list[0]['meteringpoint_id'], '2024030800', 'ActiveEnergy', 'quarter')
  print(period_data)

  # Invalidate token
  api.logout()
else:
  errorMessage = api.getErrorMessage();
  print(f"Failed to authenticate token: {errorMessage}")

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

energiinfo-1.0.4.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

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

energiinfo-1.0.4-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

Details for the file energiinfo-1.0.4.tar.gz.

File metadata

  • Download URL: energiinfo-1.0.4.tar.gz
  • Upload date:
  • Size: 16.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.0

File hashes

Hashes for energiinfo-1.0.4.tar.gz
Algorithm Hash digest
SHA256 460511a0e3031ab5ab6e1593003229aeeb23d02b1b7a2955e5141e16f373557c
MD5 445ad879c6c47e887ef9663ff341edca
BLAKE2b-256 4bf34760a47fefce51ce5267b2b9f2d600e62cf834f5c1a18ac966459fe83c24

See more details on using hashes here.

File details

Details for the file energiinfo-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: energiinfo-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 17.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.0

File hashes

Hashes for energiinfo-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 11a5cf300a8c7bfa5818752e3eb61d9ec30312a4b6fc2b61603c1b8ad127f41c
MD5 ada21e808141d3aea898584bc262cb58
BLAKE2b-256 7f153698f58b2705e5ed8d064305b4573cf0cfd6cb3d7b7900281ad20c79967f

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