Skip to main content

mpg321 wrapper for python - command line music player

Project description

Downloads Downloads Downloads


mpyg321 is a simple python wrapper for mpg321 and mpg123. It allows you to easily play mp3 sounds in python, do basic operations on the music and implement callbacks for events like the end of a sound.


mpyg321 requires the installation of mpg123 (or mpg321 depending on your usage) software for reading mp3. This section describes the installation of the library on MacOS, Linux and Windows. For now, the library has only been tested on mac, but it should work on any platform.

We recommend using mpg123 since the project is more up to date. However, you can also use this library with mpg321 (using the MPyg321Player class)


$ brew install mpg123 # or mpg321
$ pip3 install mpyg321


$ sudo apt-get update
$ sudo apt-get install mpg123 # or mpg321
$ pip3 install mpyg321


For windows installation, download mpg123 on the website: mpg123's website, and then run:

$ pip install mpyg321


Usage is pretty straight forward, and all the functionnalities are easily shown in the examples folder.

from mpyg321.MPyg123Player import MPyg123Player # or MPyg321Player if you installed mpg321
player = MPyg123Player()


You can implement callbacks for several events such as: end of song, user paused the music, ... All the callbacks can be found inside the code of the BasePlayer class and the MPyg123Player class. Most of the callbacks are implemented in the example file.


In order to loop (replay the song when it ended), you can either set the loop mode when calling the play_song function:

player.play_song("/path/to/sample.mp3", loop=True)

or programmatically set the loop mode anywhere in the code:

// Do some stuff ...

Note: when calling player.set_loop(True), the loop mode will only be taken into account at the end of a song. If nothing is playing, this call will not replay the previous song. In order to replay the previous song, you should call:

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

mpyg321-2.1.1.tar.gz (7.4 kB view hashes)

Uploaded source

Built Distribution

mpyg321-2.1.1-py3-none-any.whl (8.1 kB view hashes)

Uploaded py3

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