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. This module is run by the pactl-py command. 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:
         sink = await lib_pulse.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 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_iterator()
        async for event in iterator:
            # 'event' is an instance of PulseEvent.
            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.6.tar.gz (53.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

libpulse-0.6-py3-none-any.whl (43.9 kB view details)

Uploaded Python 3

File details

Details for the file libpulse-0.6.tar.gz.

File metadata

  • Download URL: libpulse-0.6.tar.gz
  • Upload date:
  • Size: 53.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.3

File hashes

Hashes for libpulse-0.6.tar.gz
Algorithm Hash digest
SHA256 8143af5ebd996544bb0dffac722a2ab22a737e7d3bd3864882c58354e603c24a
MD5 5741a3c80f496ec0585f9c376a8e627d
BLAKE2b-256 b5d58d1ddbc2d8c96f32935377d3dda9d9e30bae00addeea5693558241106d81

See more details on using hashes here.

File details

Details for the file libpulse-0.6-py3-none-any.whl.

File metadata

  • Download URL: libpulse-0.6-py3-none-any.whl
  • Upload date:
  • Size: 43.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.3

File hashes

Hashes for libpulse-0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 3e91070b98a32042d7ed92694d0df535f175fa15c8b46bd55b54ce0405e9fef2
MD5 c8e6cc9ba3918abacb3cd12f13855a0e
BLAKE2b-256 ea554c166e1c23a438a3d9780845b93aac62117c82624f20e3b25dcb8d09cbbe

See more details on using hashes here.

Supported by

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