Skip to content

📊 GetPackageStats

Fetches the download statistics and the list of available versions for a given package.

When to use

📈 Monitor a package's daily / monthly / total downloads and plot trends; 🎯 evaluate a package's popularity before adopting it; 📋 list a package's available versions to assist with version constraint resolution.

Signature

go
func (c *ComposerClient) GetPackageStats(packageName string) (*domain.PackageStatsResponse, error)

Parameters

ParameterTypeDescription
packageNamestringPackage name, e.g. symfony/console

Return value

ValueTypeDescription
Result*domain.PackageStatsResponseContains download statistics (total/monthly/daily), the version list, and the statistics date
ErrorerrorReturned on HTTP failure, non-200 status, or JSON parse failure

Corresponding endpoint: GET https://packagist.org/packages/{name}/stats.json.

Example

go
package main

import (
	"fmt"
	"log"
	"time"

	"github.com/scagogogo/composer-skills/pkg/client"
)

func main() {
	c := client.NewComposerClient(30 * time.Second)

	stats, err := c.GetPackageStats("symfony/console")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Total downloads: %d\n", stats.Downloads.Total)
	fmt.Printf("Monthly downloads: %d\n", stats.Downloads.Monthly)
	fmt.Printf("Daily downloads: %d\n", stats.Downloads.Daily)
	fmt.Printf("Available versions: %d\n", len(stats.Versions))
	fmt.Printf("Stats start date: %s\n", stats.Date)
}

Advanced

  • 📦 To get the full set of downloads + stars + maintainers in one call, use GetPackage (its Downloads field has the same structure).
  • 🚀 For incremental package change sync, use GetPackageChanges.
  • 📈 For repository-wide totals, use GetStatistics.

Released under the MIT License