Skip to main content

Python class for reading and writing data to a GitHub repository

Project description

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

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 GithubContents

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

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,
    },
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

github-contents-0.2.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

github_contents-0.2-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file github-contents-0.2.tar.gz.

File metadata

  • Download URL: github-contents-0.2.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.1

File hashes

Hashes for github-contents-0.2.tar.gz
Algorithm Hash digest
SHA256 8693bca4111bc52f2f8e752619fd06b4a00b22b609a5fb97285d622b7c891086
MD5 3ba3b572a229a5d534992e1b4de66aaf
BLAKE2b-256 673930cec2610e796447fa416f941a8351e0c14ac715f22d17c7f2c63ef3e144

See more details on using hashes here.

File details

Details for the file github_contents-0.2-py3-none-any.whl.

File metadata

  • Download URL: github_contents-0.2-py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.1

File hashes

Hashes for github_contents-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 042918b0680ac76764006f99d95784b1c27bcd702eff4a3adecd077009da6660
MD5 26ba2bbebffed440aec516a2ede96c8c
BLAKE2b-256 b41fa8e06c2ce2f7438d557031eae2fb7f5d9cc02dad726f233d3cc205565b71

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page