Skip to content

PyPI downloads example: total chart, direct line, in-memory cache#203

Merged
jlowin merged 1 commit intomainfrom
pypi-downloads-enhancements
Feb 27, 2026
Merged

PyPI downloads example: total chart, direct line, in-memory cache#203
jlowin merged 1 commit intomainfrom
pypi-downloads-enhancements

Conversation

@jlowin
Copy link
Member

@jlowin jlowin commented Feb 27, 2026

The PyPI downloads example previously required pre-fetching data to CSV before the server could start, and only showed dependent package downloads. This rework makes the example self-contained and more informative.

The dashboard now shows the package's own total weekly downloads in a chart above the dependents chart. A "direct" line in the dependents chart estimates downloads not attributable to any tracked dependent (total minus sum of top-20 dependents). A checkbox toggles the direct line instantly via a lightweight /api/render endpoint that re-renders from an in-memory cache without re-querying ClickHouse.

The page header is reactive — it updates as you type in the package name field, using the defer/insert pattern:

pkg_input = Input(name="package_name", value="fastmcp", defer=True)

with Column():
    Text(f"PyPI Downloads: {pkg_input.rx}")  # reactive header
    with Form(...):
        insert(pkg_input)  # render the input here

All file-based caching (CSV, meta JSON) is replaced with a simple in-memory dict, so the server starts clean and fetches data on demand.

… example

- Add query_total.sql for the package's own weekly downloads
- Replace CSV/file caching with in-memory cache
- Add total downloads chart above dependents chart
- Compute "direct" line (total - sum of dependents) in dependents chart
- Add checkbox to toggle direct downloads visibility
- Add reactive page header using defer/insert pattern
- Simplify query.py (remove CLI entry point and file I/O)
- Default date range to 6 months
@marvin-context-protocol marvin-context-protocol bot added enhancement Improvement to existing functionality or new capabilities. python Related to the Python SDK: components, actions, serialization. labels Feb 27, 2026
@jlowin jlowin merged commit f27a38d into main Feb 27, 2026
7 checks passed
@jlowin jlowin deleted the pypi-downloads-enhancements branch February 27, 2026 02:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Improvement to existing functionality or new capabilities. python Related to the Python SDK: components, actions, serialization.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant