In a previous post, I was trying to parse out the most popular Composer packages, and wasn’t able to find a way to get the information through any kind of API. I ended up doing a simple scrape, but then I started searching through the Packagist code , and I found some interesting gems.
First, is a list of ALL the packages: https://packagist.org/packages/list.json . It produces a simple list of all 7002 (at the moment) packages in json.
{
"packageNames": [
"illuminate/auth",
"illuminate/cache",
"illuminate/config",
"illuminate/console",
"illuminate/container",
"illuminate/cookie",
"illuminate/database",
"illuminate/encryption",
"illuminate/events",
"illuminate/exception",
"illuminate/filesystem",
"illuminate/foundation",
"illuminate/hashing",
"illuminate/http",
"illuminate/log",
"illuminate/mail",
"illuminate/pagination",
"illuminate/queue",
"illuminate/redis",
"illuminate/routing",
"illuminate/session",
"illuminate/socialite",
"illuminate/support",
"illuminate/translation",
"illuminate/validation",
"illuminate/view",
"illuminate/workbench",
]
}
With that list, you could easily get the specifics about each package at https://packagist.org/p/{package-name}.json. For example: https://packagist.org/p/illuminate/database.json . But what about searching? The Packagist website UI isn’t the most intuitive, but there a couple of queries that make the search fairly powerful. First, is just a regular search like : https://packagist.org/search.json?q=laravel This is fine. It mirrors the site’s search and it’s nice that it includes the ‘downloads’ and ‘favers’
{
"results": [
{
"name": "laravel/framework",
"description": "The Laravel Framework.",
"url": "https://packagist.org/packages/laravel/framework",
"downloads": 6493,
"favers": 4
},
{
"name": "laravel/curl",
"description": "Laravel Curl Helper Library inspired by Phil",
"url": "https://packagist.org/packages/laravel/curl",
"downloads": 87,
"favers": 0
},
],
"total": 77,
"next": "https://packagist.org/search.json?q=laravel&page=2"
}
But we can get even fancier and search the tags as well: https://packagist.org/search.json?tags=laravel
{
"results": [
{
"name": "laravel/framework",
"description": "The Laravel Framework.",
"url": "https://packagist.org/packages/laravel/framework",
"downloads": 6493,
"favers": 4
},
{
"name": "composer/installers",
"description": "A multi-framework Composer library installer",
"url": "https://packagist.org/packages/composer/installers",
"downloads": 5562,
"favers": 2
},
{
"name": "cartalyst/sentry",
"description": "PHP 5.3+ fully-featured authentication & authorization system",
"url": "https://packagist.org/packages/cartalyst/sentry",
"downloads": 731,
"favers": 2
},
{
"name": "illuminate/database",
"description": "An elegant database abstraction library.",
"url": "https://packagist.org/packages/illuminate/database",
"downloads": 10787,
"favers": 1
}
],
"total": 60,
"next": "https://packagist.org/search.json?page=2&tags%5B0%5D=laravel"
}
Let’s say we only want packages that are tagged with “laravel” AND “database”. That’s possible, too: https://packagist.org/search.json?tags[]=laravel&tags[]=database
{
"results": [
{
"name": "illuminate/database",
"description": "An elegant database abstraction library.",
"url": "https://packagist.org/packages/illuminate/database",
"downloads": 10787,
"favers": 1
},
{
"name": "laravelbook/ardent",
"description": "Self-validating smart models for Laravel 4's Eloquent O/RM",
"url": "https://packagist.org/packages/laravelbook/ardent",
"downloads": 69,
"favers": 1
},
{
"name": "jtgrimes/laravelodbc",
"description": "Adds an ODBC driver to Laravel4",
"url": "https://packagist.org/packages/jtgrimes/laravelodbc",
"downloads": 5,
"favers": 0
},
{
"name": "dhorrigan/capsule",
"description": "A simple wrapper class for the Laravel Database package. This is only to be used outside of a Laravel application.",
"url": "https://packagist.org/packages/dhorrigan/capsule",
"downloads": 79,
"favers": 0
},
{
"name": "iyoworks/elegant",
"description": "",
"url": "https://packagist.org/packages/iyoworks/elegant",
"downloads": 12,
"favers": 0
}
],
"total": 5
}
You can also search for a “type”, like https://packagist.org/search.json?type=symfony-module or even mix the queries like so: https://packagist.org/search.json/?q=laravel&tags[]=orm&tags[]=database
Other interesting ways to view the data can be found at: https://packagist.org/packages.json … so if you wanted to view packages only released in January of 2013, you can use: https://packagist.org/p/packages-2013-01.json
My favorite “hack”, is searching with an empty value like so: https://packagist.org/search.json?page=1&q= … which returns all the records (15 on a page), ordered by popularity.
One of these days, if someone else doesn’t beat me to it, I’ll make a review/upvote/downvote site so that the best packages can be found a bit easier. Also, there are some excellent packages that have almost no documentation… so having comments that explain some use-cases would be nice.