Python API

Use the Python APIs to integrate into your code

Sixfab offers Python API which allows a user to integrate UPS HAT v2 into their own project.

Requirements

Enabling the I2C on the Raspberry Pi.

To connect via I2C you’ll need to first enable the interface on the Pi. This is done via raspi-config which can be run in a terminal window:

sudo raspi-config

In the raspi-config user interface navigate to Interfacing Options >> I2C and answer the question "Would you like the ARM I2C interface to be enabled?" with . After the next reboot user pi will be able to use the I2C bus without root privileges.

Installation

Install pip3

If Python 3 has already been installed on the system, execute the command below to install pip3:

sudo apt -y install python3-pip

Install Power API

If pip3 has already been installed on the system, execute the command below to install power-api

pip3 install power-api

Uninstall

Use the following command to uninstall the library:

pip3 uninstall power-api

Upgrade

Use the following command to upgrade the library to the latest:

pip3 install power-api --upgrade

Methods

All the methods can be accessed from the API doc.

Examples

Here's a list of example actions that you can do using the Python API:

Usage

One of the simple ways to use the Python API is to use the Python Interpreter.

pi@raspberrypi:~ $ python3 Python 3.7.3 (default, Jul 25 2020, 13:03:44) [GCC 8.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> from power_api import SixfabPower, Definition, Event >>> api = SixfabPower() >>> api.get_battery_level() 90 >>> api.get_system_temp() 45.2