It is actually quite hard shaping per application using the linux kernel tools, unless the application uses specific ip addresses and/or ports you can match on.
Assuming that is the case then you'll need to read up on iptables and in particular fwmarks. You'll also need to read up on tc. In combination those two tools can do what you want. The Linux Advanced Routing & Traffic Control is a good place to start.
Assuming your application doesn't use a predictable set of ports/ip addresses then you'll need to use a userspace shaper like Trickle. This inserts itself between the application and the kernel and shapes the traffic for that application in userspace.
I don't think there are any direct python bindings for any of those tools, but it would be simple to script them using python and just calling the executables directly.