Skip to main content
[libpulse test coverage]

Asyncio interface to the Pulseaudio and Pipewire pulse library.

Overview

libpulse is a Python package 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.

Async functions are those pulse functions that return results through a callback. They are implemented as asyncio coroutines that return the callback results. They have the same name as the corresponding pulse async function.

Non-async pulse functions have their corresponding ctypes foreign functions defined in the libpulse module namespace under the same name as the corresponding pulse function. They may be called directly.

Calling an async function or a plain function is simple:

import asyncio
import libpulse.libpulse as libpulse

async def main():
    async with libpulse.LibPulse('my libpulse') as lp_instance:
        # A plain function.
        server = libpulse.pa_context_get_server(lp_instance.c_context)
        print('server:', server.decode())

        # An async function.
        sink = await lp_instance.pa_context_get_sink_info_by_index(0)
        print('sample_spec rate:', sink.sample_spec.rate)
        print('proplist names:', list(sink.proplist.keys()))

asyncio.run(main())

Another example processing pulse events:

import asyncio
import libpulse.libpulse as libpulse

async def main():
    async with libpulse.LibPulse('my libpulse') as lp_instance:
        await lp_instance.pa_context_subscribe(
                                libpulse.PA_SUBSCRIPTION_MASK_ALL)
        iterator = lp_instance.get_events_iterator()

        async for event in iterator:
            # Start playing some sound to print the events.
            # 'event' is an instance of the PulseEvent class.
            print(event.__dict__)

asyncio.run(main())

The libpulse package also includes the pactl-py command, which is a Python implementation of the pactl command running on Pulseaudio and Pipewire. The output of most pactl-py subcommands can be parsed by Python. When this output is 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

Requirements

Python version 3.8 or more recent.

Documentation

The libpulse documentation is hosted at Read the Docs:

To access the documentation as a pdf document one must click on the icon at the down-right corner of any page. It allows to switch between stable and latest versions and to select the corresponding pdf document.

The documentation describing the C language API of the pulse library is at PulseAudio Documentation.

Installation

Install libpulse with pip:

$ python -m pip install libpulse

Metadata

Release files for libpulse 0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for libpulse 0.7
File Size Uploaded Provenance
libpulse-0.7.tar.gz 61.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for libpulse 0.7
File Interpreter ABI Platform
libpulse-0.7-py3-none-any.whl Python 3 none any Details

Total release size: 105.6 kB

Release files / libpulse-0.7.tar.gz

Download URL libpulse-0.7.tar.gz
Size 61.1 kB
Tags Source
SHA-256 checksum
How to use checksums
f80bfa304784c550d71e37d2e8c9cb06b7fb639b9898f778768c0c69aba0d429
BLAKE2b-256 checksum
How to use checksums
ecd6caddf6ed22c2f559897dfa72bdbcc9422df44694f375527420d35f99bc3f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.32.3

Release files / libpulse-0.7-py3-none-any.whl

Download URL libpulse-0.7-py3-none-any.whl
Size 44.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
63881802afdd0566832ea4c037d39f2e2b832bbe64392f0ec3b3763c126251b7
BLAKE2b-256 checksum
How to use checksums
7621f18688d5ac6af444d2075b969c518916d11d41bb7bfd679e5f0f9450f100
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.32.3

Security for libpulse 0.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page