项目作者: simonw

项目描述 :
Python class for reading and writing data to a GitHub repository
高级语言: Python
项目地址: git://github.com/simonw/github-contents.git
创建时间: 2019-06-09T19:10:59Z
项目社区:https://github.com/simonw/github-contents

开源协议:

下载


github-contents

PyPI
Changelog
Tests
License

Read and write both small and large files to Github.

The regular GitHub Contents API can’t handle files larger than 1MB - this class knows how to spot that problem and switch to the large-file-supporting low level Git Data API instead.

Note that file contents is passed and returned as bytestrings, not regular strings.

Installation

  1. pip install github-contents

Usage

You will need a GitHub OAuth token with full repository access.

The easiest way to create one of these is using https://github.com/settings/tokens

  1. from github_contents import GithubContents
  2. # For repo simonw/disaster-data:
  3. github = GithubContents(
  4. "simonw",
  5. "disaster-data",
  6. token=GITHUB_OAUTH_TOKEN,
  7. branch="main"
  8. )

To read a file:

  1. content_in_bytes, sha = github.read(path_within_repo)

To write a file:

  1. content_sha, commit_sha = github.write(
  2. filepath=path_within_repo,
  3. content_bytes=contents_in_bytes,
  4. sha=previous_sha, # Optional
  5. commit_message=commit_message,
  6. committer={
  7. "name": COMMITTER_NAME,
  8. "email": COMMITTER_EMAIL,
  9. },
  10. )