Metadata-Version: 2.4
Name: fetchify
Version: 3.0.0
Summary: Fetch files from any GitHub repository — configurable for any user.
Home-page: https://techinfoak.wixsite.com/tech-info
Author: Anupam Kanoongo
Author-email: programmer.tiak@gmail.com
License: MIT
Project-URL: Our Website, https://techinfoak.wixsite.com/devak
Project-URL: Our YT Handle, https://youtube.com/@developer.anupam
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.6
Description-Content-Type: text/markdown
Requires-Dist: requests
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: license
Dynamic: project-url
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

# fetchify

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

[![PyPI version](https://badge.fury.io/py/fetchify.svg)](https://pypi.org/project/fetchify/)
[![Python 3.6+](https://img.shields.io/badge/python-3.6%2B-blue.svg)](https://www.python.org/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

---

## Installation

```bash
pip install fetchify
```

---

## Quick Start

### Module-level API (simple scripts)

```python
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)

```python
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)](https://github.com/settings/tokens) to access private repos:

```python
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.
> ```python
> 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

```python
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](https://github.com/Anupam1707)
