paquet / packagist-client
A typed Packagist API client
Requires
- php: ^8.4
- composer/metadata-minifier: ^1.0.1
- psr/http-factory: ^1.1
- saloonphp/pagination-plugin: ^2.3
- saloonphp/saloon: ^4.0
Requires (Dev)
- carthage-software/mago: ^1.46
- ergebnis/composer-normalize: ^2.52
- phpunit/phpunit: ^11.5
This package is not auto-updated.
Last update: 2026-08-19 21:18:09 UTC
README
A typed PHP client for the Packagist API.
Installation
Install the package with Composer:
composer require paquet/packagist-client
Packagist API
Unauthenticated
Initialize the client with the default configuration for public endpoints:
use Paquet\Packagist\Packagist; $packagist = Packagist::init();
Authenticated
Provide Packagist credentials for authenticated operations:
use Paquet\Packagist\Credentials; use Paquet\Packagist\Packagist; $packagist = Packagist::init( credentials: Credentials::make( username: 'username', apiToken: 'api-token', ), );
Custom Options
Configure the User-Agent or API base URL:
use Paquet\Packagist\Options; use Paquet\Packagist\Packagist; $packagist = Packagist::init( options: Options::make( userAgent: 'my-app/1.0 (mailto:team@example.com)', baseUrl: 'https://packagist.example', ), );
Options may also be passed as a map:
$packagist = Packagist::init(options: [ 'userAgent' => 'my-app/1.0 (mailto:team@example.com)', 'baseUrl' => 'https://packagist.example', ]);
Environment Variables
The API connector loads credentials and options from these environment variables:
PACKAGIST_USERNAME=username
PACKAGIST_API_TOKEN=api-token
PACKAGIST_API_USER_AGENT="my-app/1.0 (mailto:api@example.com)"
PACKAGIST_API_BASE_URL=https://packagist.org
use Paquet\Packagist\Packagist; $packagist = Packagist::init();
Repository API
Use the repository connector to retrieve Composer package metadata:
use Paquet\Packagist\PackagistRepository; $repository = PackagistRepository::init(); $metadata = $repository->packages->tagged('vendor/package');
Metadata Discovery
The repository base URL points to the Composer repository root where packages.json
is available. On the first package request, the connector fetches that file and reads
its metadata-url template:
{
"metadata-url": "https://repo.packagist.org/p2/%package%.json"
}
The template may be absolute, root-relative, or relative to the repository base URL,
and must contain %package%. Tagged requests replace the placeholder with
vendor/package; development requests use vendor/package~dev. The discovered
template is cached for the lifetime of the connector.
Custom Options
Configure the User-Agent or repository base URL:
use Paquet\Packagist\PackagistRepository; use Paquet\Packagist\RepositoryOptions; $repository = PackagistRepository::init( options: RepositoryOptions::make( userAgent: 'my-app/1.0 (mailto:team@example.com)', baseUrl: 'https://repo.packagist.example', ), );
Repository options may also be passed as a map:
$repository = PackagistRepository::init(options: [ 'userAgent' => 'my-app/1.0 (mailto:team@example.com)', 'baseUrl' => 'https://repo.packagist.example', ]);
Environment Variables
The repository connector loads options from these environment variables:
PACKAGIST_REPOSITORY_USER_AGENT="my-app/1.0 (mailto:repository@example.com)"
PACKAGIST_REPOSITORY_BASE_URL=https://repo.packagist.org
use Paquet\Packagist\PackagistRepository; $repository = PackagistRepository::init();
License
Copyright (c) 2026 Nicolas Hedger.
This project is open source and licensed under the MIT License.