Micropython - How to find the callback created with python in ffi from my C/C++ function?
03:42 24 Feb 2026

I want to async not only call the cpp functions in Python but return Python functions in my cpp functions to make callbacks

Python ffi module is managed by the functions available in micropython. the path is ports/unix/modffi.c

https://github.com/micropython/micropython/blob/master/ports/unix/modffi.c

Example

python script

import ffi
import exemplecpp

def hello():
    print("Hello world\n")

hello_callback = ffi.callback("v", hello, "")

exemplecpp.cppfunc(hello_callback)

How in the usermodule to retrieve the callback as a function to use it in my cpp function

cpp function

mp_obj_t cppfunc(mp_obj_t func_obj)
{
  ...
  func_obj();
  ...
  return mp_const_none
}
python c++ callback ffi micropython