def public(thing): """Print 'public' attributes of thing.""" for x in dir(thing): if not x.startswith('_'): print(x) from github3 import login username = 'jiffyclub' token = '---' # not an actual token gh = login(username=username, token=token) public(gh) repo = gh.repository(username, 'demodemo') public(repo) repo.contents('/') tf = repo.contents('test_file.md') public(tf) tf.content tf.decoded content = tf.decoded.decode('utf-8') content new_content = content + '\nA fancy new change via the GitHub API.\n' c = tf.update('Trying out the GitHub API via github3.py and Python 3', new_content.encode('utf-8')) c public(c) repo = repo.refresh() files = repo.contents('/') files new_file_content = files['new_file.md'].refresh().decoded.decode('utf-8') test_file_content = files['test_file.md'].refresh().decoded.decode('utf-8') new_file_content test_file_content new_file_content = new_file_content + '\nMulti-file commit via the GitHub API!\n' test_file_content = test_file_content + '\nMulti-file commit via the GitHub API!\n' new_file_blob = repo.create_blob(new_file_content, encoding='utf-8') test_file_blob = repo.create_blob(test_file_content, encoding='utf-8') print(new_file_blob, test_file_blob) branch = repo.branch(repo.default_branch) public(branch) tree_sha = branch.commit.commit.tree.sha tree_data = [{'path': 'new_file.md', 'mode': '100644', 'type': 'blob', 'sha': new_file_blob}, {'path': 'test_file.md', 'mode': '100644', 'type': 'blob', 'sha': test_file_blob}] tree = repo.create_tree(tree_data, tree_sha) tree message = 'Modifying multiple files via the GitHub API and github3.py.' c = repo.create_commit(message, tree.sha, [branch.commit.sha]) c c.html_url ref = repo.ref('heads/{}'.format(repo.default_branch)) ref.update(c.sha) branch.links['html']