Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read content of file which is in GitHub using PyGitHub

Let’s say "sample.txt" file is in GitHub under the "Demo" repository [Demo/sample.txt]. How can I read the content of sample.txt using PyGitHub instead fetching from the API?

Else, do we have some other package to read such file content?

like image 503
Sridhar Dhandapani Avatar asked Jul 14 '26 04:07

Sridhar Dhandapani


1 Answers

You can use this code to see the content of the file:

from github import Github
github = Github('user', 'password')
user = github.get_user()
repository = user.get_repo('Demo')
file_content = repository.get_contents('sample.txt')
print(file_content.decoded_content.decode())

If you need to see more attributes like decoded_content, just type this:

print(help(file_content))
like image 109
Andre Lopez Avatar answered Jul 15 '26 22:07

Andre Lopez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!