pyfetchy 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,32 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.pyo
5
+ *.pyd
6
+ *.so
7
+ *.egg
8
+ *.egg-info/
9
+ dist/
10
+ build/
11
+ .eggs/
12
+ .venv/
13
+ venv/
14
+ env/
15
+
16
+ # fetchy state files
17
+ *.fetchy
18
+
19
+ # pytest
20
+ .pytest_cache/
21
+ .coverage
22
+ htmlcov/
23
+
24
+ # editors
25
+ .vscode/
26
+ .idea/
27
+ *.swp
28
+ *.swo
29
+
30
+ # OS
31
+ .DS_Store
32
+ Thumbs.db
Binary file
Binary file
pyfetchy-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 fetchy contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,156 @@
1
+ Metadata-Version: 2.4
2
+ Name: pyfetchy
3
+ Version: 0.1.0
4
+ Summary: A fast, open-source download manager with parallel segments and resume support
5
+ Project-URL: Homepage, https://github.com/Uruskus/fetchy
6
+ Project-URL: Issues, https://github.com/Uruskus/fetchy/issues
7
+ Author: fetchy contributors
8
+ License: MIT
9
+ License-File: LICENSE
10
+ Keywords: cli,download,manager,parallel,resume
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: End Users/Desktop
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Internet :: WWW/HTTP
20
+ Classifier: Topic :: Utilities
21
+ Requires-Python: >=3.10
22
+ Requires-Dist: httpx>=0.27.0
23
+ Requires-Dist: rich>=13.0.0
24
+ Requires-Dist: typer>=0.12.0
25
+ Description-Content-Type: text/markdown
26
+
27
+ # fetchy
28
+
29
+ > A fast, open-source CLI download manager — a free alternative to IDM.
30
+
31
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10%2B-blue)](https://python.org)
32
+ [![License: MIT](https://img.shields.io/badge/license-MIT-green)](LICENSE)
33
+ [![PyPI](https://img.shields.io/pypi/v/fetchy)](https://pypi.org/project/fetchy)
34
+
35
+ fetchy splits files into parallel segments using HTTP Range Requests, giving you faster downloads and the ability to resume interrupted transfers — right from your terminal.
36
+
37
+ ---
38
+
39
+ ## Features
40
+
41
+ - **Parallel downloads** — splits files into N segments downloaded simultaneously
42
+ - **Resume support** — interrupted downloads continue from where they left off
43
+ - **Live progress** — per-segment bars with speed and ETA
44
+ - **Retry logic** — transient errors are retried automatically with exponential backoff
45
+ - **Cross-platform** — works on Windows, macOS, and Linux
46
+ - **Zero config** — sensible defaults, fully configurable via flags
47
+
48
+ ---
49
+
50
+ ## Installation
51
+
52
+ ```bash
53
+ pip install fetchy
54
+ ```
55
+
56
+ Or install from source:
57
+
58
+ ```bash
59
+ git clone https://github.com/yourusername/fetchy.git
60
+ cd fetchy
61
+ pip install -e .
62
+ ```
63
+
64
+ ---
65
+
66
+ ## Usage
67
+
68
+ ```bash
69
+ # Basic download (4 segments by default)
70
+ fetchy get https://example.com/largefile.zip
71
+
72
+ # Save to a specific directory or filename
73
+ fetchy get https://example.com/largefile.zip -o ~/Downloads/
74
+ fetchy get https://example.com/largefile.zip -o ~/Downloads/myfile.zip
75
+
76
+ # Use 8 parallel segments
77
+ fetchy get https://example.com/largefile.zip -s 8
78
+
79
+ # Disable resume (start fresh even if a state file exists)
80
+ fetchy get https://example.com/largefile.zip --no-resume
81
+
82
+ # Show version
83
+ fetchy --version
84
+ ```
85
+
86
+ **Resuming:** if you press `Ctrl+C` during a download, fetchy saves a `.fetchy` state file next to the output file. Run the same command again to resume automatically.
87
+
88
+ ---
89
+
90
+ ## How it works
91
+
92
+ 1. fetchy sends a `HEAD` request to check the file size and whether the server supports `Range` requests.
93
+ 2. If supported, the file is split into N equally-sized byte ranges.
94
+ 3. Each segment is downloaded in parallel using async HTTP (httpx).
95
+ 4. Segments are written directly to their correct offset in the pre-allocated output file — no temp files to merge.
96
+ 5. Progress and speed are tracked per segment and shown in a live Rich display.
97
+ 6. On completion the `.fetchy` state file is deleted automatically.
98
+
99
+ ---
100
+
101
+ ## Options
102
+
103
+ | Flag | Default | Description |
104
+ |---|---|---|
105
+ | `-o`, `--output` | `.` (current dir) | Output file or directory |
106
+ | `-s`, `--segments` | `4` | Number of parallel segments |
107
+ | `-r`, `--retries` | `5` | Max retries per segment |
108
+ | `--resume / --no-resume` | `--resume` | Resume interrupted downloads |
109
+
110
+ ---
111
+
112
+ ## Development
113
+
114
+ ```bash
115
+ # Install with dev dependencies
116
+ pip install -e ".[dev]"
117
+
118
+ # Run tests
119
+ pytest
120
+
121
+ # Run a local download test
122
+ fetchy get https://speed.hetzner.de/100MB.bin -s 8
123
+ ```
124
+
125
+ ### Project structure
126
+
127
+ ```
128
+ fetchy/
129
+ ├── src/
130
+ │ └── fetchy/
131
+ │ ├── __init__.py # version
132
+ │ ├── cli.py # Typer CLI entry point
133
+ │ ├── downloader.py # core engine (segments, resume, retry)
134
+ │ └── progress.py # Rich progress display
135
+ ├── tests/
136
+ │ └── test_downloader.py
137
+ ├── pyproject.toml
138
+ └── README.md
139
+ ```
140
+
141
+ ---
142
+
143
+ ## Contributing
144
+
145
+ Contributions are welcome! Please open an issue first to discuss what you'd like to change.
146
+
147
+ 1. Fork the repo
148
+ 2. Create a feature branch (`git checkout -b feature/your-feature`)
149
+ 3. Commit your changes
150
+ 4. Open a pull request
151
+
152
+ ---
153
+
154
+ ## License
155
+
156
+ MIT — see [LICENSE](LICENSE).
@@ -0,0 +1,130 @@
1
+ # fetchy
2
+
3
+ > A fast, open-source CLI download manager — a free alternative to IDM.
4
+
5
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10%2B-blue)](https://python.org)
6
+ [![License: MIT](https://img.shields.io/badge/license-MIT-green)](LICENSE)
7
+ [![PyPI](https://img.shields.io/pypi/v/fetchy)](https://pypi.org/project/fetchy)
8
+
9
+ fetchy splits files into parallel segments using HTTP Range Requests, giving you faster downloads and the ability to resume interrupted transfers — right from your terminal.
10
+
11
+ ---
12
+
13
+ ## Features
14
+
15
+ - **Parallel downloads** — splits files into N segments downloaded simultaneously
16
+ - **Resume support** — interrupted downloads continue from where they left off
17
+ - **Live progress** — per-segment bars with speed and ETA
18
+ - **Retry logic** — transient errors are retried automatically with exponential backoff
19
+ - **Cross-platform** — works on Windows, macOS, and Linux
20
+ - **Zero config** — sensible defaults, fully configurable via flags
21
+
22
+ ---
23
+
24
+ ## Installation
25
+
26
+ ```bash
27
+ pip install fetchy
28
+ ```
29
+
30
+ Or install from source:
31
+
32
+ ```bash
33
+ git clone https://github.com/yourusername/fetchy.git
34
+ cd fetchy
35
+ pip install -e .
36
+ ```
37
+
38
+ ---
39
+
40
+ ## Usage
41
+
42
+ ```bash
43
+ # Basic download (4 segments by default)
44
+ fetchy get https://example.com/largefile.zip
45
+
46
+ # Save to a specific directory or filename
47
+ fetchy get https://example.com/largefile.zip -o ~/Downloads/
48
+ fetchy get https://example.com/largefile.zip -o ~/Downloads/myfile.zip
49
+
50
+ # Use 8 parallel segments
51
+ fetchy get https://example.com/largefile.zip -s 8
52
+
53
+ # Disable resume (start fresh even if a state file exists)
54
+ fetchy get https://example.com/largefile.zip --no-resume
55
+
56
+ # Show version
57
+ fetchy --version
58
+ ```
59
+
60
+ **Resuming:** if you press `Ctrl+C` during a download, fetchy saves a `.fetchy` state file next to the output file. Run the same command again to resume automatically.
61
+
62
+ ---
63
+
64
+ ## How it works
65
+
66
+ 1. fetchy sends a `HEAD` request to check the file size and whether the server supports `Range` requests.
67
+ 2. If supported, the file is split into N equally-sized byte ranges.
68
+ 3. Each segment is downloaded in parallel using async HTTP (httpx).
69
+ 4. Segments are written directly to their correct offset in the pre-allocated output file — no temp files to merge.
70
+ 5. Progress and speed are tracked per segment and shown in a live Rich display.
71
+ 6. On completion the `.fetchy` state file is deleted automatically.
72
+
73
+ ---
74
+
75
+ ## Options
76
+
77
+ | Flag | Default | Description |
78
+ |---|---|---|
79
+ | `-o`, `--output` | `.` (current dir) | Output file or directory |
80
+ | `-s`, `--segments` | `4` | Number of parallel segments |
81
+ | `-r`, `--retries` | `5` | Max retries per segment |
82
+ | `--resume / --no-resume` | `--resume` | Resume interrupted downloads |
83
+
84
+ ---
85
+
86
+ ## Development
87
+
88
+ ```bash
89
+ # Install with dev dependencies
90
+ pip install -e ".[dev]"
91
+
92
+ # Run tests
93
+ pytest
94
+
95
+ # Run a local download test
96
+ fetchy get https://speed.hetzner.de/100MB.bin -s 8
97
+ ```
98
+
99
+ ### Project structure
100
+
101
+ ```
102
+ fetchy/
103
+ ├── src/
104
+ │ └── fetchy/
105
+ │ ├── __init__.py # version
106
+ │ ├── cli.py # Typer CLI entry point
107
+ │ ├── downloader.py # core engine (segments, resume, retry)
108
+ │ └── progress.py # Rich progress display
109
+ ├── tests/
110
+ │ └── test_downloader.py
111
+ ├── pyproject.toml
112
+ └── README.md
113
+ ```
114
+
115
+ ---
116
+
117
+ ## Contributing
118
+
119
+ Contributions are welcome! Please open an issue first to discuss what you'd like to change.
120
+
121
+ 1. Fork the repo
122
+ 2. Create a feature branch (`git checkout -b feature/your-feature`)
123
+ 3. Commit your changes
124
+ 4. Open a pull request
125
+
126
+ ---
127
+
128
+ ## License
129
+
130
+ MIT — see [LICENSE](LICENSE).
@@ -0,0 +1,3 @@
1
+ """fetchy – a fast, open-source CLI download manager."""
2
+
3
+ __version__ = "0.1.0"
@@ -0,0 +1,172 @@
1
+ """
2
+ fetchy CLI – entry point.
3
+
4
+ Usage examples:
5
+ fetchy https://example.com/file.zip
6
+ fetchy https://example.com/file.zip -o ~/Downloads/
7
+ fetchy https://example.com/file.zip -s 8
8
+ fetchy https://example.com/file.zip --resume
9
+ """
10
+
11
+ import asyncio
12
+ from pathlib import Path
13
+ from typing import Optional
14
+
15
+ import typer
16
+ from rich.console import Console
17
+
18
+ from fetchy import __version__
19
+ from fetchy.downloader import download, _get_file_info, _load_state
20
+ from fetchy.progress import DownloadProgress
21
+
22
+ import httpx
23
+
24
+ app = typer.Typer(
25
+ name="fetchy",
26
+ help="A fast, open-source CLI download manager with parallel segments.",
27
+ add_completion=False,
28
+ )
29
+ console = Console()
30
+
31
+
32
+ def _version_callback(value: bool) -> None:
33
+ if value:
34
+ console.print(f"fetchy {__version__}")
35
+ raise typer.Exit()
36
+
37
+
38
+ @app.callback()
39
+ def main(
40
+ version: Optional[bool] = typer.Option(
41
+ None,
42
+ "--version",
43
+ "-v",
44
+ callback=_version_callback,
45
+ is_eager=True,
46
+ help="Show version and exit.",
47
+ ),
48
+ ) -> None:
49
+ """fetchy – download files fast with parallel HTTP segments."""
50
+
51
+
52
+ @app.command()
53
+ def get(
54
+ url: str = typer.Argument(..., help="URL of the file to download"),
55
+ output: Optional[Path] = typer.Option(
56
+ None,
57
+ "--output",
58
+ "-o",
59
+ help="Output file or directory (default: current directory)",
60
+ ),
61
+ segments: int = typer.Option(
62
+ 4,
63
+ "--segments",
64
+ "-s",
65
+ min=1,
66
+ max=32,
67
+ help="Number of parallel download segments",
68
+ ),
69
+ retries: int = typer.Option(
70
+ 5,
71
+ "--retries",
72
+ "-r",
73
+ help="Max retries per segment on error",
74
+ ),
75
+ resume: bool = typer.Option(
76
+ True,
77
+ "--resume/--no-resume",
78
+ help="Resume an interrupted download if a .fetchy state file exists",
79
+ ),
80
+ ) -> None:
81
+ """Download a file from URL using parallel segments."""
82
+
83
+ # Resolve output path
84
+ out = output or Path(".")
85
+
86
+ # Check for existing resume state before probing the server
87
+ if out.is_dir():
88
+ # We don't know the filename yet – probe first
89
+ existing_state = None
90
+ else:
91
+ existing_state = _load_state(out) if resume else None
92
+
93
+ # Run the async download
94
+ try:
95
+ asyncio.run(
96
+ _run_download(url, out, segments, retries, resume)
97
+ )
98
+ except KeyboardInterrupt:
99
+ console.print("\n[yellow]Download paused.[/yellow] Run the same command to resume.")
100
+ raise typer.Exit(1)
101
+ except Exception as exc:
102
+ console.print(f"\n[red]Error:[/red] {exc}")
103
+ raise typer.Exit(1)
104
+
105
+
106
+ async def _run_download(
107
+ url: str,
108
+ output: Path,
109
+ num_segments: int,
110
+ max_retries: int,
111
+ resume: bool,
112
+ ) -> None:
113
+ """Async wrapper that wires up the progress display and calls the downloader."""
114
+
115
+ # Probe the server to get file info for the progress display
116
+ async with httpx.AsyncClient(timeout=30) as client:
117
+ total_size, supports_ranges, filename = await _get_file_info(client, url)
118
+
119
+ # If output is a directory, figure out the final path
120
+ if output.is_dir():
121
+ final_path = output / filename
122
+ else:
123
+ final_path = output
124
+ filename = final_path.name
125
+
126
+ # Adjust segment count if the server doesn't support ranges
127
+ effective_segments = num_segments if supports_ranges and total_size > 0 else 1
128
+ if effective_segments == 1 and num_segments > 1:
129
+ console.print(
130
+ "[yellow]Server does not support Range requests – using single-stream download.[/yellow]"
131
+ )
132
+
133
+ # Check for resume state
134
+ existing = _load_state(final_path) if resume else None
135
+ if existing and not existing.completed:
136
+ console.print(f"[green]Resuming[/green] interrupted download of [bold]{filename}[/bold]")
137
+ already_downloaded = sum(s.downloaded for s in existing.segments)
138
+ console.print(
139
+ f" {_fmt_bytes(already_downloaded)} of {_fmt_bytes(total_size)} already downloaded"
140
+ )
141
+ else:
142
+ console.print(f"[bold]Downloading[/bold] [cyan]{filename}[/cyan]")
143
+ if total_size:
144
+ console.print(f" Size: {_fmt_bytes(total_size)} | Segments: {effective_segments}")
145
+
146
+ with DownloadProgress(total_size, effective_segments, filename) as dp:
147
+ # Pre-advance progress bars for already-downloaded bytes (resume case)
148
+ if existing and not existing.completed:
149
+ for seg in existing.segments:
150
+ if seg.downloaded > 0:
151
+ dp._progress.advance(dp._overall_task, seg.downloaded)
152
+ if seg.index in dp._segment_tasks:
153
+ dp._progress.advance(dp._segment_tasks[seg.index], seg.downloaded)
154
+
155
+ await download(
156
+ url=url,
157
+ output_path=final_path,
158
+ num_segments=effective_segments,
159
+ on_progress=dp.update,
160
+ max_retries=max_retries,
161
+ )
162
+
163
+ console.print(f"\n[bold green]Done![/bold green] Saved to [cyan]{final_path}[/cyan]")
164
+
165
+
166
+ def _fmt_bytes(n: int) -> str:
167
+ """Format a byte count as a human-readable string."""
168
+ for unit in ("B", "KB", "MB", "GB", "TB"):
169
+ if n < 1024:
170
+ return f"{n:.1f} {unit}"
171
+ n /= 1024
172
+ return f"{n:.1f} PB"