Resolving firmlinks in Python

I recently had the need to resolve firmlinks in python. For example given a path like /Applications/Safari.app, I needed to get /System/Volumes/Data/Applications/Safari.app.

Turns out there is not a single example of this anywhere online, so if you are in the same place as I am, here is an example of how to do that: