Package: tibber.py
tibber.py - The Python wrapper for the Tibber APIHead over tohttps://tibberpy.readthedocs.io/en/latest/to read the documentation for this library!tibber.py is a python wrapper package for communication with theTibber API.
This package aims to cover all functionalities of the Tibber API in the most beginner-friendly way. You can read all the capabilites of the API and explore it
withTibbers' API explorer.Every field of the API types should be found in the correspondingtibber.type(e.g. thesize: Intfield ofHometype, should be accessed in the tibber.py package as:Home.sizeand return an int). In addition to these "1 to 1",
field to property/method functions, there might be extra properties or methods for simpler access of common properties
(one example: it is possible to simply writehome.address1instead ofhome.address.address1, although the latter is
also supported). The docstrings of thetibber.typescorrespond to the description of each type in the api explorer
docs (located on the right side of the Tibber API explorer).InstallationInstall via pippython -m pip install tibber.pyRequirementstibber.py depends ongql,gql[aiohttp],gql[websockets]andgraphql-core. As of now, the projectrequires Python 3.9+.
Soon the project will most likely support Python 3.7 and up.ExamplesGetting basic account dataimporttibberaccount=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 dataimporttibberaccount=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)# 195print(home.type)# "HOUSE"print(home.number_of_residents)# 5print(home.primary_heating_source)# "GROUND"print(home.has_ventilation_system)# Falseprint(home.main_fuse_size)# 25Reading historical dataimporttibberaccount=tibber.Account(tibber.DEMO_TOKEN)home=account.homes[0]# Get the first 10 hours of consumption availablehour_data=home.fetch_consumption("HOURLY",first=10)# Get the last 3 days of consumptionday_data=home.fetch_consumption("DAILY",last=3)# Get last 2 monthsmonth_data=home.fetch_consumption("MONTHLY",last=2)forhourinhour_data:print(hour.from_time)print(hour.to_time)print(f"{hour.unit_price}{hour.currency}")print(hour.consumption)print(hour.cost)Reading live measurementsNote how you can register multiple callbacks for the same event. These will be run
in asynchronously (at the same time)!importtibberaccount=tibber.Account(tibber.DEMO_TOKEN)home=account.homes[0]@home.event("live_measurement")asyncdefshow_current_power(data):print(data.power)# Multiple callback functions for the same event!@home.event("live_measurement")asyncdefshow_accumulated_cost(data):print(f"{data.accumulated_cost}{data.currency}")defwhen_to_stop(data):returndata.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 herehome.start_live_feed(user_agent="UserAgent/0.0.1",exit_condition=when_to_stop)Contributing to the projectI'm glad to see you're interested in contributing! When programming, I tend to follow some style guides
and urge you to do the same. Here are two important videos which cover the most important styles to follow
and how to do so.Never nest,How to name variables.To start contributing to the project, create your own fork of this repository on GitHub by clicking "Fork"
in the top right corner. Clone your fork of this project to your own computer usinggit.
Now create a new branch named a short 1-3 word long name, hyphenated (this-is-hyphenated), and prefixed with
one of these:refactor/- A refactoring of pre-existing codebug/- Fixing a bugfeature/- Adding a featureother/- If it really doesn't fit any of the aboveHere are some example branch names:refactor/async-callbacksbug/query-executionfeature/live-dataOnce you have created a new branch, play around, code your changes and then add a pull request back to this
GitHub repository!