forked from elastic/supply-chain-monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtop_pypi_packages.py
More file actions
29 lines (20 loc) · 881 Bytes
/
top_pypi_packages.py
File metadata and controls
29 lines (20 loc) · 881 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Copyright 2026 Elastic N.V.
# Licensed under the MIT License. See LICENSE file in the project root for details.
import json
import urllib.request
URL = "https://hugovk.github.io/top-pypi-packages/top-pypi-packages-30-days.min.json"
TOP_N = 1000
def fetch_top_packages(url: str = URL, top_n: int = TOP_N) -> list[dict]:
with urllib.request.urlopen(url) as resp:
data = json.loads(resp.read())
print(f"Last updated: {data['last_update']}")
print(f"Total packages in dataset: {len(data['rows']):,}")
rows = data["rows"][:top_n]
print(f"\nTop {top_n} packages by 30-day downloads:\n")
print(f"{'Rank':<6} {'Package':<40} {'Downloads':>15}")
print("-" * 63)
for i, row in enumerate(rows, 1):
print(f"{i:<6} {row['project']:<40} {row['download_count']:>15,}")
return rows
if __name__ == "__main__":
fetch_top_packages()