An unofficial API client for Pub.dev
This package aims to be a complete, stable pub.dev API client. If an endpoint is missing, please open an issue.
A simple usage example:
import 'package:pub_api_client/pub_api_client.dart';
void main() {
final client = PubClient();
}Retrieves all available information about a specific package.
final package = await client.packageInfo('pkg_name');Package pubspec dependencies retain their typed source metadata. The public
library exports HostedDependency, GitDependency, PathDependency, and
SdkDependency so consumers can inspect constraints, URLs, refs, subpaths, and
SDK names without importing an implementation dependency separately.
Returns the following score information about a package.
- Pub Points (
grantedPoints/maxPoints) - Likes (
likeCount) - 30-day downloads (
downloadCount30Days) - Tags
final score = await client.packageScore('pkg_name');
popularityScoreis alwaysnull— pub.dev retired the popularity score. UsedownloadCount30Daysinstead.
The packageMetrics method returns a package score and scorecard.
final metrics = await client.packageMetrics('pkg_name');
final weekly = metrics?.scorecard.weeklyVersionDownloads;
if (weekly != null && weekly.totalWeeklyDownloads.isNotEmpty) {
print('Latest weekly downloads: ${weekly.totalWeeklyDownloads.last}');
}When supplied by the server, the scorecard includes total weekly downloads and major, minor, and patch version-range histories.
The packageVersions method returns only the published version strings.
final versions = await client.packageVersions('pkg_name');The packageVersionInfo method returns information about a specific package
version.
final version = await client.packageVersionInfo('pkg_name', 'version');The method packageVersionScore returns the score of a single version.
final score = await client.packageVersionScore('pkg_name', 'version');The method packageVersionOptions tells whether a specific version has been
retracted.
final options = await client.packageVersionOptions('pkg_name', 'version');
print(options.isRetracted);The packagePublisher method returns the publisher ID of a specific package.
final publisher = await client.packagePublisher('pkg_name');
print(publisher.publisherId);The method packageLikes returns the public like count of a package. Unlike
the like endpoints this does not require authentication.
final likes = await client.packageLikes('pkg_name');
print(likes.likes);The method packageOptions returns options of a package.
final options = await client.packageOptions('pkg_name');The documentation method returns each version and its documentation status.
final documentation = await client.documentation('pkg_name');The method packageAdvisories returns the security advisories affecting a
package, in OSV format. Returns null
when the server does not implement the endpoint.
final advisories = await client.packageAdvisories('pkg_name');
if (advisories != null && advisories.advisories.isNotEmpty) {
print(advisories.advisories.first.pubDisplayUrl);
}The method publisherInfo returns the public profile of a publisher.
final publisher = await client.publisherInfo('dart.dev');
print(publisher.description);The endpoints in this section inspect or change the authenticated user's like
state and require pub.dev authentication. The package-wide count returned by
packageLikes is public.
Returns the packages liked by the authenticated user.
final likes = await client.listPackageLikes();Returns like status of a package.
final like = await client.likePackageStatus('pkg_name');Likes a package and returns its authenticated like status.
final like = await client.likePackage('pkg_name');Unlikes a package.
await client.unlikePackage('pkg_name');Searches pub.dev for packages matching a query, with optional tag and topic filters.
final results = await client.search(
'query',
tags: [
PackageTag.publisher('publisher_id'),
PackageTag.dependency('dependency_name'),
'another:tag',
],
topics: ['topic_1', 'topic_2'],
);
// Returns the packages that match the query
print(results.packages);Search results support these orderings:
| Value | Orders by |
|---|---|
SearchOrder.top |
Weighted text, downloads, points, and likes |
SearchOrder.text |
Text-match similarity |
SearchOrder.created |
Package creation time |
SearchOrder.updated |
Last update time |
SearchOrder.downloads |
Download count |
SearchOrder.like |
Like count |
SearchOrder.points |
Pub points |
SearchOrder.trending |
Trend score |
final results = await client.search('query', sort: SearchOrder.updated);
print(results.packages);
SearchOrder.popularityis deprecated. pub.dev no longer accepts it and silently serves those requests asSearchOrder.top. UseSearchOrder.downloads.
Use the next URL to page through search results.
final results = await client.search('query');
final nextPage = results.next;
if (nextPage != null) {
final nextResults = await client.nextPage(nextPage);
print(nextResults.packages);
}To retrieve a specific result page, pass the page parameter directly.
final results = await client.search('query', page: 2);
print(results.packages);pub.dev stops returning a
nextlink after page 10, so paging through a search yields at most 100 packages.
packageNameCompletion returns the top package names on pub.dev, and
packageNames returns every package name in one gzip-compressed response.
final top = await client.packageNameCompletion();
final all = await client.packageNames();topicNameCompletion returns every topic mapped to the number of packages
using it.
final topics = await client.topicNameCompletion();
// {'flutter': 1234, 'http': 567, ...}Returns all Flutter favorites on pub.dev.
final results = await client.fetchFlutterFavorites();Returns official Google packages across the known Google publishers.
final results = await client.fetchGooglePackages();Returns all packages for a specific publisher.
final results = await client.fetchPublisherPackages('dart.dev');Returns all packages that match a given query.
final results = await client.fetchAllPackages(
'',
tags: [PackageTag.publisher('leoafarias.com')],
);pub.dev caps each search at 10 pages.
fetchAllPackages,fetchPublisherPackages, andfetchFlutterFavoritestherefore return at most 100 packages per query.fetchGooglePackagesapplies the same limit separately to each known publisher.
