Unearth Package Fetcher

0.18.2 · active · verified Thu Apr 09

Unearth is a utility library for fetching and downloading Python packages from various sources, including PyPI, local files, and version control systems (Git). It's currently at version 0.18.2 and maintains an active release cadence with frequent bug fixes and minor features.

Warnings

Install

Imports

Quickstart

This example demonstrates how to initialize `Unearth` and use it to find the best match for a Python package from PyPI, using a temporary cache directory.

import tempfile
from pathlib import Path
from unearth import Unearth

# Create a temporary directory for caching resolved packages
with tempfile.TemporaryDirectory() as cache_dir_str:
    cache_dir = Path(cache_dir_str)

    # Instantiate Unearth to search for packages on PyPI
    finder = Unearth(
        index_urls=["https://pypi.org/simple"],
        cache_dir=cache_dir
    )

    # Find matches for a specific package, e.g., 'requests'
    matches = finder.find_matches("requests")

    # Get the best matching distribution
    best_match = matches.best_match

    if best_match:
        print(f"Found best match: {best_match.name} {best_match.version} from {best_match.link.url}")
        # To actually download, you would process best_match.link.url
        # Unearth primarily provides the links, not direct download functionality
    else:
        print("No matches found for requests.")

view raw JSON →