<jupyter_start><jupyter_text>github_api<jupyter_code>import github<jupyter_output><empty_output><jupyter_text>We initialize the API object by adding an access token:<jupyter_code>api = github.API(token="...")<jupyter_output><empty_output><jupyter_text>If we want to list all repositories which the authenticated user has access to, we do it with the following command, which returns a list of Repository objects.<jupyter_code>api.repositories.list()<jupyter_output><empty_output><jupyter_text>If we want the names of these repositories:<jupyter_code>[repository.full_name for repository in api.repositories.list()]<jupyter_output><empty_output><jupyter_text>More detailed information about specific repositories we get with the get function.<jupyter_code>repository = api.repositories.get("QuicksilverMachine/github_api")
repository.description<jupyter_output><empty_output><jupyter_text>Save command is used to save the changes on a repository.<jupyter_code>repository.description = "A small python library to interface with Github API. - changed with api"
repository.save()<jupyter_output><empty_output><jupyter_text>GitHub api has a limit on a number of requests that can be made to it. The rate_limits property returns a dictionary with detailed information about request limits.<jupyter_code>api.rate_limits<jupyter_output><empty_output><jupyter_text>Only the standard request remaining count:<jupyter_code>api.standard_requests_remaining<jupyter_output><empty_output><jupyter_text>The next_rate_limit_reset property returns a datetime object with the time of the next rate_limit count reset.<jupyter_code>api.next_rate_limit_reset<jupyter_output><empty_output><jupyter_text>Every repository has a list of collaborators, whose usernames are retrieved with:<jupyter_code>[user.login for user in repository.collaborators.list()]<jupyter_output><empty_output><jupyter_text>Repository owner is retrieved with:<jupyter_code>user = repository.owner<jupyter_output><empty_output><jupyter_text>The add function causes an invitation to be sent to a user for them to be added to a repository collaborator list, however in this case we can't add the owner of the repository as a collaborator, so the libraty raises an exception with the error message from the GitHub response.<jupyter_code>repository.collaborators.add(user)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07282793867120954, 'fraction_numerical': 0.0, 'mean_word_length': 8.746887966804978, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '574179', 'license': 'MIT', 'n_tokens_mistral': 707, 'n_tokens_neox': 684, 'n_words': 203, 'path': 'github_api.ipynb', 'repo_name': 'QuicksilverMachine/github_api', 'size': '2348'}