How to programmatically get the current branch in Python transforms?

I have a Python script and I want to set certain environment variables dependent on the current branch that I am in. Is there a way to programmatically determine the current branch of the repository using Python?

The TransformOutput has the branch as a property.