Skip to main content

Python wrapper for PortAudio's ring buffer

Project description

The ring buffer functionality is typically not included in binary distributions of PortAudio, therefore most Python wrappers don’t include it, either.

The pa_ringbuffer module provides only a Python wrapper, the actual PortAudio ring buffer code has to be compiled separately, see Usage. It can be used on any Python version where CFFI is available.

This module is designed to be used together with the sounddevice module (it might work with other modules, too) for non-blocking transfer of data between the main Python program and an audio callback function which is implemented in C or some other compiled language.


This module is not meant to be used on its own, it is only useful in cooperation with another Python module using CFFI. For an example, have a look at

You can get the Python code from PyPI, for example in your file (in the following example, your module would be called mycffimodule):

from setuptools import setup

    setup_requires=['CFFI', 'pa_ringbuffer'],

Alternatively, you can just copy the file src/ to your own source directory and import it from there.

You can build your own CFFI module like described in, just adding a few more bits to your

from cffi import FFI
import pa_ringbuffer

ffibuilder = FFI()

/* my own declarations */

    '/* my implementation */',

if __name__ == '__main__':

Note that the following files must be available to the compiler:

For your own C code, you might need some definitions from the main PortAudio header:

Once you have compiled your extension module (with the help of CFFI), you can use something like this in your own module to get access to the RingBuffer class:

import pa_ringbuffer
from _mycffimodule import ffi, lib

RingBuffer = pa_ringbuffer.init(ffi, lib)

API Reference

There are only two functions:


This function returns a string containing C declarations from the file pa_ringbuffer.h, which can be used as argument to CFFI’s cdef() function (see Usage above). Note that the returned declarations are slightly different when called on a macOS/Darwin system.

pa_ringbuffer.init(ffi, lib)

This function returns the RingBuffer class which is associated with the CFFI instance given by ffi and lib.

Creating the Documentation

The documentation of the RingBuffer class is not available separately. If you are using Sphinx, you can seamlessly include the documentation of the RingBuffer class with your own documentation. An example for this can be found at, the generated documentation is available at

You’ll need to have the autodoc extension activated in your

extensions = [

And somewhere within your module documentation, you should add this:

.. autoclass:: RingBuffer

Before that, you might have to use the currentmodule directive to select your own module. Using automodule should also do.

Version History

0.1.3 (2018-06-02):
  • No new features, just a minor documentation update
0.1.2 (2017-10-21):
  • No new features, just a bug fix
0.1.1 (2017-09-04):
  • Add buffer parameter
0.1.0 (2017-08-08):
Initial release

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pa-ringbuffer, version 0.1.3
Filename, size File type Python version Upload date Hashes
Filename, size pa_ringbuffer-0.1.3-py2.py3-none-any.whl (8.8 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size pa-ringbuffer-0.1.3.tar.gz (7.3 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page