In [1]:
from github3 import (login, GitHub)
from github_settings import (username, password, token)
from itertools import islice

#gh = login(username, password=password)
gh = login(token=token)

from github3 import (login, GitHub)
from github_settings import (username, password, token)
from itertools import islice

#gh = login(username, password=password)
gh = login(token=token)


def repo_is_empty(repo_name, repo_owner='GITenberg', branch='master'):
    try:
        repo = gh.repository(repo_owner, repo_name)
        repo_branch = repo.branch(branch)
        # if there no branch
        if repo_branch is None:
            return True
        # if there are no files in tree
        tree = repo.tree(repo_branch.commit.sha)
        return len(tree.tree) == 0    
    except Exception as e:
        return e

In [2]:
repo_is_empty('United-States-Declaration-of-Independence_1')


Out[2]:
True

In [3]:
# no master branch at all
repo = gh.repository('GITenberg', 'United-States-Declaration-of-Independence_1')
repo.branch('master') is None


Out[3]:
True

In [ ]: