Skip to content
Merged
3 changes: 1 addition & 2 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT}

USER vscode

RUN curl -sSf https://rye.astral.sh/get | RYE_VERSION="0.44.0" RYE_INSTALL_OPTION="--yes" bash
ENV PATH=/home/vscode/.rye/shims:$PATH
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/

RUN echo "[[ -d .venv ]] && source .venv/bin/activate || export PATH=\$PATH" >> /home/vscode/.bashrc
4 changes: 2 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"context": ".."
},

"postStartCommand": "rye sync --all-features",
"postStartCommand": "uv sync --all-extras",

"customizations": {
"vscode": {
Expand All @@ -20,7 +20,7 @@
"python.defaultInterpreterPath": ".venv/bin/python",
"python.typeChecking": "basic",
"terminal.integrated.env.linux": {
"PATH": "/home/vscode/.rye/shims:${env:PATH}"
"PATH": "${env:PATH}"
}
}
}
Expand Down
57 changes: 23 additions & 34 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,13 @@ jobs:
steps:
- uses: actions/checkout@v6

- name: Install Rye
run: |
curl -sSf https://rye.astral.sh/get | bash
echo "$HOME/.rye/shims" >> $GITHUB_PATH
env:
RYE_VERSION: '0.44.0'
RYE_INSTALL_OPTION: '--yes'
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
version: '0.10.2'

- name: Install dependencies
run: rye sync --all-features
run: uv sync --all-extras

- name: Run lints
run: ./scripts/lint
Expand All @@ -53,19 +50,16 @@ jobs:
steps:
- uses: actions/checkout@v6

- name: Install Rye
run: |
curl -sSf https://rye.astral.sh/get | bash
echo "$HOME/.rye/shims" >> $GITHUB_PATH
env:
RYE_VERSION: '0.44.0'
RYE_INSTALL_OPTION: '--yes'
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
version: '0.10.2'

- name: Install dependencies
run: rye sync --all-features
run: uv sync --all-extras

- name: Run build
run: rye build
run: uv build

- name: Get GitHub OIDC Token
if: |-
Expand Down Expand Up @@ -94,19 +88,18 @@ jobs:
steps:
- uses: actions/checkout@v6

- name: Install Rye
run: |
curl -sSf https://rye.astral.sh/get | bash
echo "$HOME/.rye/shims" >> $GITHUB_PATH
env:
RYE_VERSION: '0.44.0'
RYE_INSTALL_OPTION: '--yes'
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
version: '0.10.2'

- name: Bootstrap
run: ./scripts/bootstrap

- name: Run tests
run: ./scripts/test
env:
UV_PYTHON: ">=3.9.0"

examples:
timeout-minutes: 10
Expand All @@ -117,21 +110,17 @@ jobs:
steps:
- uses: actions/checkout@v6

- name: Install Rye
run: |
curl -sSf https://rye.astral.sh/get | bash
echo "$HOME/.rye/shims" >> $GITHUB_PATH
env:
RYE_VERSION: '0.44.0'
RYE_INSTALL_OPTION: '--yes'
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
version: '0.10.2'
- name: Install dependencies
run: |
rye sync --all-features
run: uv sync --all-extras

- env:
CLOUDFLARE_ACCOUNT_ID: f037e56e89293a057740de681ac9abbe
CLOUDFLARE_EMAIL: terraform-acceptance-test@cfapi.net
CLOUDFLARE_ZONE_ID: 0da42c8d2132a9ddaf714f9e7c920711
CLOUDFLARE_API_KEY: ${{ secrets.CLOUDFLARE_API_KEY }}
run: |
rye run python ./examples/dns/record.py
uv run python ./examples/dns/record.py
16 changes: 6 additions & 10 deletions .github/workflows/detect-breaking-changes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,15 @@ jobs:
# Ensure we can check out the pull request base in the script below.
fetch-depth: ${{ env.FETCH_DEPTH }}

- name: Install Rye
run: |
curl -sSf https://rye.astral.sh/get | bash
echo "$HOME/.rye/shims" >> $GITHUB_PATH
env:
RYE_VERSION: '0.44.0'
RYE_INSTALL_OPTION: '--yes'
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
version: '0.10.2'
- name: Install dependencies
run: |
rye sync --all-features
run: uv sync --all-extras
- name: Detect removed symbols
run: |
rye run python scripts/detect-breaking-changes.py "${{ github.event.pull_request.base.sha }}"
uv run python scripts/detect-breaking-changes.py "${{ github.event.pull_request.base.sha }}"

- name: Detect breaking changes
run: |
Expand Down
11 changes: 4 additions & 7 deletions .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@ jobs:
steps:
- uses: actions/checkout@v6

- name: Install Rye
run: |
curl -sSf https://rye.astral.sh/get | bash
echo "$HOME/.rye/shims" >> $GITHUB_PATH
env:
RYE_VERSION: '0.44.0'
RYE_INSTALL_OPTION: '--yes'
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
version: '0.9.13'

- name: Publish to PyPI
run: |
Expand Down
4 changes: 2 additions & 2 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 2195
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-a6c352830d1270d0abb5bb983058ea21815e1bb7d2e163965335dcb0e706f057.yml
openapi_spec_hash: ffe469d5b0b3f29c20ccb91c0a2862e7
config_hash: a83bae9f0be0219cfe77d38d5af60d4a
openapi_spec_hash: aa452e4dfaec546a7e50ef8665bd39f4
config_hash: d3379006654eb5479a62d9576648acc5
2 changes: 1 addition & 1 deletion Brewfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
brew "rye"
brew "uv"

22 changes: 11 additions & 11 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
## Setting up the environment

### With Rye
### With `uv`

We use [Rye](https://rye.astral.sh/) to manage dependencies because it will automatically provision a Python environment with the expected Python version. To set it up, run:
We use [uv](https://docs.astral.sh/uv/) to manage dependencies because it will automatically provision a Python environment with the expected Python version. To set it up, run:

```sh
$ ./scripts/bootstrap
```

Or [install Rye manually](https://rye.astral.sh/guide/installation/) and run:
Or [install uv manually](https://docs.astral.sh/uv/getting-started/installation/) and run:

```sh
$ rye sync --all-features
$ uv sync --all-extras
```

You can then run scripts using `rye run python script.py` or by activating the virtual environment:
You can then run scripts using `uv run python script.py` or by manually activating the virtual environment:

```sh
# Activate the virtual environment - https://docs.python.org/3/library/venv.html#how-venvs-work
# manually activate - https://docs.python.org/3/library/venv.html#how-venvs-work
$ source .venv/bin/activate

# now you can omit the `rye run` prefix
# now you can omit the `uv run` prefix
$ python script.py
```

### Without Rye
### Without `uv`

Alternatively if you don't want to install `Rye`, you can stick with the standard `pip` setup by ensuring you have the Python version specified in `.python-version`, create a virtual environment however you desire and then install dependencies using this command:
Alternatively if you don't want to install `uv`, you can stick with the standard `pip` setup by ensuring you have the Python version specified in `.python-version`, create a virtual environment however you desire and then install dependencies using this command:

```sh
$ pip install -r requirements-dev.lock
Expand All @@ -45,7 +45,7 @@ All files in the `examples/` directory are not modified by the generator and can
```py
# add an example to examples/<your-example>.py

#!/usr/bin/env -S rye run python
#!/usr/bin/env -S uv run python
```

Expand All @@ -72,7 +72,7 @@ Building this package will create two files in the `dist/` directory, a `.tar.gz
To create a distributable version of the library, all you have to do is run this command:

```sh
$ rye build
$ uv build
# or
$ python -m build
```
Expand Down
39 changes: 0 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,45 +29,6 @@ The REST API documentation can be found on [developers.cloudflare.com](https://d
pip install --pre cloudflare
```

## Authentication

The SDK supports multiple authentication methods. Each can be provided as a constructor argument or read automatically from an environment variable.

### API Token (recommended)

[API tokens](https://developers.cloudflare.com/fundamentals/api/get-started/create-token/) are scoped to specific permissions and are the recommended way to authenticate.

```python
from cloudflare import Cloudflare

client = Cloudflare(api_token="your-api-token")

# Or set the CLOUDFLARE_API_TOKEN environment variable and omit the argument:
client = Cloudflare()
```

### API Key + Email

The [Global API Key](https://developers.cloudflare.com/fundamentals/api/get-started/keys/) authenticates using a key and email pair. Both must be provided together.

```python
from cloudflare import Cloudflare

client = Cloudflare(
api_key="your-global-api-key",
api_email="user@example.com",
)

# Or set CLOUDFLARE_API_KEY and CLOUDFLARE_EMAIL environment variables:
client = Cloudflare()
```

| Parameter | Environment variable | Header sent |
|-----------|---------------------|-------------|
| `api_token` | `CLOUDFLARE_API_TOKEN` | `Authorization: Bearer <token>` |
| `api_key` | `CLOUDFLARE_API_KEY` | `X-Auth-Key: <key>` |
| `api_email` | `CLOUDFLARE_EMAIL` | `X-Auth-Email: <email>` |

## Usage

The full API of this library can be found in [api.md](api.md).
Expand Down
5 changes: 3 additions & 2 deletions bin/publish-pypi
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env bash

set -eux
rm -rf dist
mkdir -p dist
rye build --clean
rye publish --yes --token=$PYPI_TOKEN
uv build
uv publish --token=$PYPI_TOKEN
9 changes: 0 additions & 9 deletions noxfile.py

This file was deleted.

52 changes: 19 additions & 33 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,53 +43,39 @@ Repository = "https://github.com/cloudflare/cloudflare-python"
[project.optional-dependencies]
aiohttp = ["aiohttp", "httpx_aiohttp>=0.1.9"]

[tool.rye]
[tool.uv]
managed = true
# version pins are in requirements-dev.lock
dev-dependencies = [
required-version = ">=0.9"
conflicts = [
[
{ group = "pydantic-v1" },
{ group = "pydantic-v2" },
],
]

[dependency-groups]
# version pins are in uv.lock
dev = [
"pyright==1.1.399",
"mypy==1.17",
"respx",
"pytest",
"pytest-asyncio",
"ruff",
"time-machine",
"nox",
"dirty-equals>=0.6.0",
"importlib-metadata>=6.7.0",
"rich>=13.7.1",
"pytest-xdist>=3.6.1",
"griffe>=1",
]

[tool.rye.scripts]
format = { chain = [
"format:ruff",
"format:docs",
"fix:ruff",
# run formatting again to fix any inconsistencies when imports are stripped
"format:ruff",
]}
"format:docs" = "bash -c 'python scripts/utils/ruffen-docs.py README.md $(find . -type f -name api.md)'"
"format:ruff" = "ruff format"

"lint" = { chain = [
"check:ruff",
"typecheck",
"check:importable",
]}
"check:ruff" = "ruff check ."
"fix:ruff" = "ruff check --fix ."

"check:importable" = "python -c 'import cloudflare'"

typecheck = { chain = [
"typecheck:pyright",
"typecheck:mypy"
]}
"typecheck:pyright" = "pyright"
"typecheck:verify-types" = "pyright --verifytypes cloudflare --ignoreexternal"
"typecheck:mypy" = "mypy ."
pydantic-v1 = [
"pydantic>=1.9.0,<2",
]
pydantic-v2 = [
"pydantic~=2.0 ; python_full_version < '3.14'",
"pydantic~=2.12 ; python_full_version >= '3.14'",
]

[build-system]
requires = ["hatchling==1.26.3", "hatch-fancy-pypi-readme"]
Expand Down
Loading
Loading