There are a couple of Python modules that will let you do this, I would suggest using sounddevice.  It can be installed with pip or conda:  python-sounddevice as is built on top of the platform independent PortIO package.  The documentation has lots of examples, ranging from very simple to sophisticated.