Bootstrap Python runtime with uv for faster build time

オープン
#2,719 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
30/100
issue の種類
機能追加
明瞭さ
説明が足りない
活発さ
静か
技術スタック
python

調査の方向性

この issue では、リポジトリのファイル、テスト、実装のエントリーポイントがいずれも指定されていません。まず、PYTHON_VERSION のランタイム設定が cloudflare-python に属するのか Cloudflare Pages に属するのかを確認し、次にビルドランタイムの担当箇所を特定してください。要求された Python バージョンを uv でインストールするための実装方針が決まり、報告されたビルド時間の改善が検証されれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Confirm this is a Python library issue and not an underlying Cloudflare API issue.
  • This is an issue with the Python library

edit: I'm not sure this is an issue with the "Python library" but with the Python support in CloudFlare itself, but I don't see where that is reportable/feature requestable? I came here via the link in the CloudFlare developer platform changelog and would appreciate being pointed in the right direction if I'm in the wrong place!

Describe the bug

I'm not sure how easy it would be for you to use uv behind the scenes to set Python up itself, but this is something uv supports.

Currently PYTHON_VERSION triggers setup of a Python runtime via pyenv, to my understanding.

I imagine uv would do this faster, as uv is optimised for speed, besides which once I get a Python [with pip] the first thing I have to do is use that to get uv to set up the tool I actually want.

I use uv rather than plain pip because it works with my lockfile, and for many Python developers it is the go-to tool, so this makes cloudflare-python feel a little awkward to work with. I would think this can be easily fixed by having a mechanism to set up uv?

A Python runtime is set up if you set PYTHON_VERSION (here "3.13") but then you have to pip install uv to get uv.

This setup took ~100 seconds, 94% of which is building Python from source. uv can install Python for you, it'd be nice to be able to instead set UV_PYTHON_VERSION and have uv install a Python runtime via python-build-standalone (used by mise for example). This exact scenario is highlighted in the uv docs in contrast to the uv approach:

CPython distributions

As Python does not publish official distributable CPython binaries, uv instead uses pre-built distributions from the Astral python-build-standalone project. python-build-standalone is also is used in many other Python projects, like Mise and bazelbuild/rules_python.

The uv Python distributions are self-contained, highly-portable, and performant. While Python can be built from source, as in tools like pyenv, doing so requires preinstalled system dependencies, and creating optimized, performant builds (e.g., with PGO and LTO enabled) is very slow.

These distributions have some behavior quirks, generally as a consequence of portability; see the python-build-standalone quirks documentation for details.

2026-05-11T09:58:20.18442Z	Detected the following tools from environment: python@3.13.12, pip@25.1.1
2026-05-11T09:58:20.184785Z	Installing python 3.13.12
2026-05-11T09:58:20.92625Z	From https://github.com/pyenv/pyenv
2026-05-11T09:58:20.926531Z	   d26308df..c639152a  master     -> origin/master
2026-05-11T09:58:20.926629Z	 * [new tag]           v2.6.31    -> v2.6.31
2026-05-11T09:58:20.941038Z	 * [new tag]           v2.6.27    -> v2.6.27
2026-05-11T09:58:20.941232Z	 * [new tag]           v2.6.28    -> v2.6.28
2026-05-11T09:58:20.941299Z	 * [new tag]           v2.6.29    -> v2.6.29
2026-05-11T09:58:20.941401Z	 * [new tag]           v2.6.30    -> v2.6.30
2026-05-11T09:58:21.131194Z	python-build 3.13.12 /opt/buildhome/.asdf/installs/python/3.13.12
2026-05-11T09:58:21.206109Z	Downloading Python-3.13.12.tar.xz...
2026-05-11T09:58:21.206372Z	-> https://www.python.org/ftp/python/3.13.12/Python-3.13.12.tar.xz
2026-05-11T09:58:23.253131Z	Installing Python-3.13.12...
2026-05-11T09:59:57.220831Z	Installed Python-3.13.12 to /opt/buildhome/.asdf/installs/python/3.13.12
2026-05-11T09:59:58.07709Z	Executing user command: pip install uv && uvx zensical build
2026-05-11T09:59:58.977421Z	Collecting uv
2026-05-11T09:59:59.031347Z	  Downloading uv-0.11.13-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (11 kB)
2026-05-11T09:59:59.050936Z	Downloading uv-0.11.13-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (24.7 MB)
2026-05-11T09:59:59.530469Z	   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 24.7/24.7 MB 54.2 MB/s  0:00:00
2026-05-11T09:59:59.57034Z	Installing collected packages: uv
2026-05-11T09:59:59.921853Z	Successfully installed uv-0.11.13
2026-05-11T10:00:00.031242Z	
2026-05-11T10:00:00.031568Z	[notice] A new release of pip is available: 25.3 -> 26.1.1
2026-05-11T10:00:00.031744Z	[notice] To update, run: pip3 install --upgrade pip
2026-05-11T10:00:00.100405Z	Reshimming asdf python...

uv setup benchmark

I measured in an Ubuntu (latest) Docker container:

  • Installing uv takes 3 seconds
curl -LsSf https://astral.sh/uv/install.sh | sh
root@564346048fa8:/# export PATH="$HOME/.local/bin:$PATH"
root@564346048fa8:/# uv --version
uv 0.11.13 (x86_64-unknown-linux-gnu)
  • Installing Python 3.13 takes another 3 seconds
root@564346048fa8:/# UV_PYTHON_VERSION=3.13
root@564346048fa8:/# uv python install $UV_PYTHON_VERSION
Installed Python 3.13.13 in 3.31s
 + cpython-3.13.13-linux-x86_64-gnu (python3.13)

So we're easily looking at over 10x faster than the pyenv approach (~6s not 100s)

To Reproduce
  1. Set PYTHON_VERSION when setting up CloudFlare Pages
  2. Build spends 94s compiling Python from source
  3. This compilation step could pull prebuilt binaries much faster
Code snippets

OS

Linux

Python version

3.13

Library version

v5.1.0 (latest)

主要言語
Python
スター
509
フォーク
150
平均マージ
3時間 15分
マージ済み PR(30日)
1

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

cloudflare/cloudflare-python のほかの issue

cloudflare/cloudflare-python の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。