Generic Python code and utilities