Skip to main content

fetchify

Fetch files from any GitHub repository — configurable for any user.

PyPI version Python 3.6+ License: MIT


Installation

pip install fetchify

Quick Start

Module-level API (simple scripts)

import fetchify

# Configure once with your GitHub username
fetchify.configure("your-github-username")

# Register repo aliases
fetchify.add_repo("py", "Python_Projects")
fetchify.add_repo("web", "my-web-app")

# Fetch a file (returns text)
content = fetchify.fetch("main.py", "py")
print(content)

# Save it to disk
fetchify.save(content, "main.py")

Class API (recommended for larger projects)

from fetchify import Fetchify

f = Fetchify(username="your-github-username")

# Register multiple repos at once
f.add_repos({
    "py":  "Python_Projects",
    "web": "my-web-app",
    "ds":  "DataSense",
})

# Fetch a file from the default branch (main)
code = f.fetch("utils.py", "py")

# Fetch from a specific branch
code_dev = f.fetch("utils.py", "py", branch="dev")

# Fetch an image / binary file
img_bytes = f.fetch("logo.png", "web", image=True)
fetchify.save(img_bytes, "logo.png")

Private Repositories

Pass a GitHub Personal Access Token (PAT) to access private repos:

from fetchify import Fetchify

f = Fetchify(
    username="your-github-username",
    token="ghp_your_token_here"
)
f.add_repo("private", "my-private-repo")
content = f.fetch("secret.py", "private")

Tip: Store your token in an environment variable — never hardcode it.

import os
f = Fetchify(username="...", token=os.getenv("GITHUB_TOKEN"))

API Reference

Fetchify(username, token=None, default_branch="main")

Create a new Fetchify instance.

Parameter Type Description
username str GitHub username
token str GitHub PAT (optional, for private repos)
default_branch str Default branch to fetch from (default: "main")

f.add_repo(alias, repo_name) → self

Register a single repo alias.

f.add_repos(repo_dict) → self

Register multiple aliases from a dict. Supports method chaining.

f.list_repos() → dict

Returns the registered alias → repo-name mapping.

f.fetch(filename, repo, branch=None, image=False) → str | bytes

Fetch a file from GitHub.

Parameter Type Description
filename str Path inside the repo (e.g. "src/main.py")
repo str Alias or exact repo name
branch str Branch to fetch from (overrides default_branch)
image bool Return bytes if True, str if False

f.fetch_raw(url, image=False) → str | bytes

Fetch from an arbitrary raw GitHub URL directly.

fetchify.save(content, name, mode=None)

Save fetched content to a local file. Auto-detects text vs binary.

Parameter Type Description
content str | bytes Content from fetch()
name str Destination file path
mode str Force "w" or "wb" (optional)

fetchify.configure(username, token=None, default_branch="main")

Set up the module-level default instance (for the simple API).


Error Handling

from fetchify import Fetchify, FetchError, RepoNotFoundError

f = Fetchify("my-username")
f.add_repo("py", "Python_Projects")

try:
    content = f.fetch("nonexistent.py", "py")
except FetchError as e:
    print(f"Could not fetch file: {e}")
Exception When raised
FetchifyError Base class for all fetchify errors
FetchError HTTP errors (404, 403, network issues)
RepoNotFoundError Alias not registered

Migration from v2.x

v2.x v3.x
fetch("file.py", "py") fetchify.configure("user") then fetchify.fetch("file.py", "py")
gem(prompt) Removed — use google-generativeai directly
Hardcoded API key No credentials in library
Only works with Anupam1707 repos Works with any GitHub user

License

MIT © Anupam Kanoongo

Metadata

Release files for fetchify 3.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fetchify 3.0.0
File Size Uploaded Provenance
fetchify-3.0.0.tar.gz 5.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for fetchify 3.0.0
File Interpreter ABI Platform
fetchify-3.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 11.0 kB

Release files / fetchify-3.0.0.tar.gz

Download URL fetchify-3.0.0.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
3ced9c99ee4e2451290d901b7985fdf26e14327ed5a709087300217a494c20bd
BLAKE2b-256 checksum
How to use checksums
14a2ea7d3cbf05afbe7836d4897413e5385578e1d7f82f85c48c82ed7a8bf22c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.0

Release files / fetchify-3.0.0-py3-none-any.whl

Download URL fetchify-3.0.0-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
520695a007cab2a23f61a3779707ca159f4b704fc95b1209ff05c04494ebacc0
BLAKE2b-256 checksum
How to use checksums
402e43527987807e40a0eb20d05fd40d4ae686f1eb2df222a1d42457c73aa26d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.0

Security for fetchify 3.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page