Skip to main content

Python library for Busy Bar API

Project description

busylib

A simple and intuitive Python client for interacting with the Busy Bar API. This library allows you to programmatically control the device's display, audio, and assets.

Features

  • Easy-to-use API for all major device functions.
  • Upload and manage assets for your applications.
  • Control the display by drawing text and images.
  • Play and stop audio files.
  • Built-in validation for device IP addresses.

Installation

You can install busylib directly from PyPI:

pip install busylib

Usage

First, import and initialize the BusyBar client with IP address of your device.

from busylib import BusyBar

bb = BusyBar("10.0.4.20")

version_info = bb.get_version()
print(f"Device version: {version_info.version}")

You can also use context manager.

from busylib import BusyBar

with BusyBar("10.0.4.20") as bb:
    version_info = bb.get_version()
    print(f"Device version: {version_info.version}")

API Examples

Here are some examples of how to use the library to control your Busy Bar device.

Uploading an Asset

You can upload files (like images or sounds) to be used by your application on the device.

with open("path/to/your/image.png", "rb") as f:
    file_bytes = f.read()
    response = bb.upload_asset(
        app_id="my-app",
        filename="logo.png",
        data=file_bytes
    )
    print(f"Upload result: {response.result}")


with open("path/to/your/sound.wav", "rb") as f:
    file_bytes = f.read()
    response = bb.upload_asset(
        app_id="my-app",
        filename="notification.wav",
        data=file_bytes
    )

Drawing on the Display

Draw text or images on the device's screen. The draw_on_display method accepts a DisplayElements object containing a list of elements to render.

from busylib import types


text_element = types.TextElement(
    id="hello",
    type="text",
    x=10,
    y=20,
    text="Hello, World!",
    display=types.DisplayName.FRONT,
)

image_element = types.ImageElement(
    id="logo",
    type="image",
    x=50,
    y=40,
    path="logo.png",
    display=types.DisplayName.BACK,
)

display_data = types.DisplayElements(
    app_id="my-app",
    elements=[text_element, image_element]
)

response = bb.draw_on_display(display_data)
print(f"Draw result: {response.result}")

Clearing the Display

To clear everything from the screen:

response = bb.clear_display()
print(f"Clear result: {response.result}")

Playing Audio

Play an audio file that you have already uploaded.

response = bb.play_audio(app_id="my-app", path="notification.wav")
print(f"Play result: {response.result}")

Stopping Audio

To stop any audio that is currently playing:

response = bb.stop_audio()
print(f"Stop result: {response.result}")

Deleting All Assets for an App

This will remove all files associated with a specific app_id.

response = bb.delete_app_assets(app_id="my-app")
print(f"Delete result: {response.result}")

Getting Device Status

You can get various status information from the device:

version = bb.get_version()
print(f"Version: {version.version}, Branch: {version.branch}")

status = bb.get_status()
if status.system:
    print(f"Uptime: {status.system.uptime}")
if status.power:
    print(f"Battery: {status.power.battery_charge}%")

brightness = bb.get_display_brightness()
print(f"Front brightness: {brightness.front}, Back brightness: {brightness.back}")

volume = bb.get_audio_volume()
print(f"Volume: {volume.volume}")

Working with Storage

You can manage files in the device's storage:

file_data = b"Hello, world!"
response = bb.write_storage_file(path="/my-app/data.txt", data=file_data)

file_content = bb.read_storage_file(path="/my-app/data.txt")
print(file_content.decode('utf-8'))

storage_list = bb.list_storage_files(path="/my-app")
for item in storage_list.list:
    if item.type == "file":
        print(f"File: {item.name} ({item.size} bytes)")
    else:
        print(f"Directory: {item.name}")

response = bb.create_storage_directory(path="/my-app/subdirectory")

response = bb.remove_storage_file(path="/my-app/data.txt")

Development

To set up a development environment, clone the repository and install the package in editable mode with test dependencies:

git clone https://github.com/busy-app/busylib
cd busylib
python3 -m venv .venv
source .venv/bin/activate
make install-dev

To run the tests:

make test

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

busylib-0.2.0.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

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

busylib-0.2.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file busylib-0.2.0.tar.gz.

File metadata

  • Download URL: busylib-0.2.0.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for busylib-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c5c656bba907872276d1d1c6fe9c1825383f4c9f31338746a598194b71fbc719
MD5 68d3e48779a950053e4090f96be72250
BLAKE2b-256 3365e62390b70fa729c9449ee88d53fb7b428dcd48cfb544408413205ea0ce60

See more details on using hashes here.

File details

Details for the file busylib-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: busylib-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for busylib-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 61baaccd9a896d35a0edfe7387cb03f8bae56ce81f1e63c06c0e5e8d6aee9524
MD5 f2f3b092fdf15ee12f08b0a7d1b7e8a2
BLAKE2b-256 5364098fd53681e7bca0f5d4bc206663356a5ab4245a3f7790578a9384aae44c

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