Modularize python connection