Basically, you can't.
You can measure performance and execution plans in PostgreSQL queries but I can't even begin to picture how you'd integrate that with a profile for an imperative programming language. You can completely replace the Python with Perl that generates the same queries and it wouldn't make a blind bit of difference to PostgreSQL anyway.
So - there are two interesting questions to answer. Firstly, what queries are taking up all your time? Secondly, is the query planner doing a good job?
For the first, there are a number of logfile processors that will build stats for you but I would recommend the pg_stat_statements extension. Leave this running and it will count up how many times you run different queries and how long they take.
For the second, you'll want to check the query plans produced via EXPLAIN and see if you need to alter the indexes available, or perhaps the queries themselves. That's too large a topic for here, but the wiki is a good starting point. There's an excellent online tool to help illustrate query-plans too.