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)
🌐
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.
🌐
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 ...
🌐
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)
When you want to call a C function, you need a way to represent that function within your Python program. That's where ctypes._FuncPtr comes in. Think of it as a Python object that points to the actual C function in memory. It's a function pointer.
🌐
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 significantly. We could make pointer[...] return a GenericAlias as usual Or alternatively, it can, at runtime, return a call POINTER(...) With this option we can effectively eliminate the need for the other POINTER type.
🌐
dbader.org
dbader.org › blog › python-ctypes-tutorial-part-2
Interfacing Python and C: Advanced “ctypes” Features – dbader.org
November 7, 2017 - Before we get into the depths of this tutorial, I’ll show you a utility function we’ll be using throughout. This Python function is called wrap_function. It takes the object returned from ctypes.CDLL and the name of a function (as a string).
🌐
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?