Best option I can think, of course, is to use twisted.
Old version of BitTorrent was built with it. The link is to last known version that uses twisted. You can study that as a starting point.
There's also Vertex. It is a library that uses twisted and allows p2p with firewall bypassing.