According to the ctypes callback docs you can define python function

def my_callback(a, p, frame, p1, p2)
    pass

and then create a pointer to a C callable function like this:

callback = write_callback_prototype(my_callback)

This function pointer can then be passed into FLAC

Answer from Ber on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › using-pointers-in-python-using-ctypes
Using Pointers in Python using ctypes - GeeksforGeeks
July 23, 2025 - Since in Python the concept of pointers is not properly available or used we can't properly create a Void Pointer, as the POINTER function requires one argument i.e the data type. But we can create a Void pointer of a certain data type and then don't point it to any memory address. We are just typecasting it like C/C++ early. We can also create some void pointers of a specific type that doesn't hold any address while creating. ... import ctypes as ct # Creating a variable ptr2 which will act as a void pointer # We will not point it to any other memory location ptr2 = ct.POINTER(ct.c_int) # Trying to print a void pointer print(ptr2)
🌐
Fz-juelich
pgi-jcns.fz-juelich.de › portal › pages › using-c-from-python.html
Using C from Python: How to create a ctypes wrapper - Scientific IT-Systems
The function ctypes.POINTER creates a pointer datatype, so ctypes.POINTER(ctypes.c_int) is the ctypes datatype for int *. When using the functions, ctypes will check if the arguments fit to these types. The real function definition follows in the next lines. We don't need the num_numbers argument ...
🌐
Python
docs.python.org › 3 › library › ctypes.html
ctypes — A foreign function library for Python
Generally you only use this feature if you receive a pointer from a C function, and you know that the pointer actually points to an array instead of a single item. ... Because pointer objects support subscription, they implicitly support iteration. Unless doing this in a controlled manner, such as by manually calling next() on a pointer() iterator, this will typically lead to infinite loops or crashes, because ctypes has no way of knowing when to stop iteration.
🌐
Stack Overflow
stackoverflow.com › questions › 25014191 › python-ctypes-function-pointer
Python ctypes function pointer - Stack Overflow
To call your function, you would call the SET_FUNC, GET_FUNC, GET_DOUBLE, and SYS_CALLBACK variables (which are all instances of CFUNCTYPE) to convert Python functions to function pointers, ctypes.pointer to create pointers to objects (which you would need to initialize the gsl_rng structure, whose type field expects a pointer to an instance of gsl_rng_type), and ctypes.byref to pass ctypes objects by reference to your function (using ctypes.pointer also works in this case, but is slower).
🌐
Runebook
runebook.dev › english › articles › python
Python ctypes: Working with Function Pointers (ctypes._FuncPtr)
import ctypes # Assume we have ... print(result) # Output: 8 · Now, add_func(5, 3) calls the actual C function. ctypes handles the conversion of Python arguments to C types and vice-versa....
🌐
CodersLegacy
coderslegacy.com › home › python › using pointers with ctypes and python
Using Pointers with Ctypes and Python - CodersLegacy
July 8, 2022 - The pointer() function will then return a pointer object. By using the .contents attribute, we can dereference a pointer and gain access to the original object it was pointing to.
🌐
GeeksforGeeks
geeksforgeeks.org › turning-a-function-pointer-to-callable
Turning a Function Pointer to Callable | GeeksforGeeks
April 2, 2019 - Well, the memory address of a compiled function is obtained but how to turn it to Python callable that can be used as an extension. The answer to this the use of ctypes module that can create a Python callable and can wrap arbitrary memory address. The code below shows how to obtain the raw, low-level address of a C function and how to turn it back into a callable object.
Find elsewhere
🌐
SciPy
scipy.github.io › old-wiki › pages › Cookbook › Ctypes.html
Cookbook/Ctypes - SciPy wiki dump
ctypes supports the idea of callbacks, allowing C code to call back into Python through a function pointer.
🌐
GitHub
github.com › python › mypy › issues › 7540
ctypes POINTER(c_type) is not allowed as function arg type · Issue #7540 · python/mypy
September 20, 2019 - # Naive approach @func(mylib) def MyFuncOne(id: ctypes.c_uint32, val: ctypes.POINTER(ctypes.c_uint32) -> ctypes.uint32: ... # Try to use variable, since POINTER is declared in typeshed as # (type: Type[_CT]) -> Type[pointer[_CT]]` PTR_UINT32 = ctypes.POINTER(ctypes.c_uint32) @func(mylib) def MyFuncTwo(id: ctypes.c_uint32, val: PTR_UINT32) -> ctypes.uint32: ...
Author: python
🌐
Stack Overflow
stackoverflow.com › questions › 25116465 › function-pointer-in-python
ctypes - Function pointer in Python - Stack Overflow
In ctypes, you create a pointer type by using POINTER(type), then create an instance of that type the same way as any other ctypes type. Or you can call addressof to get a pointer to some existing ctypes object.
🌐
Python.org
discuss.python.org › ideas
Implement __class_getitem__ for ctypes.pointer - Ideas - Discussions on Python.org
January 8, 2023 - Proposal Make ctypes.pointer support __class_getitem__. As it is currently a function, we can change it to a class, with __new__ implementing the current features of the function. This should not affect existing behavior…
🌐
Runebook
runebook.dev › english › articles › python
Working with Structures and Pointers in Python using ctypes._Pointer
Changes made through the pointer ... This is essential for performance-critical tasks and interacting with hardware. ... ctypes._Pointer is the Python representation of a C pointer....
🌐
Runebook.dev
runebook.dev › en › docs › python › library › ctypes › ctypes._Pointer
ctypes Pointers in Python: Correct Usage with POINTER, pointer, and byref
Since it's an internal detail (the underscore at the start, _Pointer, is a convention for internal use!), you generally interact with pointers using the public function ctypes.POINTER() (to create a pointer type) or ctypes.pointer() (to create a pointer instance). Let's dive into some common issues and better ways to handle pointers with ctypes! When working with C pointers via Python's ctypes (usually through POINTER() or pointer()), here are some typical pitfalls
🌐
Things Of Some Value
mattgwwalker.wordpress.com › 2020 › 05 › 30 › pointer-manipulation-in-python
Pointer Manipulation in Python – Things Of Some Value
May 30, 2020 - >>> # And call our function >>> printContents(x) 0 0 0 0 0 0 0 0 0 0 >>> >>> # We can populate the array with some data >>> x[0] = 99 >>> x[1] = -1 >>> x[2] = 42 >>> >>> # Print out the array >>> printContents(x) 99 -1 42 0 0 0 0 0 0 0 >>> >>> # Get a pointer to the array >>> p = ctypes.pointer(x) >>> >>> # What's the pointer's type?
🌐
Python
docs.python.domainunion.de › 3 › library › ctypes.html
ctypes — A foreign function library for Python
October 19, 2019 - Instances of foreign functions are also C compatible data types; they represent C function pointers. This behavior can be customized by assigning to special attributes of the foreign function object. ... Assign a ctypes type to specify the result type of the foreign function. Use None for void, a function not returning anything. It is possible to assign a callable Python object that is not a ctypes type, in this case the function is assumed to return a C int, and the callable will be called with this integer, allowing further processing or error checking.