Yoctopuce Python API

raw JSON →
2.1.12672 verified Mon Apr 27 auth: no python

Official Python API for Yoctopuce sensors and actuators. Provides access to USB and networked Yoctopuce devices. Current version 2.1.12672, released regularly.

pip install yoctopuce
error ModuleNotFoundError: No module named 'yoctopuce'
cause Package not installed or misspelled.
fix
pip install yoctopuce
error AttributeError: module 'yoctopuce' has no attribute 'YAPI'
cause Importing yoctopuce directly instead of its submodules.
fix
Use 'from yoctopuce.yapi import YAPI'
error YAPI.RegisterHub failed: timeout
cause Hub URL incorrect or network issue; IPv6 address can cause timeout.
fix
Check hub URL, use IPv4, or ensure VirtualHub is running.
breaking YAPI.PreregisterHub() may timeout with IPv6 addresses; use IPv4 or ensure DNS resolution works.
fix Use IPv4 address explicitly, e.g., YAPI.PreregisterHub('192.168.1.10')
gotcha YAPI.RegisterHub() must be called after PreregisterHub() if using non-default hub.
fix Always call YAPI.PreregisterHub() then YAPI.RegisterHub() for each hub.
deprecated YAPI.RegisterHub() without PreregisterHub() may be removed in future versions.
fix Always use PreregisterHub before RegisterHub.

Quickstart to list first Yoctopuce sensor. Preregister 'usb' for USB, or an IP address for networked hubs.

from yoctopuce.yapi import YAPI
from yoctopuce.ysensor import YSensor

# Register a hub (adjust as needed)
YAPI.PreregisterHub('usb')
# Use default hub URL 'usb' for USB devices
YAPI.RegisterHub('usb')
sensor = YSensor.FirstSensor()
if sensor:
    print(f"Sensor: {sensor.get_friendlyName()}, value: {sensor.get_currentValue()}")
YAPI.FreeAPI()