搜尋套件、儲存庫與 APP 分類

套件詳情v4.0.0

pub_api_client

一個用於 Pub 的 API 客戶端,用於與公開套件資訊進行互動。

AndroidiOSmacOSWindowsLinux
近 30 天下載
18.6萬
喜歡數
70
Pub 分數
160

安裝套件

flutter pub add pub_api_client

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個 Flutter/Dart 套件,提供與 Pub 套件儲存庫互動的客戶端,讓開發者能夠取得公開套件資訊,例如元資料、版本和相依性。設計簡單且可靠,可無縫整合至需要即時存取 Dart 套件資料的應用程式中。該客戶端支援所有主要平台,包含行動裝置、桌面與網頁,非常適合用於分析或顯示套件詳細資訊的工具。由 leoafarias.com 維護,並託管於 GitHub,以確保透明度與社群貢獻。

適用情境

  • 正在獲取軟體包元數據
  • 顯示軟體包版本
  • 分析軟體包依賴關係
  • 建構套件搜尋工具
  • 與開發工具整合

主要特色

  • 簡單 API 接口
  • 跨平台支援
  • 即時套件資料
  • GitHub託管的原始碼
  • 官方發布庫倉儲整合

適合對象

  • Dart 包瀏覽器
  • 開發者工具應用
  • 依賴分析工具
  • 關於 Dart 套件的教育類應用程式
  • CI/CD 流水線整合

使用建議

  • 需要互聯網連接
  • 可能會應用速率限制
  • 僅限公開套件資料
  • 不適用於私人套件管理
  • 依賴外部Pub服務的穩定性

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

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.

所屬分類

依賴

依賴清單 5 項

原始碼儲存庫

使用此套件的專案