# PyPI Package Stats & Metadata (`grit-77/pypi-packages`) Actor

PyPI package scraper for Python dependency research. Export versions, dependencies, release history and project links as JSON, with optional recent download counts.

- **URL**: https://apify.com/grit-77/pypi-packages.md
- **Developed by:** [Grit](https://apify.com/grit-77) (community)
- **Categories:** Developer tools, AI
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$0.40 / 1,000 packages

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## PyPI Package Stats & Metadata

PyPI packages scraper returns Python package metadata and optional recent download counts. PyPI API results include versions, dependencies, release history, project links, and timestamps for collected data.

### Input example

```json
{
  "packages": [
    "sampleproject"
  ],
  "maxItems": 1,
  "includeDownloads": false
}
```

The input keys and allowed values follow [input_schema.json](.actor/input_schema.json).

### Output fields

| Field | Type | Example or excerpt from sample |
|---|---|---|
| `input` | string | `"sampleproject"` |
| `package` | string | `"sampleproject"` |
| `status` | string | `"ok"` |
| `collected_at` | string | `"2026-10-05T12:07:09.388032Z"` |
| `downloads_status` | string | `"ok"` |
| `downloads_fetched_at` | string | `"2026-10-05T12:01:02.242673Z"` |
| `downloads_cached` | boolean | `true` |
| `downloads_last_day` | integer | `16511` |
| `downloads_last_week` | integer | `117011` |
| `downloads_last_month` | integer | `491628` |
| `errors` | array | `[]` |
| `warnings` | array | `[]` |
| `name` | string | `"sampleproject"` |
| `version` | string | `"4.0.0"` |
| `summary` | string | `"A sample Python project"` |
| `description` | string | `"# A sample Python project\n\n![Python Logo](https://www.python.org/static/community_…` |
| `description_content_type` | string | `"text/markdown"` |
| `license` | string | `"BSD-3-Clause"` |
| `license_expression` | string or null | `null` |
| `license_classifiers` | array | `["License :: OSI Approved :: MIT License"]` |
| `requires_python` | string | `">=3.9"` |
| `requires_dist` | array | `["peppercorn", "check-manifest; extra == \"dev\"", "coverage; extra == \"test\""]` |
| `provides_extra` | array | `["dev", "test"]` |
| `project_urls` | object | `{"Bug Reports": "https://github.com/pypa/sampleproject/issues", "Funding": "https://d…` |
| `home_page` | string or null | `null` |
| `keywords` | string or null | `"sample, setuptools, development"` |
| `classifiers` | array | `["Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OS…` |
| `yanked` | boolean | `false` |
| `yanked_reason` | string or null | `null` |
| `first_release_date` | string | `"2015-06-14T14:37:56.383366Z"` |
| `latest_release_date` | string | `"2024-11-06T22:37:09.220617Z"` |
| `release_count` | integer | `7` |
| `releases` | array | `[{"version": "4.0.0", "released_at": "2024-11-06T22:37:09.220617Z", "file_count": 2, …` |
| `pypi_url` | string | `"https://pypi.org/project/sampleproject/"` |
| `metadata_source_url` | string | `"https://pypi.org/pypi/sampleproject/json"` |
| `downloads_source_url` | string | `"https://pypistats.org/api/packages/sampleproject/recent"` |

### Output example

Trimmed from [sample_output.json](sample_output.json); omitted fields remain available in the dataset.

```json
{
  "input": "sampleproject",
  "package": "sampleproject",
  "status": "ok",
  "collected_at": "2026-10-05T12:07:09.388032Z",
  "downloads_status": "ok",
  "downloads_fetched_at": "2026-10-05T12:01:02.242673Z",
  "downloads_cached": true,
  "name": "sampleproject"
}
```

### Limits and source behavior

- `maxItems` defaults to 20 and accepts 1–500. It caps the entire dataset, including error rows.
- `concurrency` defaults to 3 and accepts 1–10. Downloads remain serialized with at least `downloadIntervalSecs` between network calls; that setting defaults to 2 and accepts 2–60 seconds.
- Successful recent-download responses are cached for the current UTC day in the named `pypi-package-stats-cache` key-value store. This allows runs using the same account/storage namespace to reuse counts. `downloads_fetched_at` preserves the original fetch time; it is not the source's last update time.
- PyPIStats [updates daily and applies IP-based limits](https://pypistats.org/api/). HTTP 429 pauses further stats calls for that run and persists a cooldown of at least 60 seconds or the supplied `Retry-After`, whichever is longer. Metadata remains available. Parallel runs sharing an IP can still be limited; the spacing control coordinates one run only.
- Transient network errors and selected server errors get at most three attempts with exponential backoff. PyPI retries respect `Retry-After`; waits longer than 120 seconds become an error row. A 404 is not retried.
- Name search downloads the full simple-index name list before selecting bounded matches. Use explicit names for routine monitoring; allow more memory for large-index searches.
- Release dates use the first surviving file's `upload_time_iso_8601`. Empty/deleted releases have a null date. The project's `releases` key is [deprecated by PyPI](https://docs.pypi.org/api/json/); if it disappears, history is empty and a warning is returned.
- Download counts describe downloads, not unique users. Publisher-supplied licenses and requirements are not independently audited. Null means unavailable, not zero.
- Spending limits stop further saving after the last affordable result. Already running metadata requests can finish before their results are discarded. The run summary includes exact charged USD and budget status.

### FAQ

**What are the output limits?** `maxItems` caps output, including errors. Package search matches names and loads the simple index; explicit names are preferable for routine monitoring.

**Do I need a proxy or login?** Public PyPI and PyPIStats endpoints need no login or proxy.

**How is this priced?** Proposed pay per event: $0.0004 for each saved `package` metadata row, including results with unavailable optional downloads. Input and metadata errors are uncharged. These are proposals in [PRICING.md](PRICING.md); the owner must configure Store billing.

**How are rate limits handled?** Download lookups are spaced by `downloadIntervalSecs`; HTTP 429 pauses PyPIStats calls for the run and records a cooldown.

**How fresh is the data?** PyPI metadata can change. `collected_at` marks collection, while `downloads_fetched_at` marks the optional PyPIStats lookup. Download counts are not unique users; publisher supplied metadata is not independently audited.

### Use with AI agents / MCP

After the actor is published, connect your agent to the [Apify MCP server](https://docs.apify.com/integrations/mcp) with an Apify API token. Use `call-actor` with the published actor identifier and the JSON input shown above. Read the returned dataset with `get-dataset-items`; the run response itself contains status and storage IDs, not the result rows. Alternatively, use the [Apify API](https://docs.apify.com/api/v2) to start a run and read its default dataset. Keep the actor input bounded with `maxItems`, and inspect source links and any error fields before using results in an answer.

# Actor input Schema

## `packages` (type: `array`):

PyPI distribution names, without version pins or URLs. Names are normalized and duplicates removed. Invalid names produce uncharged error rows. May be empty when search is supplied.

## `search` (type: `string`):

Optional case-insensitive literal name match over the official PyPI simple index. Matches package names, not descriptions. Punctuation variants of dots, underscores and hyphens are normalized.

## `searchMode` (type: `string`):

Contains matches anywhere in a name; prefix matches the start; exact matches a normalized distribution name. Results follow index order, without popularity ranking.

## `maxItems` (type: `integer`):

Total row cap including invalid and missing-package rows. Successful metadata rows are charged once each. Explicit names take priority.

## `concurrency` (type: `integer`):

Maximum packages processed concurrently. PyPIStats requests remain serialized regardless of this setting.

## `includeDownloads` (type: `boolean`):

Get last day/week/month downloads from pypistats.org. Reuse successful responses within a UTC day. If unavailable, metadata is still returned with an explicit error.

## `downloadIntervalSecs` (type: `integer`):

Minimum spacing between uncached PyPIStats calls, including retries. HTTP 429 pauses further download calls for the run and saves a Retry-After cooldown. Shared-IP or parallel-run limits may still apply.

## Actor input object example

```json
{
  "packages": [
    "requests",
    "sampleproject",
    "httpx"
  ],
  "search": "",
  "searchMode": "contains",
  "maxItems": 20,
  "concurrency": 3,
  "includeDownloads": true,
  "downloadIntervalSecs": 2
}
```

# Actor output Schema

## `dataset` (type: `string`):

Dataset items containing package metadata, download statistics and error rows.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "packages": [
        "requests",
        "sampleproject",
        "httpx"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("grit-77/pypi-packages").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "packages": [
        "requests",
        "sampleproject",
        "httpx",
    ] }

# Run the Actor and wait for it to finish
run = client.actor("grit-77/pypi-packages").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "packages": [
    "requests",
    "sampleproject",
    "httpx"
  ]
}' |
apify call grit-77/pypi-packages --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,grit-77/pypi-packages"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/YaElq5LqC2KZVW7AG/builds/TBXuUMJqFmu1JEzjb/openapi.json
