For this purpose, it looks like this:
if 'googlebot' in request.headers.get('user-agent', 'googlebot'): return 403