how do I prevent my postgres connection from timing out? (python, psycopg2)
PostgreSQL doesn't drop idle connections. It must be something else, probably a misconfigured firewall.
To defend against that, set the parameter tcp_keepalives_idle on the server to something less than the default 2 hours.
There is also a corresponding parameter keepalives_idle on the client side that you could set when you connect with psycopg2.
Both should do the trick.