Skip to main content

Track, store and query your PyPI package download statistics

Project description

pkgdb

Track, store, and analyze PyPI package download statistics.

Fetches download stats via the pypistats API, stores historical data in SQLite, and generates HTML reports with charts.

Installation

pip install pkgdb

To build:

Requires Python 3.10+. Uses uv for dependency management.

uv sync

Usage

Configure packages

Edit packages.yml to list the packages you want to track:

published:
  - my-package
  - another-package

Commands

# Fetch latest stats from PyPI and store in database
pkgdb fetch

# Display stats in terminal (includes trend sparklines and growth %)
pkgdb list

# Show historical stats for a specific package
pkgdb history <package-name>

# Generate HTML report with charts (opens in browser)
pkgdb report

# Generate detailed HTML report for a single package
pkgdb report <package-name>

# Include environment summary (Python versions, OS) in report
pkgdb report -e

# Export stats in various formats
pkgdb export -f csv      # CSV format (default)
pkgdb export -f json     # JSON format
pkgdb export -f markdown # Markdown table

# Show detailed stats for a package (Python versions, OS breakdown)
pkgdb stats <package-name>

# Fetch stats and generate report in one step
pkgdb update

Options

# Use custom database file
pkgdb -d custom.db fetch

# Use custom packages file
pkgdb -p custom.yml fetch

# Specify output file for report
pkgdb report -o custom-report.html

# Limit history output to N days
pkgdb history my-package -n 14

# Export to file instead of stdout
pkgdb export -f json -o stats.json

Architecture

Single-file CLI application with seven commands:

  • fetch: Calls pypistats.recent() and pypistats.overall() for each package, stores results in SQLite
  • list: Queries latest stats per package with trend sparklines and growth metrics
  • history: Shows historical data for a specific package over time
  • report: Generates self-contained HTML report with SVG charts (bar charts + time-series). With -e flag, includes Python version and OS distribution summary. With package argument, generates detailed single-package report
  • export: Exports stats in CSV, JSON, or Markdown format
  • stats: Shows detailed breakdown (Python versions, OS) for a single package
  • update: Runs fetch then report

Data flow

packages.yml -> pypistats API -> SQLite (pkg.db) -> HTML/terminal output

Database schema

The package_stats table stores:

  • package_name: Package identifier
  • fetch_date: Date stats were fetched (YYYY-MM-DD)
  • last_day, last_week, last_month: Recent download counts
  • total: Total downloads (excluding mirrors)

Stats are upserted per package per day, so running fetch multiple times on the same day updates rather than duplicates.

Files

  • pkgdb.py: Main CLI application
  • packages.yml: Package list configuration
  • pkg.db: SQLite database (auto-created)
  • report.html: Generated HTML report (default output)

Development

# Install dev dependencies
uv sync

# Run tests
pytest

# Run tests with verbose output
pytest -v

Dependencies

Runtime:

  • pypistats: PyPI download statistics API client
  • pyyaml: YAML configuration parsing
  • tabulate: Terminal table formatting

Development:

  • pytest: Testing framework

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pkgdb-0.1.2.tar.gz (15.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pkgdb-0.1.2-py3-none-any.whl (15.9 kB view details)

Uploaded Python 3

File details

Details for the file pkgdb-0.1.2.tar.gz.

File metadata

  • Download URL: pkgdb-0.1.2.tar.gz
  • Upload date:
  • Size: 15.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for pkgdb-0.1.2.tar.gz
Algorithm Hash digest
SHA256 463766c06abfcfc999c722ac387f9cf67160df7ab67f4931da44960513e81c7a
MD5 437e4b6cd1575a37bfc3a11d92e72f3a
BLAKE2b-256 69380313a4925f45bc841465b279df0ee66f80e2fa23af2e792a6614c5f0c6ff

See more details on using hashes here.

File details

Details for the file pkgdb-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: pkgdb-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 15.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for pkgdb-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ab7977cf36bc29c0052848aa4faee04fe95533b9c38063e03216a5a1675c0e83
MD5 0b6bb05e6a4182cc6d5a7678d0e9ba61
BLAKE2b-256 9839917d524a524dff4444cb4fe1704907c53e2df9cf8c1f10819be79cf0f8d4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page