Skip to content

Conversation

loonghao
Copy link
Owner

@loonghao loonghao commented May 27, 2025

πŸš€ New Features

This PR adds comprehensive PyPI package download statistics and popularity analysis tools to the MCP server.

✨ What's New

πŸ“Š Download Statistics Tools

  • get_download_statistics - Get comprehensive download statistics for any package
  • get_download_trends - Analyze download trends and time series data (last 180 days)
  • get_top_downloaded_packages - Get the most popular packages by download count

πŸ”§ Core Infrastructure

  • PyPIStatsClient - New async client for pypistats.org API integration
  • Advanced analysis functions - Download trends analysis with growth indicators
  • Repository information integration - Links to GitHub/GitLab repositories
  • Comprehensive caching - Efficient data caching for better performance

🎯 Use Cases

Now you can ask questions like:

  • "What are the download statistics for the requests package this month?"
  • "Show me the download trends for numpy over the last 180 days"
  • "What are the top 10 most downloaded Python packages today?"
  • "Compare the popularity of Django vs Flask vs FastAPI"
  • "Which web framework has the highest download count this week?"

πŸ“ˆ Example Output

{
  "package": "requests",
  "downloads": {
    "last_day": 1500000,
    "last_week": 10500000,
    "last_month": 45000000
  },
  "analysis": {
    "total_downloads": 57000000,
    "highest_period": "last_month",
    "growth_indicators": {
      "daily_vs_weekly": 1.0,
      "weekly_vs_monthly": 0.93
    }
  },
  "metadata": {
    "name": "requests",
    "version": "2.31.0",
    "summary": "Python HTTP for Humans.",
    "project_urls": {
      "Repository": "https://github.com/psf/requests"
    }
  }
}

πŸ§ͺ Testing

  • βœ… Comprehensive unit tests with 76% coverage
  • βœ… Mock-based testing for reliable CI/CD
  • βœ… Integration tests for all new MCP tools
  • βœ… Demo script with real-world examples

πŸ“š Documentation

  • βœ… Updated README with new features and examples
  • βœ… Comprehensive docstrings for all functions
  • βœ… Usage examples and conversation patterns
  • βœ… Demo script (examples/download_stats_demo.py)

πŸ”„ Backward Compatibility

  • βœ… All existing functionality remains unchanged
  • βœ… No breaking changes to existing APIs
  • βœ… New features are additive only

πŸ“¦ Files Changed

  • pypi_query_mcp/core/stats_client.py - New PyPIStatsClient for API integration
  • pypi_query_mcp/tools/download_stats.py - Download statistics tools implementation
  • pypi_query_mcp/server.py - New MCP tools registration
  • tests/test_download_stats.py - Comprehensive test coverage
  • examples/download_stats_demo.py - Demo script with examples
  • README.md - Updated documentation

πŸŽ‰ Ready for Use

This feature is production-ready and can be used immediately after merging. The pypistats.org API is stable and widely used by the Python community.


Note: This implementation uses the pypistats.org API which provides download statistics for the last 180 days. For longer historical data, users can be directed to use Google BigQuery with PyPI datasets.

loonghao added 2 commits May 27, 2025 19:23
- Add PyPIStatsClient for pypistats.org API integration
- Implement get_package_download_stats for recent download statistics
- Implement get_package_download_trends for time series analysis
- Implement get_top_packages_by_downloads for popularity rankings
- Add comprehensive MCP tools for download statistics
- Include download trends analysis with growth indicators
- Add repository information and metadata integration
- Provide comprehensive test coverage
- Add demo script and usage examples
- Update README with new features and examples

Signed-off-by: longhao <hal.long@outlook.com>
- Remove unused imports in stats_client.py and download_stats.py
- Fix import sorting in test files
- Remove unnecessary f-strings in server.py and demo script
- Clean up whitespace and formatting issues
- Ensure all files pass ruff and isort checks

Signed-off-by: longhao <hal.long@outlook.com>
@loonghao loonghao merged commit 3d9d7b4 into main May 27, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant