{"id":15433190,"url":"https://github.com/simonw/github-contents","last_synced_at":"2025-04-19T17:52:51.319Z","repository":{"id":57434572,"uuid":"191045082","full_name":"simonw/github-contents","owner":"simonw","description":"Python class for reading and writing data to a GitHub repository","archived":false,"fork":false,"pushed_at":"2021-02-24T18:34:49.000Z","size":27,"stargazers_count":20,"open_issues_count":7,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-05-01T23:17:31.999Z","etag":null,"topics":["github","githubapi"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simonw.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-06-09T19:10:59.000Z","updated_at":"2023-08-30T02:24:47.000Z","dependencies_parsed_at":"2022-09-04T15:30:52.399Z","dependency_job_id":null,"html_url":"https://github.com/simonw/github-contents","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fgithub-contents","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fgithub-contents/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fgithub-contents/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fgithub-contents/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simonw","download_url":"https://codeload.github.com/simonw/github-contents/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249753110,"owners_count":21320664,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["github","githubapi"],"created_at":"2024-10-01T18:32:30.564Z","updated_at":"2025-04-19T17:52:51.297Z","avatar_url":"https://github.com/simonw.png","language":"Python","readme":"# github-contents\n\n[![PyPI](https://img.shields.io/pypi/v/github-contents.svg)](https://pypi.org/project/github-contents/)\n[![Changelog](https://img.shields.io/github/v/release/simonw/github-contents?include_prereleases\u0026label=changelog)](https://github.com/simonw/github-contents/releases)\n[![Tests](https://github.com/simonw/github-contents/workflows/Test/badge.svg)](https://github.com/simonw/github-contents/actions?query=workflow%3ATest)\n[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/simonw/github-contents/blob/main/LICENSE)\n\nRead and write both small and large files to Github.\n\nThe regular [GitHub Contents API](https://developer.github.com/v3/repos/contents/) 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](https://developer.github.com/v3/git/) instead.\n\nNote that file contents is passed and returned as bytestrings, not regular strings.\n\n## Installation\n\n    pip install github-contents\n\n## Usage\n\nYou will need a GitHub OAuth token with full repository access.\n\nThe easiest way to create one of these is using [https://github.com/settings/tokens](https://github.com/settings/tokens)\n\n```python\nfrom github_contents import GithubContents\n\n# For repo simonw/disaster-data:\ngithub = GithubContents(\n    \"simonw\",\n    \"disaster-data\",\n    token=GITHUB_OAUTH_TOKEN,\n    branch=\"main\"\n)\n```\nTo read a file:\n```python\ncontent_in_bytes, sha = github.read(path_within_repo)\n```\nTo write a file:\n```python\ncontent_sha, commit_sha = github.write(\n    filepath=path_within_repo,\n    content_bytes=contents_in_bytes,\n    sha=previous_sha, # Optional\n    commit_message=commit_message,\n    committer={\n        \"name\": COMMITTER_NAME,\n        \"email\": COMMITTER_EMAIL,\n    },\n)\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonw%2Fgithub-contents","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimonw%2Fgithub-contents","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonw%2Fgithub-contents/lists"}