Changing default branch using the bitbucket REST API

Currently, I am working on a tool that creates a repository in a bitbucket project and populates it with files from a template after some processing. I have been asked to add a feature that changes the default branch from master to main.

  1. repo.git.execute(['git', 'checkout', '-b', 'main'])
  2. response = requests.put(" 
                      auth=HTTPBasicAuth(<username>, <password>),
  3. repo.create_head('main').checkout()

Above are a few attempts that I made to create or change to a new default branch, with varying degrees of success. Below are links to the documentation that I have been following as I build the tool.

I have some additional documentation to share but, if there is a more simple manner to implement this feature, you have documentation that I haven’t yet come across, or can offer any assistance, please do not hesitate to reach out.