github-contents
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,
},
)
Metadata
Release files for github-contents 0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| github-contents-0.2.tar.gz | 3.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| github_contents-0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.2 kB
Release files / github-contents-0.2.tar.gz
| Download URL | github-contents-0.2.tar.gz |
|---|---|
| Size | 3.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8693bca4111bc52f2f8e752619fd06b4a00b22b609a5fb97285d622b7c891086
|
|
BLAKE2b-256 checksum How to use checksums |
673930cec2610e796447fa416f941a8351e0c14ac715f22d17c7f2c63ef3e144
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / github_contents-0.2-py3-none-any.whl
| Download URL | github_contents-0.2-py3-none-any.whl |
|---|---|
| Size | 3.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
042918b0680ac76764006f99d95784b1c27bcd702eff4a3adecd077009da6660
|
|
BLAKE2b-256 checksum How to use checksums |
b41fa8e06c2ce2f7438d557031eae2fb7f5d9cc02dad726f233d3cc205565b71
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|