diff --git a/docs/_freeze/posts/better-pypi-stats/index/execute-results/html.json b/docs/_freeze/posts/better-pypi-stats/index/execute-results/html.json new file mode 100644 index 000000000000..12971c36e457 --- /dev/null +++ b/docs/_freeze/posts/better-pypi-stats/index/execute-results/html.json @@ -0,0 +1,16 @@ +{ + "hash": "5e6abf57172aae80eb02eb0f3e381ff5", + "result": { + "engine": "jupyter", + "markdown": "---\ntitle: \"Better PyPI stats with Python\"\nauthor: \"Cody Peterson\"\ndate: \"2024-09-03\"\nimage: thumbnail.png\ncategories:\n - clickhouse\n - shiny\n---\n\n\n\n\n***Ibis + ClickHouse + Shiny for Python = better PyPI stats.***\n\n## Overview\n\n[PyPI Stats](https://pypistats.org/about) is a great resource for Python package\ndownload statistics from PyPI. However, it only contains 180 days of data and\nlacks more detailed analysis we might be interested in. In this post, we'll\nbuild a dynamic Python application for better PyPI stats using\n[ClickHouse](https://github.com/clickhouse/clickhouse) as our data platform,\n[Ibis](https://github.com/ibis-project/ibis) as our Python data interface, and\n[Shiny for Python](https://github.com/posit-dev/py-shiny) as our dashboarding\ntool.\n\n::: {.callout-note title=\"What about ClickPy?\"}\n[ClickPy](https://github.com/ClickHouse/clickpy) is an existing open source and\nreproducible project built on the same data with ClickHouse. The primary\ndifference is that ClickPy uses SQL and JavaScript whereas this project is in\nPython. We also focus on different visualizations and metrics.\n:::\n\n## Prerequisites\n\nInstall the required dependencies:\n\n```bash\npip install 'ibis-framework[clickhouse]' plotly\n```\n\nThen run imports and setup:\n\n::: {#35a43503 .cell execution_count=2}\n``` {.python .cell-code}\nimport ibis\nimport plotly.express as px\nimport clickhouse_connect\n\npx.defaults.template = \"plotly_dark\"\nibis.options.interactive = True\n```\n:::\n\n\n## Connecting to ClickHouse\n\nYou can connect to the public ClickHouse playground's PyPI database:\n\n::: {#5c8d30ee .cell execution_count=3}\n``` {.python .cell-code}\nhost = \"clickpy-clickhouse.clickhouse.com\"\nport = 443\nuser = \"play\"\ndatabase = \"pypi\"\n\ncon = ibis.clickhouse.connect(\n host=host,\n port=port,\n user=user,\n database=database,\n)\ncon.list_tables()\n```\n\n::: {.cell-output .cell-output-display execution_count=122}\n```\n['countries',\n 'countries_dict',\n 'last_updated_dict',\n 'projects',\n 'pypi',\n 'pypi_downloads',\n 'pypi_downloads_by_version',\n 'pypi_downloads_by_version_mv',\n 'pypi_downloads_max_min',\n 'pypi_downloads_max_min_mv',\n 'pypi_downloads_mv',\n 'pypi_downloads_per_day',\n 'pypi_downloads_per_day_by_version',\n 'pypi_downloads_per_day_by_version_by_country',\n 'pypi_downloads_per_day_by_version_by_country_mv',\n 'pypi_downloads_per_day_by_version_by_file_type',\n 'pypi_downloads_per_day_by_version_by_file_type_mv',\n 'pypi_downloads_per_day_by_version_by_installer_by_type',\n 'pypi_downloads_per_day_by_version_by_installer_by_type_by_country',\n 'pypi_downloads_per_day_by_version_by_installer_by_type_by_country_mv',\n 'pypi_downloads_per_day_by_version_by_installer_by_type_mv',\n 'pypi_downloads_per_day_by_version_by_python',\n 'pypi_downloads_per_day_by_version_by_python_by_country',\n 'pypi_downloads_per_day_by_version_by_python_by_country_mv',\n 'pypi_downloads_per_day_by_version_by_python_mv',\n 'pypi_downloads_per_day_by_version_by_system',\n 'pypi_downloads_per_day_by_version_by_system_by_country',\n 'pypi_downloads_per_day_by_version_by_system_by_country_mv',\n 'pypi_downloads_per_day_by_version_by_system_mv',\n 'pypi_downloads_per_day_by_version_mv',\n 'pypi_downloads_per_day_mv',\n 'pypi_downloads_per_month',\n 'pypi_downloads_per_month_mv']\n```\n:::\n:::\n\n\n## Top packages by downloads\n\nLet's start by looking at the most downloaded packages:\n\n::: {#4f28fe0b .cell execution_count=4}\n``` {.python .cell-code}\noverall_t = con.table(\"pypi_downloads\")\n\ntop_k = 10_000\noverall_t = (\n overall_t.order_by(ibis.desc(\"count\"))\n .limit(top_k)\n .mutate(rank=1 + ibis.row_number().over(order_by=ibis.desc(\"count\")))\n .rename({\"downloads\": \"count\"})\n .relocate(\"rank\")\n .order_by(\"rank\")\n)\noverall_t\n```\n\n::: {.cell-output .cell-output-display execution_count=123}\n```{=html}\n
┏━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┓\n┃ rank   project          downloads   ┃\n┡━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━┩\n│ int64!string!int64      │\n├───────┼─────────────────┼─────────────┤\n│     1boto3          25779423674 │\n│     2urllib3        16339094961 │\n│     3botocore       15210036424 │\n│     4requests       13514466781 │\n│     5setuptools     12656259406 │\n│     6idna           11843633399 │\n│     7certifi        11823436764 │\n│     8s3transfer     11059293057 │\n│     9six            10982223268 │\n│    10python-dateutil10756832919 │\n│      │\n└───────┴─────────────────┴─────────────┘\n
\n```\n:::\n:::\n\n\n## Analyzing downloads for a package\n\nLet's choose a package to analyze:\n\n::: {#25d25e25 .cell execution_count=5}\n``` {.python .cell-code}\nproject = \"clickhouse-connect\"\n```\n:::\n\n\nAnd see where it ranks in the top downloads:\n\n::: {#d78f47dc .cell execution_count=6}\n``` {.python .cell-code}\noverall_t.filter(overall_t[\"project\"] == project)\n```\n\n::: {.cell-output .cell-output-display execution_count=125}\n```{=html}\n
┏━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┓\n┃ rank   project             downloads ┃\n┡━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━┩\n│ int64!string!int64    │\n├───────┼────────────────────┼───────────┤\n│  2303clickhouse-connect23148161 │\n└───────┴────────────────────┴───────────┘\n
\n```\n:::\n:::\n\n\nLet's look at downloads per day by various categories for this package:\n\n::: {#08381aa9 .cell execution_count=7}\n``` {.python .cell-code}\ndownloads_t = con.table(\n \"pypi_downloads_per_day_by_version_by_installer_by_type_by_country\"\n).filter(ibis._[\"project\"] == project)\ndownloads_t\n```\n\n::: {.cell-output .cell-output-display execution_count=126}\n```{=html}\n
┏━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━┓\n┃ project             version  date        installer     type         country_code  count  ┃\n┡━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━┩\n│ !string!string!date!string!string!string!int64 │\n├────────────────────┼─────────┼────────────┼──────────────┼─────────────┼──────────────┼────────┤\n│ clickhouse-connect0.2.10 2024-08-29bandersnatchbdist_wheelUS          18 │\n│ clickhouse-connect0.2.10 2024-08-29bandersnatchsdist      US          1 │\n│ clickhouse-connect0.2.8  2024-08-29bandersnatchbdist_wheelUS          9 │\n│ clickhouse-connect0.2.9  2024-08-29bandersnatchbdist_wheelUS          16 │\n│ clickhouse-connect0.2.9  2024-08-29bandersnatchsdist      US          1 │\n│ clickhouse-connect0.3.0  2024-08-29bandersnatchbdist_wheelUS          19 │\n│ clickhouse-connect0.3.0  2024-08-29bandersnatchsdist      US          1 │\n│ clickhouse-connect0.3.1  2024-08-29~bdist_wheelUS          26 │\n│ clickhouse-connect0.3.1  2024-08-29~sdist      US          1 │\n│ clickhouse-connect0.3.1  2024-08-29Browser     bdist_wheelUS          1 │\n│  │\n└────────────────────┴─────────┴────────────┴──────────────┴─────────────┴──────────────┴────────┘\n
\n```\n:::\n:::\n\n\nWe might be interested in the day-of-week seasonality of downloads:\n\n::: {#c6a458a0 .cell execution_count=8}\n``` {.python .cell-code}\ndef day_of_week_bar(t):\n t = t.mutate(day_of_week=t[\"date\"].day_of_week.full_name())\n t = t.group_by(\"day_of_week\").agg(downloads=ibis._[\"count\"].sum())\n c = px.bar(\n t,\n x=\"day_of_week\",\n y=\"downloads\",\n category_orders={\n \"day_of_week\": [\n \"Sunday\",\n \"Monday\",\n \"Tuesday\",\n \"Wednesday\",\n \"Thursday\",\n \"Friday\",\n \"Saturday\",\n ]\n },\n )\n return c\n\n\nday_of_week_bar(downloads_t)\n```\n\n::: {.cell-output .cell-output-display}\n```{=html}\n
\n```\n:::\n:::\n\n\nOr the rolling 28-day downloads metric:\n\n::: {#dc30bbc1 .cell execution_count=9}\n``` {.python .cell-code}\ndef rolling_downloads(t, days=28):\n t = t.mutate(\n timestamp=t[\"date\"].cast(\"timestamp\"),\n )\n t = t.group_by(\"timestamp\").agg(downloads=ibis._[\"count\"].sum())\n t = t.select(\n \"timestamp\",\n rolling_downloads=ibis._[\"downloads\"]\n .sum()\n .over(\n ibis.window(\n order_by=\"timestamp\",\n preceding=days,\n following=0,\n )\n ),\n ).order_by(\"timestamp\")\n\n c = px.line(\n t,\n x=\"timestamp\",\n y=\"rolling_downloads\",\n )\n\n return c\n\n\nrolling_downloads(downloads_t)\n```\n\n::: {.cell-output .cell-output-display}\n```{=html}\n
\n```\n:::\n:::\n\n\nOr rolling 28-days downloads by version with a few options for how to group\nversions:\n\n::: {#f0db4a6b .cell execution_count=10}\n``` {.python .cell-code}\ndef rolling_downloads_by_version(t, days=28, version_style=\"major.minor\"):\n t = t.mutate(\n timestamp=t[\"date\"].cast(\"timestamp\"),\n )\n\n match version_style:\n case \"major\":\n t = t.mutate(version=t[\"version\"].split(\".\")[0])\n case \"major.minor\":\n t = t.mutate(\n version=t[\"version\"].split(\".\")[0] + \".\" + t[\"version\"].split(\".\")[1]\n )\n case _:\n pass\n\n t = t.group_by(\"timestamp\", \"version\").agg(downloads=ibis._[\"count\"].sum())\n\n t = t.select(\n \"timestamp\",\n \"version\",\n rolling_downloads=ibis._[\"downloads\"]\n .sum()\n .over(\n ibis.window(\n order_by=\"timestamp\",\n group_by=\"version\",\n preceding=28,\n following=0,\n )\n ),\n ).order_by(\"timestamp\")\n\n c = px.line(\n t,\n x=\"timestamp\",\n y=\"rolling_downloads\",\n color=\"version\",\n category_orders={\n \"version\": reversed(\n sorted(\n t.distinct(on=\"version\")[\"version\"].to_pyarrow().to_pylist(),\n key=lambda x: tuple(int(y) for y in x.split(\".\") if y.isdigit()),\n )\n )\n },\n )\n return c\n\n\nrolling_downloads_by_version(downloads_t)\n```\n\n::: {.cell-output .cell-output-display}\n```{=html}\n
\n```\n:::\n:::\n\n\nOr a bar chart of downloads grouped by a category:\n\n::: {#17fed57f .cell execution_count=11}\n``` {.python .cell-code}\ndef group_bar(t, group_by=\"installer\", log_y=True):\n t = t.mutate(timestamp=t[\"date\"].cast(\"timestamp\"))\n t = t.group_by(group_by).agg(downloads=ibis._[\"count\"].sum())\n t = t.order_by(ibis.desc(\"downloads\"))\n\n c = px.bar(\n t,\n x=group_by,\n y=\"downloads\",\n log_y=log_y,\n )\n return c\n\n\ngroup_bar(downloads_t)\n```\n\n::: {.cell-output .cell-output-display}\n```{=html}\n
\n```\n:::\n:::\n\n\n::: {.callout-tip title=\"More examples\" collapse=\"true\"}\n\nSince we're just writing Python, we've already organized code into functions for\nreuse. We can rerun our above analytics on a different package by changing the\n`project` variable and adjusting our table accordingly. We'll demonstrate this\nwith a few more packages below.\n\nNotice you could also pass in Ibis tables from different backends, not just\nClickHouse, to these functions!\n\n::: {.panel-tabset}\n\n## PyArrow\n\n::: {#3229d5fe .cell execution_count=12}\n``` {.python .cell-code}\npackage = \"pyarrow\"\n\nt = con.table(\n \"pypi_downloads_per_day_by_version_by_installer_by_type_by_country\"\n).filter(ibis._[\"project\"] == package)\n```\n:::\n\n\n::: {#881a1ed1 .cell execution_count=13}\n``` {.python .cell-code}\nday_of_week_bar(t)\n```\n\n::: {.cell-output .cell-output-display}\n```{=html}\n
\n```\n:::\n:::\n\n\n::: {#8ebc02fd .cell execution_count=14}\n``` {.python .cell-code}\nrolling_downloads(t)\n```\n\n::: {.cell-output .cell-output-display}\n```{=html}\n
\n```\n:::\n:::\n\n\n::: {#d6ecba65 .cell execution_count=15}\n``` {.python .cell-code}\nrolling_downloads_by_version(t, version_style=\"major\")\n```\n\n::: {.cell-output .cell-output-display}\n```{=html}\n
\n```\n:::\n:::\n\n\n::: {#501d8216 .cell execution_count=16}\n``` {.python .cell-code}\ngroup_bar(t, group_by=\"installer\")\n```\n\n::: {.cell-output .cell-output-display}\n```{=html}\n
\n```\n:::\n:::\n\n\n## chDB\n\n::: {#f884b7f3 .cell execution_count=17}\n``` {.python .cell-code}\npackage = \"chdb\"\n\nt = con.table(\n \"pypi_downloads_per_day_by_version_by_installer_by_type_by_country\"\n).filter(ibis._[\"project\"] == package)\n```\n:::\n\n\n::: {#89831471 .cell execution_count=18}\n``` {.python .cell-code}\nday_of_week_bar(t)\n```\n\n::: {.cell-output .cell-output-display}\n```{=html}\n
\n```\n:::\n:::\n\n\n::: {#ac857a76 .cell execution_count=19}\n``` {.python .cell-code}\nrolling_downloads(t)\n```\n\n::: {.cell-output .cell-output-display}\n```{=html}\n
\n```\n:::\n:::\n\n\n::: {#435b1425 .cell execution_count=20}\n``` {.python .cell-code}\nrolling_downloads_by_version(t, version_style=\"major.minor\")\n```\n\n::: {.cell-output .cell-output-display}\n```{=html}\n
\n```\n:::\n:::\n\n\n::: {#20612d3e .cell execution_count=21}\n``` {.python .cell-code}\ngroup_bar(t, group_by=\"installer\")\n```\n\n::: {.cell-output .cell-output-display}\n```{=html}\n
\n```\n:::\n:::\n\n\n## Ibis\n\n::: {#f761c3eb .cell execution_count=22}\n``` {.python .cell-code}\npackage = \"ibis-framework\"\n\nt = con.table(\n \"pypi_downloads_per_day_by_version_by_installer_by_type_by_country\"\n).filter(ibis._[\"project\"] == package)\n```\n:::\n\n\n::: {#e562b720 .cell execution_count=23}\n``` {.python .cell-code}\nday_of_week_bar(t)\n```\n\n::: {.cell-output .cell-output-display}\n```{=html}\n
\n```\n:::\n:::\n\n\n::: {#80af6f19 .cell execution_count=24}\n``` {.python .cell-code}\nrolling_downloads(t)\n```\n\n::: {.cell-output .cell-output-display}\n```{=html}\n
\n```\n:::\n:::\n\n\n::: {#92a68ee6 .cell execution_count=25}\n``` {.python .cell-code}\nrolling_downloads_by_version(t, version_style=\"major\")\n```\n\n::: {.cell-output .cell-output-display}\n```{=html}\n
\n```\n:::\n:::\n\n\n::: {#50d9fbd2 .cell execution_count=26}\n``` {.python .cell-code}\ngroup_bar(t, group_by=\"installer\")\n```\n\n::: {.cell-output .cell-output-display}\n```{=html}\n
\n```\n:::\n:::\n\n\n:::\n\n:::\n\n## Shiny for Python application\n\nWe can create an interactive Shiny with Python application using the code above\nto serve as a dashboard for better PyPI stats:\n\n::: {.callout-tip}\nSee [the GitHub repository](https://github.com/ibis-project/better-pypi-stats)\nfor the most up-to-date code.\n:::\n\n\n\n\n{{< video https://youtu.be/jkdWaL8CbK4 >}}\n\n\n\n\n\n\n## Reproducing and contributing\n\nThe code is [available on\nGitHub](https://github.com/ibis-project/better-pypi-stats). Feel free to open an\nissue or pull request if you have any suggested improvements.\n\n", + "supporting": [ + "index_files/figure-html" + ], + "filters": [], + "includes": { + "include-in-header": [ + "\n\n\n\n\n" + ] + } + } +} \ No newline at end of file diff --git a/docs/posts/better-pypi-stats/index.qmd b/docs/posts/better-pypi-stats/index.qmd new file mode 100644 index 000000000000..44d01dd44a17 --- /dev/null +++ b/docs/posts/better-pypi-stats/index.qmd @@ -0,0 +1,358 @@ +--- +title: "Better PyPI stats with Python" +author: "Cody Peterson" +date: "2024-09-03" +image: thumbnail.png +categories: + - clickhouse + - shiny +--- + +***Ibis + ClickHouse + Shiny for Python = better PyPI stats.*** + +## Overview + +[PyPI Stats](https://pypistats.org/about) is a great resource for Python package +download statistics from PyPI. However, it only contains 180 days of data and +lacks more detailed analysis we might be interested in. In this post, we'll +build a dynamic Python application for better PyPI stats using +[ClickHouse](https://github.com/clickhouse/clickhouse) as our data platform, +[Ibis](https://github.com/ibis-project/ibis) as our Python data interface, and +[Shiny for Python](https://github.com/posit-dev/py-shiny) as our dashboarding +tool. + +::: {.callout-note title="What about ClickPy?"} +[ClickPy](https://github.com/ClickHouse/clickpy) is an existing open source and +reproducible project built on the same data with ClickHouse. The primary +difference is that ClickPy uses SQL and JavaScript whereas this project is in +Python. We also focus on different visualizations and metrics. +::: + +## Prerequisites + +Install the required dependencies: + +```bash +pip install 'ibis-framework[clickhouse]' plotly +``` + +Then run imports and setup: + +```{python} +import ibis +import plotly.express as px +import clickhouse_connect + +px.defaults.template = "plotly_dark" +ibis.options.interactive = True +``` + +## Connecting to ClickHouse + +You can connect to the public ClickHouse playground's PyPI database: + +```{python} +host = "clickpy-clickhouse.clickhouse.com" +port = 443 +user = "play" +database = "pypi" + +con = ibis.clickhouse.connect( + host=host, + port=port, + user=user, + database=database, +) +con.list_tables() +``` + +## Top packages by downloads + +Let's start by looking at the most downloaded packages: + +```{python} +overall_t = con.table("pypi_downloads") + +top_k = 10_000 +overall_t = ( + overall_t.order_by(ibis.desc("count")) + .limit(top_k) + .mutate(rank=1 + ibis.row_number().over(order_by=ibis.desc("count"))) + .rename({"downloads": "count"}) + .relocate("rank") + .order_by("rank") +) +overall_t +``` + +## Analyzing downloads for a package + +Let's choose a package to analyze: + +```{python} +project = "clickhouse-connect" +``` + +And see where it ranks in the top downloads: + +```{python} +overall_t.filter(overall_t["project"] == project) +``` + +Let's look at downloads per day by various categories for this package: + +```{python} +downloads_t = con.table( + "pypi_downloads_per_day_by_version_by_installer_by_type_by_country" +).filter(ibis._["project"] == project) +downloads_t +``` + +We might be interested in the day-of-week seasonality of downloads: + +```{python} +def day_of_week_bar(t): + t = t.mutate(day_of_week=t["date"].day_of_week.full_name()) + t = t.group_by("day_of_week").agg(downloads=ibis._["count"].sum()) + c = px.bar( + t, + x="day_of_week", + y="downloads", + category_orders={ + "day_of_week": [ + "Sunday", + "Monday", + "Tuesday", + "Wednesday", + "Thursday", + "Friday", + "Saturday", + ] + }, + ) + return c + + +day_of_week_bar(downloads_t) +``` + +Or the rolling 28-day downloads metric: + +```{python} +def rolling_downloads(t, days=28): + t = t.mutate( + timestamp=t["date"].cast("timestamp"), + ) + t = t.group_by("timestamp").agg(downloads=ibis._["count"].sum()) + t = t.select( + "timestamp", + rolling_downloads=ibis._["downloads"] + .sum() + .over( + ibis.window( + order_by="timestamp", + preceding=days, + following=0, + ) + ), + ).order_by("timestamp") + + c = px.line( + t, + x="timestamp", + y="rolling_downloads", + ) + + return c + + +rolling_downloads(downloads_t) +``` + +Or rolling 28-days downloads by version with a few options for how to group +versions: + +```{python} +def rolling_downloads_by_version(t, days=28, version_style="major.minor"): + t = t.mutate( + timestamp=t["date"].cast("timestamp"), + ) + + match version_style: + case "major": + t = t.mutate(version=t["version"].split(".")[0]) + case "major.minor": + t = t.mutate( + version=t["version"].split(".")[0] + "." + t["version"].split(".")[1] + ) + case _: + pass + + t = t.group_by("timestamp", "version").agg(downloads=ibis._["count"].sum()) + + t = t.select( + "timestamp", + "version", + rolling_downloads=ibis._["downloads"] + .sum() + .over( + ibis.window( + order_by="timestamp", + group_by="version", + preceding=28, + following=0, + ) + ), + ).order_by("timestamp") + + c = px.line( + t, + x="timestamp", + y="rolling_downloads", + color="version", + category_orders={ + "version": reversed( + sorted( + t.distinct(on="version")["version"].to_pyarrow().to_pylist(), + key=lambda x: tuple(int(y) for y in x.split(".") if y.isdigit()), + ) + ) + }, + ) + return c + + +rolling_downloads_by_version(downloads_t) +``` + +Or a bar chart of downloads grouped by a category: + +```{python} +def group_bar(t, group_by="installer", log_y=True): + t = t.mutate(timestamp=t["date"].cast("timestamp")) + t = t.group_by(group_by).agg(downloads=ibis._["count"].sum()) + t = t.order_by(ibis.desc("downloads")) + + c = px.bar( + t, + x=group_by, + y="downloads", + log_y=log_y, + ) + return c + + +group_bar(downloads_t) +``` + +::: {.callout-tip title="More examples" collapse="true"} + +Since we're just writing Python, we've already organized code into functions for +reuse. We can rerun our above analytics on a different package by changing the +`project` variable and adjusting our table accordingly. We'll demonstrate this +with a few more packages below. + +Notice you could also pass in Ibis tables from different backends, not just +ClickHouse, to these functions! + +::: {.panel-tabset} + +## PyArrow + +```{python} +package = "pyarrow" + +t = con.table( + "pypi_downloads_per_day_by_version_by_installer_by_type_by_country" +).filter(ibis._["project"] == package) +``` + +```{python} +day_of_week_bar(t) +``` + +```{python} +rolling_downloads(t) +``` + +```{python} +rolling_downloads_by_version(t, version_style="major") +``` + +```{python} +group_bar(t, group_by="installer") +``` + +## chDB + +```{python} +package = "chdb" + +t = con.table( + "pypi_downloads_per_day_by_version_by_installer_by_type_by_country" +).filter(ibis._["project"] == package) +``` + +```{python} +day_of_week_bar(t) +``` + +```{python} +rolling_downloads(t) +``` + +```{python} +rolling_downloads_by_version(t, version_style="major.minor") +``` + +```{python} +group_bar(t, group_by="installer") +``` + +## Ibis + +```{python} +package = "ibis-framework" + +t = con.table( + "pypi_downloads_per_day_by_version_by_installer_by_type_by_country" +).filter(ibis._["project"] == package) +``` + +```{python} +day_of_week_bar(t) +``` + +```{python} +rolling_downloads(t) +``` + +```{python} +rolling_downloads_by_version(t, version_style="major") +``` + +```{python} +group_bar(t, group_by="installer") +``` + +::: + +::: + +## Shiny for Python application + +We can create an interactive Shiny with Python application using the code above +to serve as a dashboard for better PyPI stats: + +::: {.callout-tip} +See [the GitHub repository](https://github.com/ibis-project/better-pypi-stats) +for the most up-to-date code. +::: + +{{< video https://youtu.be/jkdWaL8CbK4 >}} + +## Reproducing and contributing + +The code is [available on +GitHub](https://github.com/ibis-project/better-pypi-stats). Feel free to open an +issue or pull request if you have any suggested improvements. diff --git a/docs/posts/better-pypi-stats/thumbnail.png b/docs/posts/better-pypi-stats/thumbnail.png new file mode 100644 index 000000000000..fd3034346284 Binary files /dev/null and b/docs/posts/better-pypi-stats/thumbnail.png differ