cloudflare / cloudflare/cloudflare-python

Bootstrap Python runtime with uv for faster build time

Abierto
#2,719 2 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Python
Estrellas
506
Forks
148
Merge medio
3 h 15 min
PR fusionados (30 d)
1

Descripción

### Confirm this is a Python library issue and not an underlying Cloudflare API issue.

- [x] 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](https://developers.cloudflare.com/changelog/product-group/developer-platform/#breaking-changes) 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](https://docs.astral.sh/uv/concepts/python-versions/#cpython-distributions) (used by mise for example). This exact scenario is highlighted in the uv docs in contrast to the uv approach:

> #### [CPython distributions](https://docs.astral.sh/uv/concepts/python-versions/#cpython-distributions)
>
> As Python does not publish official distributable CPython binaries, uv instead uses pre-built distributions from the Astral [python-build-standalone](https://github.com/astral-sh/python-build-standalone) project. python-build-standalone is also is used in many other Python projects, like [Mise](https://mise.jdx.dev/lang/python.html) and [bazelbuild/rules_python](https://github.com/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](https://gregoryszorc.com/docs/python-build-standalone/main/quirks.html) 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

```sh
curl -LsSf https://astral.sh/uv/install.sh | 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

```sh
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

```Python

```

### OS

Linux

### Python version

3.13

### Library version

v5.1.0 (latest)

Guía de contribución

Abrir la guía de contribución

Línea de trabajo

El issue no nombra ningún archivo del repositorio, prueba ni punto de entrada de la implementación. Empieza por confirmar si la configuración del runtime de PYTHON_VERSION corresponde a cloudflare-python o a Cloudflare Pages y, después, localiza dónde reside la responsabilidad del runtime de build. Se considerará completado cuando se haya decidido una ruta de implementación para instalar la versión de Python solicitada con uv y se haya verificado la mejora de tiempo de build reportada.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
build-system, cloud
Tipo de issue
Nueva funcionalidad
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Tranquilo
Claridad
Necesita aclaración
Aptitud para principiantes
30/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.