Skip to content

🚀 Your First Packagist Query

In 5 minutes, complete four actions from pure Go: "search packages → view details → view advisories → view statistics". No local PHP or Composer installation required, everything goes through the Packagist REST API.

Why Start Here?

The Packagist API SDK is a pure Go client with no external runtime dependencies. It's the lightest entry point to experience Composer Skills' "typed return values" philosophy — no environment configuration needed, just run and see structured results.

Step 1: Create Client

pkg/client.NewComposerClient accepts an HTTP timeout and returns a ready-to-use client.

go
c := client.NewComposerClient(30 * time.Second)

Step 2: Search Packages

SearchPackages(query, perPage, page) returns *domain.SearchResponse, containing a Results slice and Total count.

Step 3: Get Package Details

GetPackage(name) returns *domain.ComposerPackageInfo, containing description, versions, maintainers, etc.

Step 4: Security Advisories & Statistics

GetSecurityAdvisories() fetches site-wide advisories; GetStatistics() returns total packages and total downloads.

Complete Runnable Example

Save the code below as main.go, then run go run main.go.

go
package main

import (
	"fmt"
	"time"

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

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

	// 1️⃣ Search packages
	results, err := c.SearchPackages("logging", 5, 1)
	if err != nil {
		panic(err)
	}
	fmt.Printf("🔍 Searching for logging, found %d packages, showing %d:\n", results.Total, len(results.Results))
	for _, r := range results.Results {
		fmt.Printf("   - %s: %s\n", r.Name, r.Description)
	}

	// 2️⃣ Get package details
	pkg, err := c.GetPackage("monolog/monolog")
	if err != nil {
		panic(err)
	}
	fmt.Printf("\n📦 %s\n   %s\n", pkg.Package.Name, pkg.Package.Description)

	// 3️⃣ Security advisories
	advisories, err := c.GetSecurityAdvisories()
	if err != nil {
		panic(err)
	}
	fmt.Printf("\n🔒 Packagist has %d packages with security advisories\n", len(advisories.Advisories))

	// 4️⃣ Statistics
	stats, err := c.GetStatistics()
	if err != nil {
		panic(err)
	}
	fmt.Printf("\n📊 Total packages: %d | Total versions: %d | Total downloads: %d\n",
		stats.Totals.Packages, stats.Totals.Versions, stats.Totals.Downloads)
}

Expected Output

🔍 Searching for logging, found 1234 packages, showing 5:
   - monolog/monolog: Sends your logs to files, sockets...
   - ...
📦 monolog/monolog
   Sends your logs to files, sockets, inboxes, databases and various web services

🔒 Packagist has 87 packages with security advisories

📊 Total packages: 390000 | Total versions: 3200000 | Total downloads: 9876543210

The page parameter in SearchPackages enables pagination; for tag filtering use SearchPackagesByTags(tags, perPage, page), for type filtering use SearchPackagesByType(query, packageType, perPage, page).

Only care about a specific package?

Use c.GetPackage("vendor/name") directly, no need to search first. You can also use GetPackageStats to fetch per-version download counts.

Network & Rate Limiting

Packagist is a public API, please set perPage reasonably (recommend ≤ 100) and reuse the same client instance to avoid making many requests in a short time.

Next Steps

Released under the MIT License