Python API
The FrontPanel SDK can be used from Python through two APIs:
- Binding API (
import ok) — mirrors the C++ FrontPanel SDK, so its names match the C++ API reference and examples. Stable and complete. - Pythonic API (
import frontpanel) — a higher-level, idiomatic Python interface that mirrors the FrontPanel Platform (TypeScript) API: readable names, context managers that close the device for you, and typed exceptions.
Beta: the Pythonic API is new and its surface may change in future releases.
The Python packages can be found in the SDK’s API/Python/ folder, and require Python 3.11 or later.
Which should I use?
- Choose the Pythonic API if you are writing new Python code and want the most natural, idiomatic experience.
- Choose the Binding API if you are migrating an existing FrontPanel 5.x application, or following the C++ API reference and examples.
The Pythonic API is built on the Binding API, so installing it also installs the binding.
Using the Pythonic API
Install the Pythonic API from the SDK’s API/Python/ folder. Below, <sdk> is the folder where you installed the FrontPanel SDK. This single command also installs the Binding API it depends on:
pip install --no-index --find-links <sdk>/API/Python frontpanelCode language: HTML, XML (xml)--find-links points pip at the SDK folder, and --no-index keeps the install offline, so pip installs both packages straight from the files there. Then:
import frontpanelCode language: Bash (bash)Example Syntax
This opens the first available device, reads its identity, loads an FPGA configuration, and then uses the classic data port to set a wire and fire a trigger.
from frontpanel import DeviceManager
manager = DeviceManager()
# Opens the first available device; the `with` block closes it automatically.
with manager.open_device() as device:
info = device.get_device_info()
print("Serial: ", info.serial_number)
print("Product:", info.product_name)
# Load your FPGA configuration before using the data port.
device.get_fpga_configuration().load_configuration_from_file("my_design.bit")
# Wires, triggers, and pipes live on the classic data port.
classic = device.get_fpga_dataport_classic()
# Set a wire-in value and send it to the device.
classic.set_wire_in_value(0x00, 0x01)
classic.update_wire_ins()
# Fire a trigger-in (endpoint 0x40, bit 0).
classic.activate_trigger_in(0x40, 0)Code language: Python (python)manager.open_device()opens the first available device and returns aDevice; used withwith, it closes automatically when you leave the block.get_fpga_configuration().load_configuration_from_file()loads your FPGA configuration (a.bitfile).get_fpga_dataport_classic()returns the classic data port for wires, triggers, and pipes.set_wire_in_value()thenupdate_wire_ins()set a wire and send it;activate_trigger_in()fires a trigger.
Using the Binding API
The Binding API mirrors the C++ FrontPanel SDK. Install it with the wheel, or use the module files directly.
Python Wheel
Install the ok package from the SDK’s API/Python/ folder. Below, <sdk> is the folder where you installed the FrontPanel SDK:
pip install --no-index --find-links <sdk>/API/Python ok
Code language: HTML, XML (xml)--find-links points pip at the SDK folder, and --no-index keeps the install offline, so pip picks the correct wheel for your platform without contacting the internet. Then:
import ok
Code language: JavaScript (javascript)Manual Module Import
If you prefer not to install a package — for example, in an established setup that keeps its own copy of the libraries — use the Binding API files directly from the SDK’s API/Python/ folder:
To use them directly, copy these files into your project directory or add their location to your Python path. Your script can then import ok as long as the module files are accessible from the working directory or sys.path.
Required Files
The Python API distribution includes the files listed below:
ok.py_ok.pyd– Windows, architecture-specific for 32-bit/64-bit_ok.so– Linux, Mac OS, architecture-specific for 32-bit/64-bitokFrontPanel.dll– Windows, architecture-specific for 32-bit/64-bitlibokFrontPanel.so– Linux, Mac OS, architecture-specific for 32-bit/64-bitokimpl_fpoip.dll– (optional) Windows, architecture-specifc DLL used to provide FPoIP functionalityokimpl_fpoip.so– (optional) Linux, architecture-specifc DLL used to provide FPoIP functionality
The applicable files need to be in the current working directory where Python is started. Alternatively, they may be added to the Python site-packages directory within your Python distribution. Refer to the Python documentation to see how this is done.
Environment Setup
This section is for non-Windows environments. You do not need to follow any additional instructions if you are working in a Windows environment.
Assuming FrontPanel distribution was unpacked under FP_ROOT directory (this is the directory called FrontPanel-Ubuntu20.04-x86_64 or similar and containing ReleaseNotes.txt file), the following environment variables need to be set to allow using FrontPanel API from Python:
(note: if you are using Python 2.7, replace Python3 with Python)
PYTHONPATHmust be set to include$FP_ROOT/API/Python3LD_LIBRARY_PATH(DYLD_LIBRARY_PATHfor macOS) must be set to include both$FP_ROOT/API/Python3and$FP_ROOT/APIdirectories.
To do this, execute the following commands:
$ export PYTHONPATH=$FP_ROOT/API/Python3:$PYTHONPATH
$ export LD_LIBRARY_PATH=$FP_ROOT/API/Python3:$FP_ROOT/API:$LD_LIBRARY_PATH # Linux
$ export DYLD_LIBRARY_PATH=$FP_ROOT/API/Python3:$FP_ROOT/API:$DYLD_LIBRARY_PATH # macOSCode language: Bash (bash)Example Syntax
This opens the first available device, reads its identity, loads an FPGA configuration, and then uses the classic data port to set a wire and fire a trigger.
import ok
# Enumerate the connected devices and open the first available one.
xem = ok.FrontPanelDevices().Open()
info = ok.okTDeviceInfo()
xem.GetDeviceInfo(info)
print("Serial: ", info.serialNumber)
print("Product:", info.productName)
# Load your FPGA configuration before using the data port.
xem.ConfigureFPGA("my_design.bit")
# Wires, triggers, and pipes live on the classic data port.
classic = xem.GetFPGADataPortClassic()
# Set a wire-in value and send it to the device.
classic.SetWireInValue(0x00, 0x01)
classic.UpdateWireIns()
# Fire a trigger-in (endpoint 0x40, bit 0).
classic.ActivateTriggerIn(0x40, 0)
xem.Close()Code language: Python (python)ok.FrontPanelDevices().Open()opens the first available device;GetDeviceInfo()reads its identity.ConfigureFPGA()loads your FPGA configuration (a.bitfile) onto the device.GetFPGADataPortClassic()returns the classic data port, which carries wires, triggers, and pipes.SetWireInValue()thenUpdateWireIns()set a wire and send it;ActivateTriggerIn()fires a trigger.Close()releases the device.
Next steps
- Migrating from FrontPanel 5.x? See the Python migration guide.
- How-to guides walk through common tasks — enumerating devices, configuring the FPGA, transferring data, and more — with examples in both APIs.
- Reference for the Pythonic API: the FrontPanel Platform API, which it mirrors — synchronous and
snake_casefor Python, asynchronous (Promises) andcamelCasefor Typescript. - Reference for the Binding API: the C++ API reference, which it mirrors name-for-name.