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

Download files

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

Source Distribution

fetchify-3.0.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

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

fetchify-3.0.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file fetchify-3.0.0.tar.gz.

File metadata

  • Download URL: fetchify-3.0.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.10.0

File hashes

Hashes for fetchify-3.0.0.tar.gz
Algorithm Hash digest
SHA256 3ced9c99ee4e2451290d901b7985fdf26e14327ed5a709087300217a494c20bd
MD5 2673b9a3d1727942e7387d6fdff0be7b
BLAKE2b-256 14a2ea7d3cbf05afbe7836d4897413e5385578e1d7f82f85c48c82ed7a8bf22c

See more details on using hashes here.

File details

Details for the file fetchify-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: fetchify-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.10.0

File hashes

Hashes for fetchify-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 520695a007cab2a23f61a3779707ca159f4b704fc95b1209ff05c04494ebacc0
MD5 d68a2ba6f06de5c2eea120385fad6cff
BLAKE2b-256 402e43527987807e40a0eb20d05fd40d4ae686f1eb2df222a1d42457c73aa26d

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

3.0.0 This release

2 files

2.1.0

2 files

2.0.1

2 files

2.0.0

1 file

1.2.3

2 files

1.2.2

2 files

1.2.1

2 files

1.2.0

2 files

1.1.7

2 files

1.1.6

2 files

1.1.5

2 files

1.1.4

2 files

1.1.3

1 file

1.1.2

2 files

1.1.1

2 files

1.1.0

2 files

1.0.4

2 files

1.0.3

2 files

1.0.2

1 file

1.0.1

1 file

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