Skip to content
Python class for reading and writing data to a GitHub repository
Python
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci CircleCI fixes Jun 9, 2019
cassettes branch_exists() method, closes #4 Mar 13, 2020
.gitignore
README.md
github_contents.py branch_exists() method, closes #4 Mar 13, 2020
setup.py
test_github_contents.py branch_exists() method, closes #4 Mar 13, 2020

README.md

github-contents

PyPI CircleCI 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

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

from github_contents import GitubContents

# For repo simonw/disaster-data:
github = GithubContents(
    "simonw",
    "disaster-data",
    GITHUB_OAUTH_TOKEN
)

To read a file:

content_in_bytes, sha = github.read(path_within_repo)

To write a file:

content_sha, commit_sha = github.write(
    filepath=path_within_repo,
    content_bytes=contents_in_bytes,
    sha=previous_sha, # Optional
    commit_message=commit_message,
    committer={
        "name": COMMITTER_NAME,
        "email": COMMITTER_EMAIL,
    },
)
You can’t perform that action at this time.