PyPI Package Analyzer is a command-line tool written in Python to fetch, analyze, and store metadata about packages available on the Python Package Index (PyPI). It helps in gathering quick insights about Python libraries.
- Fetch Data: Retrieves comprehensive package metadata directly from the official PyPI JSON API.
- Analyze: Extracts key information like latest version, author, license, summary, Python version requirements, etc.
- Store Results:
- Saves the raw, complete JSON response from PyPI for each package (optional).
- Saves the processed, summarized analysis into a clean CSV file for easy viewing and further processing.
- Command-Line Interface: Easy-to-use CLI built with
argparsefor specifying packages and output options. - Robustness: Includes error handling for common issues like network errors, timeouts, and non-existent packages.
- Logging: Provides informative logs during execution.
- Testing: Includes unit tests using
pytestandpytest-mockto ensure core functionality works as expected. - Modularity: Code is structured into logical components (fetching, analyzing, storage).
- The tool takes a list of package names as input via the command line.
- For each package name, it constructs the PyPI JSON API URL (e.g.,
https://pypi.org/pypi/requests/json). - It sends an HTTP GET request to the URL using the
requestslibrary. - If the request is successful, it parses the JSON response. Error handling is in place for network issues or if the package isn't found (404).
- (Optional) The raw JSON data for all successfully fetched packages is saved to a single JSON file.
- The collected raw data is processed using the
pandaslibrary. Key fields are extracted into a structured format. - The processed data is organized into a pandas DataFrame.
- This DataFrame, containing the summarized analysis, is saved to a CSV file in the
data/directory.
Follow these steps to set up the project locally:
-
Clone the repository:
git clone <https://github.com/stex4cs/PyPi-Analyzer.git> cd pypi_analyzer
-
Create and activate a virtual environment: This isolates project dependencies.
# Create the environment (use python3 if python maps to Python 2) python -m venv venv # Activate the environment: # On Windows (Git Bash or WSL): # source venv/Scripts/activate # On Windows (Command Prompt/PowerShell): # .\venv\Scripts\activate # On macOS/Linux: source venv/bin/activate
You should see
(venv)at the beginning of your terminal prompt. -
Install dependencies:
pip install -r requirements.txt
The tool is run from the command line within the project's root directory. Make sure your virtual environment is activated.
Basic Command:
python -m pypi_analyzer.main --packages <package1> <package2> ...