A python wrapper for the Tibber API.
Project description
tibber.py - The Python wrapper for the Tibber API
Note that this is NOT pyTibber which is the official python wrapper endorsed by Tibber themselves.
tibber.py is an unofficial python wrapper package for communication with the Tibber API. This package aims to cover all functionalities of the Tibber API in the most beginner-friendly modern Pythonic way. You can read all the capabilites of the API and explore it with Tibbers' API explorer. For documentation on how to use tibber.py head over to https://tibberpy.readthedocs.io/en/latest/.
Every field of the API types should be found in the corresponding tibber.type (e.g. the size: Int field of Home
type, should be accessed in the tibber.py package as: Home.size and return an int). In addition to these "1 to 1" relations between the tibber.py package and the Tibber API, there might be extra properties or methods for simpler access of common properties
(one example: it is possible to simply write home.address1 instead of home.address.address1, although the latter is
also supported). The docstrings of the tibber.types correspond to the description of each type in the api explorer
docs (located on the right side of the Tibber API explorer).
Do you want to ask a question, report an issue, or even showcase your project that uses tibber.py? 🤩
Find out where to post by checking out this overview.
Installation
Install via pip
python -m pip install tibber.py
Requirements
tibber.py depends on gql, gql[aiohttp], gql[websockets] and graphql-core. tibber.py supports Python versions 3.7 and up!
Examples
Getting basic account data
import tibber
account = tibber.Account(tibber.DEMO_TOKEN) # Log in with an access token. All information gets updated here and stored in cache.
# These properties are retrieved from cache and DO NOT reflect data at the given time
# (but rather the data as it was when it last was cached)
print(account.name) # "Arya Stark"
print(account.user_id) # "dcc2355e-6f55-45c2-beb9-274241fe450c"
print(account.account_type) # ["tibber", "customer"]
print(account.login) # "arya@winterfell.com"
# To update the cache with new data straight from the tibber api, run this:
account.update()
# Now use the updated data as you would before:
print(account.name)
Getting basic home data
import tibber
account = tibber.Account(tibber.DEMO_TOKEN)
home = account.homes[0]
print(home.id) # "cc83e83e-8cbf-4595-9bf7-c3cf192f7d9c"
print(home.time_zone) # "Europe/Stockholm"
print(home.app_nickname) # "Vitahuset"
print(home.app_avatar) # "FLOORHOUSE3"
print(home.size) # 195
print(home.type) # "HOUSE"
print(home.number_of_residents) # 5
print(home.primary_heating_source) # "GROUND"
print(home.has_ventilation_system) # False
print(home.main_fuse_size) # 25
Reading historical consumption data
import tibber
account = tibber.Account(tibber.DEMO_TOKEN)
home = account.homes[0]
# Get the first 10 hours of consumption available
hour_data = home.fetch_consumption("HOURLY", first=10)
# Get the last 3 days of consumption
day_data = home.fetch_consumption("DAILY", last=3)
# Get last 2 months
month_data = home.fetch_consumption("MONTHLY", last=2)
for hour in hour_data:
print(hour.from_time)
print(hour.to_time)
print(f"{hour.unit_price}{hour.currency}")
print(hour.consumption)
print(hour.cost)
Reading historical price data
import tibber
import datetime
import base64
account = tibber.Account(tibber.DEMO_TOKEN)
price_info = account.homes[0].current_subscription.price_info
# The API requires the date to be passed as a base64 encoded string with timezone information
date = datetime.datetime(2025, 1, 1, 0, 0, 0)
encoded_date = base64.b64encode(date.astimezone().isoformat().encode("utf-8")).decode("utf-8")
# Only HOURLY and DAILY
connection = price_info.fetch_range("HOURLY", first=10, after=encoded_date)
connection.nodes # A list of Price objects
Reading live measurements
Note how you can register multiple callbacks for the same event. These will be run in asynchronously (at the same time)!
import tibber
account = tibber.Account(tibber.DEMO_TOKEN)
home = account.homes[0]
@home.event("live_measurement")
async def show_current_power(data):
print(data.power)
# Multiple callback functions for the same event!
@home.event("live_measurement")
async def show_accumulated_cost(data):
print(f"{data.accumulated_cost} {data.currency}")
def when_to_stop(data):
return data.power < 1500
# Start the live feed. This runs until data.power is less than 1500.
# If a user agent was not defined earlier, this will be required here
home.start_live_feed(user_agent = "UserAgent/0.0.1", exit_condition = when_to_stop)
Getting quarter hourly price information
import tibber
account = tibber.Account(tibber.DEMO_TOKEN)
subscription = account.homes[0].current_subscription
# The API requires the date to be passed as a base64 encoded string with timezone information
date = datetime.datetime(2025, 1, 1, 0, 0, 0)
encoded_date = base64.b64encode(date.astimezone().isoformat().encode("utf-8")).decode("utf-8")
# QUARTER_HOURLY, HOURLY or DAILY
connection = subscription.fetch_price_info_range("QUARTER_HOURLY", first=10, after=encoded_date)
connection.nodes # A list of Price objects
Getting today or tomorrows quarter hourly price information
import tibber
account = tibber.Account(tibber.DEMO_TOKEN)
subscription = account.homes[0].current_subscription
# QUARTER_HOURLY or HOURLY
price_info = subscription.fetch_price_info("QUARTER_HOURLY")
price_info.today # List of 96 Price objects
price_info.tomorrow # This data is populated once a day
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 tibber_py-0.7.1.tar.gz.
File metadata
- Download URL: tibber_py-0.7.1.tar.gz
- Upload date:
- Size: 24.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.24
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dc3890b1e9e58257ff5ef845fc72fe9c8115f00e741c7cbd541976226ec26f32
|
|
| MD5 |
54a615fa4ef714d5ca88b0ea34bb32b1
|
|
| BLAKE2b-256 |
fa0ef6512eb7a9ab329664a020699010671d94f40a250f0dcd8f95085317eff7
|
File details
Details for the file tibber_py-0.7.1-py3-none-any.whl.
File metadata
- Download URL: tibber_py-0.7.1-py3-none-any.whl
- Upload date:
- Size: 36.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.24
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d6990d6037ff628a0354e5c66d81d7b7655ecf2bd0a5b995ad3e75dfd4d68f5e
|
|
| MD5 |
4b8bd0d3fc603d12ac777549738b71e6
|
|
| BLAKE2b-256 |
c1bfc198b6dae6cd37c48f165fbb5fb7e4549a2ece0eaac3e956630148a7e4a2
|