[PYTHON] Output repository list using Github API on Mac

Purpose

It is a memorandum when outputting the repository list using Github API on Mac.

Preparation

Install PyGithub

$ pip install PyGithub

In addition, get an access token for your GitHub account (you can get it from Settings)

code

Output repository list

#!/usr/bin/env python
from github import Github
 
token = 'xxxxxxxxxxxxxxx' # your access token
 
# or using an access token
g = Github(token)
 
for repo in g.get_user().get_repos():
    print(repo.name)

Run

(Repository list is output)

Error countermeasures

$ python github.py
Traceback (most recent call last):
  File "github.py", line 2, in <module>
    from github import Github
  File "/Users/seigo/Desktop/python/burger/github.py", line 2, in <module>
    from github import Github
ImportError: cannot import name 'Github' from 'github' (/Users/seigo/Desktop/python/burger/github.py)

I get the above error when I name the sample code gitHub.py. Renamed to sample.py and resolved.

reference

PyGithub I tried to summarize various things about Github API I tried to get GitHub information using PyGithub Python 2.7 Error - ImportError: cannot import name Github

Recommended Posts

Output repository list using Github API on Mac
(Beginner) Notes on using pyenv on Mac
Stream speech recognition using Google Cloud Speech gRPC API on python3 on Mac!
I tried using the COTOHA API (there is code on GitHub)
Install opencv on Mac using Anaconda Navigator
Put Anaconda on your Mac using Pyenv
Clone the github repository on jupyter notebook
Error, warning when using TensorFlow on Mac
Video processing using Python + OpenCV on Mac
Read FeliCa using Pasori (RC-380S) on Mac
I tried using Remote API on GAE / J
Prepare a pseudo API server using GitHub Actions
python on mac
Build a Django development environment using pyenv-virtualenv on Mac
Install Python venv --VSCode --GitHub integration environment on Mac
Build a Python environment on your Mac using pyenv
Post to your account using the API on Twitter
Create a pseudo REST API server using GitHub Pages
Output to "7-segment LED" using python on Raspberry Pi 3!
Minimum memo when using Python on Mac (pyenv edition)
Minimum notes when using Python on Mac (Homebrew edition)