Skip to main content

🔊 Play music and sounds in your Python scripts

Project description

Play sounds in your Python scripts

This project provides a simple cross-platform API to play sounds in your Python scripts, and allows you to play sounds while a function or code block executes, or afterwards.

It's a simple wrapper over playsound and boombox.

I use this project in onhold and ding.


boombox is great and 90% of the way there, however the default options for playing sounds on Windows are limited to WAV files. If the platform is Windows, play_sounds will default to the playsound backend.


python3 -m pip install play_sounds


This library uses pathlib.Path objects when pointing to filenames and paths.

Playing a file

from play_sounds import play_file, DEFAULT_SONG

play_file(DEFAULT_SONG)  # blocks by default

# play without blocking
play_file(DEFAULT_SONG, block=False) 

Playing while work completes

from time import sleep
from play_sounds import play_while_running, DEFAULT_SONG

with play_while_running(DEFAULT_SONG):

Play sound after work completes

from time import sleep
from play_sounds import play_after, DEFAULT_SOUND

with play_after(DEFAULT_SOUND):  # blocks by default

# play without blocking
with play_after(DEFAULT_SOUND, block=False):





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

play_sounds-0.1.3.tar.gz (3.5 kB view hashes)

Uploaded source

Built Distribution

play_sounds-0.1.3-py2.py3-none-any.whl (7.5 MB view hashes)

Uploaded py2 py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page