Metadata-Version: 2.4
Name: pypi-bulk-download
Version: 0.1.0
Summary: Bulk-download PyPI packages filtered by popularity (monthly downloads), in parallel, with safe archive unpacking and a JSON manifest. Handy for building research corpora.
Project-URL: Homepage, https://github.com/krc7169/pypi-bulk-download
Project-URL: Issues, https://github.com/krc7169/pypi-bulk-download/issues
Author-email: krc7169 <krc7169@gmail.com>
License: MIT License
        
        Copyright (c) 2026 krc7169
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: bulk,corpus,download,mirror,pypi,research,supply-chain,top-packages
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: System :: Archiving :: Packaging
Requires-Python: >=3.9
Requires-Dist: requests>=2.20
Provides-Extra: dev
Requires-Dist: build; extra == 'dev'
Requires-Dist: pytest>=7; extra == 'dev'
Requires-Dist: twine; extra == 'dev'
Description-Content-Type: text/markdown

# pypi-bulk-download

Download PyPI packages **in bulk**, filtered by real-world popularity, in
parallel, with **safe archive unpacking** and a JSON manifest. Built for
assembling research corpora (security scanning, ecosystem analysis, mirrors)
without hand-rolling `pip download` loops.

Downloads go through `pip download`, so wheels, sdists, platform tags, and
custom indexes behave exactly as pip does. Popularity comes from the public
[top-pypi-packages](https://hugovk.github.io/top-pypi-packages/) 30-day dataset.

## Install

```bash
pip install pypi-bulk-download
```

## CLI

```bash
# Top 50 packages with >= 100k downloads/month, source dists, no deps
pypi-bulk-download --min-downloads 100000 --limit 50 --format sdist --no-deps -o corpus/

# Specific packages, 4 workers, write a manifest
pypi-bulk-download --packages requests flask httpx --workers 4 --save-manifest corpus/manifest.json

# From a requirements file, then safely unpack every archive
pypi-bulk-download -r requirements.txt -o corpus/ --unpack

# See the plan without downloading
pypi-bulk-download --min-downloads 50000 --limit 20 --dry-run
```

## Library

```python
from pypi_bulk_download import fetch_top_packages, download_many, save_manifest

targets = fetch_top_packages(min_downloads=100_000, limit=25)
results = download_many(targets, "corpus/", workers=4, prefer_format="sdist", no_deps=True)
save_manifest(results, "corpus/manifest.json")

print(sum(r.success for r in results), "of", len(results), "downloaded")
```

### Safe unpacking

`unpack_archive` / `unpack_all` validate every tar/zip member against path
traversal (tar-slip / zip-slip) before extracting — untrusted archives can't
write outside their destination folder.

```python
from pypi_bulk_download import unpack_all
unpacked, failed = unpack_all("corpus/", remove_archives=False)
```

## Notes

- Depends only on `requests` (plus `pip`, which you already have).
- `--format sdist` falls back to the best wheel when no source distribution
  exists, rather than failing hard.
- **This tool downloads third-party code.** Do not commit the download
  directory to your own repository; the included `.gitignore` excludes `pkgs/`,
  `downloads/`, and archive files by default.

## License

MIT (this tool). Downloaded packages retain their own licenses.
