A library to interface with a Bambu Labs 3D printer and query status and information
Project description
Introduction
A library to interface with a Bambu Labs 3D printer and query status and information
Dependencies
This driver depends on:
Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading the Adafruit library and driver bundle or individual libraries can be installed using circup.
Installing from PyPI
On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally from PyPI. To install for current user:
pip3 install circuitpython-bambulabs
To install system-wide (this may be required in some cases):
sudo pip3 install circuitpython-bambulabs
To install in a virtual environment in your current project:
mkdir project-name && cd project-name
python3 -m venv .venv
source .env/bin/activate
pip3 install circuitpython-bambulabs
Installing to a Connected CircuitPython Device with Circup
Make sure that you have circup installed in your Python environment. Install it with the following command if necessary:
pip3 install circup
With circup installed and your CircuitPython device connected use the following command to install:
circup install bambulabs
Or the following command to update an existing version:
circup update
Obtaining Your Printer Credentials and Save in settings.toml
Login to MakerWorld.
Open the dev-tools (F12 in most browsers) and select Application > Cookies > https://makerworld.com.
Copy the token string and save it as BAMBU_ACCESS_TOKEN in settings.toml.
Access https://makerworld.com/api/v1/design-user-service/my/preference and copy uid as USER_ID.
Access https://makerworld.com/api/v1/iot-service/api/user/bind and copy dev_id as DEVICE_ID.
On your printer, go to Settings and obtain the IP address and copy it as BAMBU_IP.
You will need a settings.toml file with the following to connect via MQTT:
CIRCUITPY_WIFI_SSID = “your_wifi_ssid”
CIRCUITPY_WIFI_PASSWORD = “your_wifi_password”
BAMBU_BROKER = os.getenv(“BAMBU_BROKER”)
ACCESS_TOKEN = os.getenv(“BAMBU_ACCESS_TOKEN”)
USER_ID = os.getenv(“USER_ID”)
DEVICE_ID = “your_printer_serial_number”
BAMBU_IP = “your_printer_IP_address”
Misc. information
This library queries your Bambu Labs 3D printer via the Bambu Cloud using MQTT 5.0. Local mode is not supported due to it using MQTT 3.1.1. Issuing commands to your Bambu printer is out of scope for this library.
Usage Example
import json
import os
import wifi
import bambulabs as bl
# You will need a settings.toml file with the following to connect via MQTT:
# bambu_broker = os.getenv("BAMBU_BROKER")
# access_token = os.getenv("BAMBU_ACCESS_TOKEN")
# user_id = os.getenv("USER_ID")
# DEVICE_ID = "your_printer_serial_number"
# Set up networking
print("Connecting to AP...")
wifi.radio.connect(os.getenv("CIRCUITPY_WIFI_SSID"), os.getenv("CIRCUITPY_WIFI_PASSWORD"))
print(f"Connected to {os.getenv('CIRCUITPY_WIFI_SSID')}")
print(f"My IP address: {wifi.radio.ipv4_address}")
device_id = os.getenv("DEVICE_ID")
printer = bl.BambuPrinter(bl.BambuPrinter.__init__, device_id)
printer.connect()
status = printer.pushall()
if status is None:
print("Timed out waiting for pushall response.")
else:
# Print out each individual status
print("--- Printer Status ---")
print(f"State: {status.gcode_state}")
print(f"File: {status.gcode_file}")
print(f"Job: {status.subtask_name}")
print(f"Progress: {status.print_percentage}%")
print(f"Remaining: {status.remaining_time} min")
print(f"Layer: {status.current_layer} / {status.total_layers}")
print(f"Print speed: {status.print_speed}")
print(f"Print error: {status.print_error_code}")
print(f"Nozzle temp: {status.nozzle_temperature} / {status.nozzle_temperature_target} C")
print(f"Bed temp: {status.bed_temperature} / {status.bed_temperature_target} C")
print(f"Chamber temp: {status.chamber_temperature} C")
print(f"Part fan: {status.part_fan_speed}")
print(f"Aux fan: {status.aux_fan_speed}")
print(f"Chamber fan: {status.chamber_fan_speed}")
print(f"Nozzle type: {status.nozzle_type}")
print(f"Nozzle diameter: {status.nozzle_diameter} mm")
print(f"WiFi signal: {status.wifi_signal}")
print(f"Light state: {status.light_state}")
print(f"Firmware version: {status.firmware_version}")
print()
# Print the entire JSON response
print("--- Raw JSON ---")
print(json.dumps(status.raw))
Documentation
API documentation for this library can be found on Read the Docs.
For information on building library documentation, please check out this guide.
Contributing
Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.
This library was created with the assistance of Claude. (I know, I know…)
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 circuitpython_bambulabs-1.0.0.tar.gz.
File metadata
- Download URL: circuitpython_bambulabs-1.0.0.tar.gz
- Upload date:
- Size: 27.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fde0ff9ad5c31041a3114796b3c029db67776644957fe1e92bdb53694fece5f3
|
|
| MD5 |
e443b6162e2687623855ab4633a01f0c
|
|
| BLAKE2b-256 |
d65f9e0e16e9d8c76ea86ba19a2626e259896ef3aac8631b9f41b74fb3e51967
|
File details
Details for the file circuitpython_bambulabs-1.0.0-py3-none-any.whl.
File metadata
- Download URL: circuitpython_bambulabs-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ab1d33872b5fd36cb5e1a2426dee2806a9bf2b3a28dc2e620bb37172995b62e2
|
|
| MD5 |
ad62771fc15e73986342e4922828ade8
|
|
| BLAKE2b-256 |
8808af9ef3086ce38bf38182580fc066327ca1b9b3a1d07e7fdf4fcb691ef458
|