Skip to main content

GoDice Python API

Overview

Use the GoDice Python API to integrate GoDice functionality into your own Python applications

PyPI version

Supported features:

  • Turn ON/OFF GoDice RGB LEDs
  • Read color (dots color)
  • Read battery level
  • Get notifications regarding the die state (Rolling or Stable and get the outcome number)
  • Use and configure different shells (D6, D20, D12 etc.)

Installation

pip install godice

Demo

Package includes a demo script showing up API features. Command to run it:

python -m godice.demo

It will discover GoDice devices nearby and connect to a closest one. Then it setups a dice color and starts listening to dice position changes, outputting a new number each time a dice is flipped.

Usage

One can import and use the API from any custom Python script like below

import asyncio
import bleak
import godice


async def main():
    mac = "00:00:00:00:00:00"

    # Python context manager (async with) is used for convenient connection handling
    # Device stays connected during `async with` block execution and auto-disconnected on block finish
    # Otherwise, dice.connect/dice.disconnect can be used instead 
    async with godice.create(mac, godice.Shell.D6, timeout=30) as dice:
		print("Connected")
        blue_rgb = (0, 0, 255)
        yellow_rgb = (255, 255, 0)
        off_rgb = (0, 0, 0)
        await dice.set_led(blue_rgb, yellow_rgb)

        color = await dice.get_color()
        battery_lvl = await dice.get_battery_level()
        print(f"Color: {color}")
        print(f"Battery: {battery_lvl}")
        
        print("Listening to position updates. Flip your dice")
        await dice.subscribe_number_notification(notification_callback)
        await asyncio.sleep(30)
        await dice.set_led(off_rgb, off_rgb)


async def notification_callback(number, stability_descr):
    """
    GoDice number notification callback.
    Called each time GoDice is flipped, receiving flip event data:
    :param number: a rolled number
    :param stability_descr: an additional value clarifying device movement state, ie stable, rolling...
    """
    print(f"Number: {number}, stability descriptor: {stability_descr}")


asyncio.run(main())

Metadata

Release files for godice 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for godice 0.1.2
File Size Uploaded Provenance
godice-0.1.2.tar.gz 10.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for godice 0.1.2
File Interpreter ABI Platform
godice-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 21.3 kB

Release files / godice-0.1.2.tar.gz

Download URL godice-0.1.2.tar.gz
Size 10.4 kB
Tags Source
SHA-256 checksum
How to use checksums
f5f41b5984afe0e9faae520dec3a76a2ec461e8d401eb538259c631c401d4e86
BLAKE2b-256 checksum
How to use checksums
372f88b827f58744e0e5c2b05b061861ab7bb92671fa290a6f0cd10da50e31a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.32.2

Release files / godice-0.1.2-py3-none-any.whl

Download URL godice-0.1.2-py3-none-any.whl
Size 10.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f2dd406fa9fdecf6f0449c108bbb3b878e3b96dddbb29760b66513d3dc37133c
BLAKE2b-256 checksum
How to use checksums
1a480f5e4cbd5f4f28267750a782949ecc9eb5cd0816f94a03ece38b77e25c20
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.32.2

Security for godice 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page