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 Common errors
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.
Warnings
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.
Imports
- YAPI wrong
import yoctopucecorrectfrom yoctopuce.yapi import YAPI - YModule wrong
from yoctopuce import YModulecorrectfrom yoctopuce.ymodule import YModule - YSensor wrong
from yoctopuce import YSensorcorrectfrom yoctopuce.ysensor import YSensor
Quickstart
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()