Skip to main content

Asyncio interface to the Pulseaudio and Pipewire pulse library.

Project description

Asyncio interface to the Pulseaudio and Pipewire pulse library.

libpulse is a Python project based on asyncio, that uses ctypes to interface with the pulse library of the PulseAudio and PipeWire sound servers. The interface is meant to be complete. That is, all the constants, structures, plain functions and async functions are made available by importing the libpulse module of the libpulse package.

It includes the pactl.py module, a Python implementation of the pactl command that runs both on Pulseaudio and Pipewire. The output of most pactl.py subcommands can be parsed by Python and when redirected to a file, the file can be imported as a Python module. For example start an interactive Python session and inspect the cards object with all its nested sructures and dereferenced pointers with:

$ ./pactl.py list cards > cards.py && python -i cards.py

Calling an async function is simple:

import asyncio
from libpulse.libpulse import LibPulse

async def main():
    async with LibPulse('my libpulse') as lib_pulse:
        server_info = await lib_pulse.pa_context_get_server_info()
        print(server_info)

asyncio.run(main())

Another example processing sink-input events:

import asyncio
from libpulse.libpulse import LibPulse, PA_SUBSCRIPTION_MASK_SINK_INPUT

async def main():
    async with LibPulse('my libpulse') as lib_pulse:
        await lib_pulse.pa_context_subscribe(
                                        PA_SUBSCRIPTION_MASK_SINK_INPUT)
        iterator = lib_pulse.get_events()
        async for event in iterator:
            some_function_to_process_the_event(event)

asyncio.run(main())

See the libpulse documentation.

Requirements

Python version 3.8 or more recent.

Installation

Install libpulse with pip:

$ python -m pip install libpulse

Project details


Download files

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

Source Distribution

libpulse-0.3.tar.gz (51.7 kB view hashes)

Uploaded Source

Built Distribution

libpulse-0.3-py3-none-any.whl (42.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page