Skip to content

Commit

Permalink
docs: move stats API to user docs (#17161)
Browse files Browse the repository at this point in the history
Signed-off-by: William Woodruff <william@trailofbits.com>
Co-authored-by: Dustin Ingram <di@users.noreply.github.com>
  • Loading branch information
woodruffw and di authored Nov 25, 2024
1 parent e52734d commit c863541
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 43 deletions.
47 changes: 4 additions & 43 deletions docs/dev/api-reference/stats.rst
Original file line number Diff line number Diff line change
@@ -1,48 +1,9 @@
Stats API
=========

PyPI offers a JSON stats endpoint via a ``Accept: application/json`` GET
request. Without the ``Accept`` header set, you will be returned a HTML page.
.. important::

**Example Client**: https://github.com/cooperlees/pypistats
This API documentation has been migrated to a new page in
the `user documentation <https://docs.pypi.org/>`_:

Project
-------

.. http:get:: /stats/
Returns statistics in JSON format. This includes:
- Total size of PyPI packages in bytes
- Top 100 packages + their size in bytes

**Example Request**:

- `curl -H "Accept: application/json" https://pypi.org/stats/`

.. code:: http
GET /stats HTTP/1.1
Host: pypi.org
Accept: application/json
**Example response**:

.. code:: json
{
"top_packages": {
"CodeIntel": {
"size": 23767329521
},
"Fiona": {
"size": 6209535709
},
"FlexGet": {
"size": 4387002448
},
"...": "..."
},
"total_packages_size": 23965450269
}
:statuscode 200: no error
* `Stats API <https://docs.pypi.org/api/stats/>`_
7 changes: 7 additions & 0 deletions docs/mkdocs-user-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ markdown_extensions:
- pymdownx.emoji:
emoji_index: !!python/name:material.extensions.emoji.twemoji
emoji_generator: !!python/name:material.extensions.emoji.to_svg
- pymdownx.magiclink:
repo_url_shorthand: true
normalize_issue_symbols: true
provider: github
user: pypi
repo: warehouse
theme:
name: material
logo: assets/logo.png
Expand Down Expand Up @@ -84,3 +90,4 @@ nav:
- "api/index-api.md"
- "api/upload.md"
- "api/integrity.md"
- "api/stats.md"
53 changes: 53 additions & 0 deletions docs/user/api/stats.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Stats API

!!! important

You **must** set `Accept: application/json` in your requests to this API.
Without the `Accept` header, you will be returned an HTML page.

!!! tip

An example stats API client can be found at @coopherlees/pypistats.

## Routes

### Project stats

Route: `GET /stats/`

Returns statistics in JSON format. This includes:

- Total size of PyPI packages in bytes
- Top 100 packages + their size in bytes

Status codes:

* `200 OK` - no error

Example request:

```http
GET /stats HTTP/1.1
Host: pypi.org
Accept: application/json
```

??? note "Example JSON response"

```json
{
"top_packages": {
"CodeIntel": {
"size": 23767329521
},
"Fiona": {
"size": 6209535709
},
"FlexGet": {
"size": 4387002448
},
"...": "..."
},
"total_packages_size": 23965450269
}
```

0 comments on commit c863541

Please sign in to comment.