Search code examples
python-3.xgithubpygithub

can you delete a repo via pygithub?


Can you delete a repo using pygithub? For example, as shown in this example, you can delete a file like so:

repo = g.get_repo("userName/repoName")
contents = repo.get_contents("filename.txt", ref="test")
repo.delete_file(contents.path, "remove test", contents.sha, branch="test")

Is there something analogous for deleting entire repos? If not, how can one do this via the github API?


Solution

  • The pygithub documentation does include a delete() method, which calls the exact GitHub repo DELETE API delete /repos/{owner}/{repo}

    So it should be possible to call that method, as in PyGithub/PyGithub tests/Repository.py

    g=Github('token')
    repo = self.g.get_user().get_repo("TestPyGithub")
    repo.delete()