And if you want to interact with tmux from within the python interpreter there is a very good library available, libtmux:
https://github.com/tmux-python/libtmux