1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
Metadata-Version: 2.3
Name: libpulse
Version: 0.7
Summary: Asyncio interface to the Pulseaudio and Pipewire pulse library.
Keywords: pulseaudio,pipewire,asyncio,ctypes
Author-email: Xavier de Gaye <xdegaye@gmail.com>
Requires-Python: >=3.8,<4
Description-Content-Type: text/x-rst
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Framework :: AsyncIO
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: Unix
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Multimedia :: Sound/Audio :: Players
Project-URL: Changelog, https://libpulse.readthedocs.io/en/stable/history.html
Project-URL: Documentation, https://libpulse.readthedocs.io/en/stable/
Project-URL: Source, https://gitlab.com/xdegaye/libpulse
.. image:: images/coverage.png
:alt: [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:
.. code-block:: python
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:
.. code-block:: python
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:
.. code-block:: shell
$ 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
.. _libpulse: https://gitlab.com/xdegaye/libpulse
.. _asyncio: https://docs.python.org/3/library/asyncio.html
.. _ctypes: https://docs.python.org/3/library/ctypes.html
.. _Read the Docs: https://about.readthedocs.com/
.. _stable documentation: https://libpulse.readthedocs.io/en/stable/
.. _latest documentation: https://libpulse.readthedocs.io/en/latest/
.. _`PulseAudio Documentation`:
https://freedesktop.org/software/pulseaudio/doxygen/index.html
|