Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Packagist Api

Packagist Api Laravel Package

spatie/packagist-api

Spatie's PHP package makes it easy to search and fetch package info from the Packagist API. Pass a Guzzle client and URL generator to the client, then list package names by type or vendor, fetch popular packages with pagination, and more.

View on GitHub
Deep Wiki
Context7

spatie/packagist-api is a lightweight PHP client that makes it easy to search and fetch package info using the Packagist API. You simply inject a Guzzle client and the built-in URL generator into PackagistClient, then query packages without hand-crafting HTTP requests or parsing raw responses yourself.

  • List all package names, or filter by type and vendor
  • Fetch popular packages with built-in pagination support
  • Retrieve detailed package metadata and search results
  • Clean, testable API with dependency injection at its core
  • Optional Laravel wrapper available

Install it via Composer with composer require spatie/packagist-api.

Frequently asked questions about Packagist Api
How do I install and use spatie/packagist-api in a Laravel project?
Install it with composer require spatie/packagist-api, then construct Spatie\Packagist\PackagistClient with a GuzzleHttp\Client and a PackagistUrlGenerator. The package ships no service provider or config file, so in Laravel you typically bind the client as a singleton in one of your own service providers and inject it behind your own interface. From there you can call helpers such as getPackagesNames, getPackagesNamesByVendor, or getPopularPackages directly.
Which Laravel and PHP versions does spatie/packagist-api support?
The package is framework agnostic and contains no Laravel-specific code, so Laravel compatibility is really a function of its PHP floor and Guzzle constraint rather than a Laravel release matrix. Check the composer.json of the exact version you intend to pin and confirm it resolves against the PHP and Guzzle versions already in your lockfile. On a supported PHP 8.x runtime with Guzzle 7 installed, it will run inside Laravel without any framework integration.
How do I search or list packages on Packagist from PHP?
PackagistClient wraps the public Packagist API with helpers: getPackagesNames returns all package names, getPackagesNamesByType and getPackagesNamesByVendor return filtered lists, and getPopularPackages returns the popular listing. Popular packages are paginated, so you can pass a page number and page size to walk through results. You can also fetch details for a specific package through the client instead of building URLs by hand.
Can I pass my own pre-configured Guzzle client to PackagistClient?
Yes. The constructor requires a GuzzleHttp\Client plus a PackagistUrlGenerator, so you can inject the same shared client your application already uses for proxies, TLS settings, timeouts, and middleware. That keeps observability, retry policy, and egress rules centralized instead of creating a second HTTP path. It also makes the client trivial to fake in tests.
Is there an official Laravel service provider or config file for Packagist API access?
No. spatie/packagist-api deliberately ships no service provider, facade, or config file because it is a plain PHP client. A third-party wrapper, markwalet/laravel-packagist, adds config and container ergonomics, but that is an extra dependency you do not control for roughly twenty lines of binding code. Most teams wire the client in their own service provider and let the rest of the codebase depend on their own gateway interface.
How should I test code that calls spatie/packagist-api?
Because the client accepts a Guzzle client, you can swap in a Guzzle MockHandler or a handler stack that replays recorded Packagist responses, so tests never touch the network. Integration tests that hit packagist.org directly are inherently flaky and will erode trust in CI. Budget for contract tests against fixtures in your own suite, and normalize responses in an adapter so recorded shapes stay valid.
Does spatie/packagist-api handle caching, retries, or rate limiting?
No. It is a stateless, read-only HTTP client and implements no caching, retries, backoff, rate limiting, or snapshot persistence; that layer is yours to build. Packagist offers no SLA and its politeness expectations are social rather than contractual, so aggressive polling risks throttling or blocking. Define a caching and rate-limit policy, and decide who owns it, before you go to production.
Is spatie/packagist-api safe to depend on in production?
It is a small MIT-licensed client of a few hundred lines over Guzzle, so you can read the entire surface and fork or vendor it if necessary. The main risk is upstream rather than in the code: availability is coupled to Packagist's public API, and adoption is thin, so edge cases are not heavily community-validated. Wrap it behind an interface you own, pin exact versions, and read changelogs, since release 2.1.1 was flagged as a breaking change in a patch position.
Why did a patch upgrade of spatie/packagist-api break my code?
Release 2.1.1 was flagged as a backward-incompatible change in a patch position, involving metadata and response shape changes between v1 and v2. Pin an exact version instead of using a caret constraint if you want predictable upgrades. Also normalize Packagist responses inside your own adapter so upstream shape changes never reach your domain code.
What are the alternatives to spatie/packagist-api?
You can call the Packagist API directly with Guzzle or Laravel's HTTP client, which is realistic given the package is mostly URL construction, response handling, and vendor/package parsing. markwalet/laravel-packagist offers a Laravel-flavored wrapper if you want config and container bindings out of the box. If you already have hand-rolled curl or Guzzle calls against Packagist, adopting this package is itself the migration.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
adachsoft/changelog-linter
adachsoft/collection
payerurl/telegrambot-crypto-payment-instant-payout
dskripchenko/laravel-hybrid-search
riorizkyrainey/lara-ced
mehedimi/static-vel
zharp/zharp
nonsapiens/bigquery-model-sync
lgu-bayambang-ict-office/lgu-laravel-development-standards
andydefer/laravel-support
se7enxweb/flysystem
lampwick/laravel
jeslage/statamic-emojis
micahdshackelford/rmap-laravel
draftsmaninc/draftsman
square-bit/laravel-volition
himito/laravel-mailman
htinlynn/genius-helper
maco-studios/hephaestus
elmogy/larafast