Asyncio interface to the Pulseaudio and Pipewire pulse library.
Project description
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:
The stable documentation of the last released version.
The latest documentation of the current GitLab development version.
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
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file libpulse-0.7.tar.gz.
File metadata
- Download URL: libpulse-0.7.tar.gz
- Upload date:
- Size: 61.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f80bfa304784c550d71e37d2e8c9cb06b7fb639b9898f778768c0c69aba0d429
|
|
| MD5 |
97d4253aa921c70ceb8153d22f4a02bb
|
|
| BLAKE2b-256 |
ecd6caddf6ed22c2f559897dfa72bdbcc9422df44694f375527420d35f99bc3f
|
File details
Details for the file libpulse-0.7-py3-none-any.whl.
File metadata
- Download URL: libpulse-0.7-py3-none-any.whl
- Upload date:
- Size: 44.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
63881802afdd0566832ea4c037d39f2e2b832bbe64392f0ec3b3763c126251b7
|
|
| MD5 |
17d9df4417629b28abca7e86d24b39a1
|
|
| BLAKE2b-256 |
7621f18688d5ac6af444d2075b969c518916d11d41bb7bfd679e5f0f9450f100
|