Ah I see what you mean.

I'm inclined to stick with PEP8 and keep things at the top unless there are serious performance implications.

Also might be worthwhile to import the specific function rather than the full module.