Skip to content

Repository files navigation

drawing

Pub Version Pub Likes Pub Points Coverage Status MIT Licence

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.

Table of contents

Usage

A simple usage example:

import 'package:pub_api_client/pub_api_client.dart';

void main() {
  final client = PubClient();
}

API

Packages

Get Package Info

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.

Get Package Score

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');

popularityScore is always null — pub.dev retired the popularity score. Use downloadCount30Days instead.

Get Package Metrics

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.

Get Package Versions

The packageVersions method returns only the published version strings.

final versions = await client.packageVersions('pkg_name');

Get Package Version Info

The packageVersionInfo method returns information about a specific package version.

final version = await client.packageVersionInfo('pkg_name', 'version');

Get Package Version Score

The method packageVersionScore returns the score of a single version.

final score = await client.packageVersionScore('pkg_name', 'version');

Get Package Version Options

The method packageVersionOptions tells whether a specific version has been retracted.

final options = await client.packageVersionOptions('pkg_name', 'version');
print(options.isRetracted);

Get Package Publisher

The packagePublisher method returns the publisher ID of a specific package.

final publisher = await client.packagePublisher('pkg_name');
print(publisher.publisherId);

Get Package Likes

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);

Get Package Options

The method packageOptions returns options of a package.

final options = await client.packageOptions('pkg_name');

Get Documentation

The documentation method returns each version and its documentation status.

final documentation = await client.documentation('pkg_name');

Get Security Advisories

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);
}

Publishers

Get Publisher Info

The method publisherInfo returns the public profile of a publisher.

final publisher = await client.publisherInfo('dart.dev');
print(publisher.description);

Like Packages

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.

List liked packages

Returns the packages liked by the authenticated user.

final likes = await client.listPackageLikes();

Package Like Status

Returns like status of a package.

final like = await client.likePackageStatus('pkg_name');

Like a Package

Likes a package and returns its authenticated like status.

final like = await client.likePackage('pkg_name');

Unlike a Package

Unlikes a package.

await client.unlikePackage('pkg_name');

Search Packages

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);

Sorting search results

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.popularity is deprecated. pub.dev no longer accepts it and silently serves those requests as SearchOrder.top. Use SearchOrder.downloads.

Paging Search Results

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 next link after page 10, so paging through a search yields at most 100 packages.

Completion Data

Package Names

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();

Topics

topicNameCompletion returns every topic mapped to the number of packages using it.

final topics = await client.topicNameCompletion();
// {'flutter': 1234, 'http': 567, ...}

Utilities

Flutter Favorites

Returns all Flutter favorites on pub.dev.

final results = await client.fetchFlutterFavorites();

Google Packages

Returns official Google packages across the known Google publishers.

final results = await client.fetchGooglePackages();

Publisher Packages

Returns all packages for a specific publisher.

final results = await client.fetchPublisherPackages('dart.dev');

All Packages

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, and fetchFlutterFavorites therefore return at most 100 packages per query. fetchGooglePackages applies the same limit separately to each known publisher.

About

The most complete & unofficial API Client for Dart Pub.dev

Topics

Resources

Stars

92 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages