Skip to content

Commit bf9d860

Browse files
authored
Merge pull request #1195 from cloudflare/release-please--branches--main--changes--next
2 parents 370836b + 02d7cbb commit bf9d860

File tree

3,102 files changed

+199152
-82498
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

3,102 files changed

+199152
-82498
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ jobs:
7878
- env:
7979
CLOUDFLARE_ACCOUNT_ID: f037e56e89293a057740de681ac9abbe
8080
CLOUDFLARE_EMAIL: terraform-acceptance-test@cfapi.net
81-
CLOUDFLARE_ZONE_ID: 0da42c8d2132a9ddaf714f9e7c92011
81+
CLOUDFLARE_ZONE_ID: 0da42c8d2132a9ddaf714f9e7c920711
8282
CLOUDFLARE_API_KEY: ${{ secrets.CLOUDFLARE_API_KEY }}
8383
run: |
84-
rye run python ./examples/workers/ai/demo.py
84+
rye run python ./examples/ai/demo.py
85+
rye run python ./examples/dns/record.py

.github/workflows/release-doctor.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ name: Release Doctor
22

33
on:
44
pull_request:
5+
branches:
6+
- main
57
workflow_dispatch:
68

79
concurrency:

.release-please-manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
".": "3.1.1"
3-
}
2+
".": "4.0.0"
3+
}

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
configured_endpoints: 1256
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-923d8c7667b68c786e6c026c4f4851798943c7d68ea055c0043d9253413c5847.yml
1+
configured_endpoints: 1493
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-3d78f855257b55bbb80884f99c3802cae877968d140eed3557fcb2cdd5f937b3.yml

CHANGELOG.md

Lines changed: 264 additions & 0 deletions
Large diffs are not rendered by default.

CONTRIBUTING.md

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
### With Rye
44

5-
We use [Rye](https://rye.astral.sh/) to manage dependencies so we highly recommend [installing it](https://rye.astral.sh/guide/installation/) as it will automatically provision a Python environment with the expected Python version.
5+
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:
66

7-
After installing Rye, you'll just have to run this command:
7+
```sh
8+
$ ./scripts/bootstrap
9+
```
10+
11+
Or [install Rye manually](https://rye.astral.sh/guide/installation/) and run:
812

913
```sh
1014
$ rye sync --all-features
@@ -31,25 +35,25 @@ $ pip install -r requirements-dev.lock
3135

3236
## Modifying/Adding code
3337

34-
Most of the SDK is generated code, and any modified code will be overridden on the next generation. The
35-
`src/cloudflare/lib/` and `examples/` directories are exceptions and will never be overridden.
38+
Most of the SDK is generated code. Modifications to code will be persisted between generations, but may
39+
result in merge conflicts between manual patches and changes from the generator. The generator will never
40+
modify the contents of the `src/cloudflare/lib/` and `examples/` directories.
3641

3742
## Adding and running examples
3843

39-
All files in the `examples/` directory are not modified by the Stainless generator and can be freely edited or
40-
added to.
44+
All files in the `examples/` directory are not modified by the generator and can be freely edited or added to.
4145

42-
```bash
46+
```py
4347
# add an example to examples/<your-example>.py
4448

4549
#!/usr/bin/env -S rye run python
4650
4751
```
4852

49-
```
50-
chmod +x examples/<your-example>.py
53+
```sh
54+
$ chmod +x examples/<your-example>.py
5155
# run the example against your api
52-
./examples/<your-example>.py
56+
$ ./examples/<your-example>.py
5357
```
5458

5559
## Using the repository from source
@@ -58,8 +62,8 @@ If you’d like to use the repository from source, you can either install from g
5862

5963
To install via git:
6064

61-
```bash
62-
pip install git+ssh://git@github.com/cloudflare/cloudflare-python.git
65+
```sh
66+
$ pip install git+ssh://git@github.com/cloudflare/cloudflare-python.git
6367
```
6468

6569
Alternatively, you can build from source and install the wheel file:
@@ -68,29 +72,29 @@ Building this package will create two files in the `dist/` directory, a `.tar.gz
6872

6973
To create a distributable version of the library, all you have to do is run this command:
7074

71-
```bash
72-
rye build
75+
```sh
76+
$ rye build
7377
# or
74-
python -m build
78+
$ python -m build
7579
```
7680

7781
Then to install:
7882

7983
```sh
80-
pip install ./path-to-wheel-file.whl
84+
$ pip install ./path-to-wheel-file.whl
8185
```
8286

8387
## Running tests
8488

8589
Most tests require you to [set up a mock server](https://github.com/stoplightio/prism) against the OpenAPI spec to run the tests.
8690

87-
```bash
91+
```sh
8892
# you will need npm installed
89-
npx prism mock path/to/your/openapi.yml
93+
$ npx prism mock path/to/your/openapi.yml
9094
```
9195

92-
```bash
93-
rye run pytest
96+
```sh
97+
$ ./scripts/test
9498
```
9599

96100
## Linting and formatting
@@ -100,14 +104,14 @@ This repository uses [ruff](https://github.com/astral-sh/ruff) and
100104

101105
To lint:
102106

103-
```bash
104-
rye run lint
107+
```sh
108+
$ ./scripts/lint
105109
```
106110

107111
To format and fix all ruff issues automatically:
108112

109-
```bash
110-
rye run format
113+
```sh
114+
$ ./scripts/format
111115
```
112116

113117
## Publishing and releases

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright 2024 Cloudflare
189+
Copyright 2025 Cloudflare
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

README.md

Lines changed: 50 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![PyPI version](https://img.shields.io/pypi/v/cloudflare.svg)](https://pypi.org/project/cloudflare/)
44

5-
The Cloudflare Python library provides convenient access to the Cloudflare REST API from any Python 3.7+
5+
The Cloudflare Python library provides convenient access to the Cloudflare REST API from any Python 3.8+
66
application. The library includes type definitions for all request params and response fields,
77
and offers both synchronous and asynchronous clients powered by [httpx](https://github.com/encode/httpx).
88

@@ -26,10 +26,8 @@ import os
2626
from cloudflare import Cloudflare
2727

2828
client = Cloudflare(
29-
# This is the default and can be omitted
30-
api_email=os.environ.get("CLOUDFLARE_EMAIL"),
31-
# This is the default and can be omitted
32-
api_key=os.environ.get("CLOUDFLARE_API_KEY"),
29+
api_email=os.environ.get("CLOUDFLARE_EMAIL"), # This is the default and can be omitted
30+
api_key=os.environ.get("CLOUDFLARE_API_KEY"), # This is the default and can be omitted
3331
)
3432

3533
zone = client.zones.create(
@@ -55,10 +53,8 @@ import asyncio
5553
from cloudflare import AsyncCloudflare
5654

5755
client = AsyncCloudflare(
58-
# This is the default and can be omitted
59-
api_email=os.environ.get("CLOUDFLARE_EMAIL"),
60-
# This is the default and can be omitted
61-
api_key=os.environ.get("CLOUDFLARE_API_KEY"),
56+
api_email=os.environ.get("CLOUDFLARE_EMAIL"), # This is the default and can be omitted
57+
api_key=os.environ.get("CLOUDFLARE_API_KEY"), # This is the default and can be omitted
6258
)
6359

6460

@@ -92,7 +88,7 @@ List methods in the Cloudflare API are paginated.
9288
This library provides auto-paginating iterators with each list response, so you do not have to request successive pages manually:
9389

9490
```python
95-
import cloudflare
91+
from cloudflare import Cloudflare
9692

9793
client = Cloudflare()
9894

@@ -108,7 +104,7 @@ Or, asynchronously:
108104

109105
```python
110106
import asyncio
111-
import cloudflare
107+
from cloudflare import AsyncCloudflare
112108

113109
client = AsyncCloudflare()
114110

@@ -141,7 +137,7 @@ Or just work directly with the returned data:
141137
```python
142138
first_page = await client.accounts.list()
143139
for account in first_page.result:
144-
print(account)
140+
print(account.id)
145141

146142
# Remove `await` for non-async usage.
147143
```
@@ -176,7 +172,7 @@ except cloudflare.APIStatusError as e:
176172
print(e.response)
177173
```
178174

179-
Error codes are as followed:
175+
Error codes are as follows:
180176

181177
| Status Code | Error Type |
182178
| ----------- | -------------------------- |
@@ -247,12 +243,14 @@ Note that requests that time out are [retried twice by default](#retries).
247243

248244
We use the standard library [`logging`](https://docs.python.org/3/library/logging.html) module.
249245

250-
You can enable logging by setting the environment variable `CLOUDFLARE_LOG` to `debug`.
246+
You can enable logging by setting the environment variable `CLOUDFLARE_LOG` to `info`.
251247

252248
```shell
253-
$ export CLOUDFLARE_LOG=debug
249+
$ export CLOUDFLARE_LOG=info
254250
```
255251

252+
Or to `debug` for more verbose logging.
253+
256254
### How to tell whether `None` means `null` or missing
257255

258256
In an API response, a field may be explicitly `null`, or missing entirely; in either case, its value is `None` in this library. You can differentiate the two cases with `.model_fields_set`:
@@ -319,8 +317,7 @@ If you need to access undocumented endpoints, params, or response properties, th
319317
#### Undocumented endpoints
320318

321319
To make requests to undocumented endpoints, you can make requests using `client.get`, `client.post`, and other
322-
http verbs. Options on the client will be respected (such as retries) will be respected when making this
323-
request.
320+
http verbs. Options on the client will be respected (such as retries) when making this request.
324321

325322
```py
326323
import httpx
@@ -349,39 +346,67 @@ can also get all the extra fields on the Pydantic model as a dict with
349346

350347
You can directly override the [httpx client](https://www.python-httpx.org/api/#client) to customize it for your use case, including:
351348

352-
- Support for proxies
353-
- Custom transports
349+
- Support for [proxies](https://www.python-httpx.org/advanced/proxies/)
350+
- Custom [transports](https://www.python-httpx.org/advanced/transports/)
354351
- Additional [advanced](https://www.python-httpx.org/advanced/clients/) functionality
355352

356353
```python
354+
import httpx
357355
from cloudflare import Cloudflare, DefaultHttpxClient
358356

359357
client = Cloudflare(
360358
# Or use the `CLOUDFLARE_BASE_URL` env var
361359
base_url="http://my.test.server.example.com:8083",
362360
http_client=DefaultHttpxClient(
363-
proxies="http://my.test.proxy.example.com",
361+
proxy="http://my.test.proxy.example.com",
364362
transport=httpx.HTTPTransport(local_address="0.0.0.0"),
365363
),
366364
)
367365
```
368366

367+
You can also customize the client on a per-request basis by using `with_options()`:
368+
369+
```python
370+
client.with_options(http_client=DefaultHttpxClient(...))
371+
```
372+
369373
### Managing HTTP resources
370374

371375
By default the library closes underlying HTTP connections whenever the client is [garbage collected](https://docs.python.org/3/reference/datamodel.html#object.__del__). You can manually close the client using the `.close()` method if desired, or with a context manager that closes when exiting.
372376

377+
```py
378+
from cloudflare import Cloudflare
379+
380+
with Cloudflare() as client:
381+
# make requests here
382+
...
383+
384+
# HTTP client is now closed
385+
```
386+
373387
## Semantic versioning
374388

375389
This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions:
376390

377391
1. Changes that only affect static types, without breaking runtime behavior.
378-
1. Changes to library internals which are technically public but not intended or documented for external use. _(Please open a GitHub issue to let us know if you are relying on such internals)_.
392+
1. Changes to library internals which are technically public but not intended or documented for external use.
379393
1. Changes that we do not expect to impact the vast majority of users in practice.
380394

381-
> [!WARNING]
382-
> In addition to the above, changes to type names, structure or methods _may_ occur as we stabilise the automated codegen pipeline. This will be removed in the future once we are further along and the service owner OpenAPI schemas have reached a higher maturity level where changes are not as constant.
383-
> If this isn't suitable for your project, we recommend pinning to a known version or using the previous major version.
395+
### Determining the installed version
396+
397+
If you've upgraded to the latest version but aren't seeing any new features you were expecting then your python environment is likely still using an older version.
398+
399+
You can determine the version that is being used at runtime with:
400+
401+
```py
402+
import cloudflare
403+
print(cloudflare.__version__)
404+
```
384405

385406
## Requirements
386407

387-
Python 3.7 or higher.
408+
Python 3.8 or higher.
409+
410+
## Contributing
411+
412+
See [the contributing documentation](./CONTRIBUTING.md).

SECURITY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Reporting Security Vulnerabilities
22

3-
Please see [this page](https://www.cloudflare.com/.well-known/security.txt) for information on how to report a vulnerability to Cloudflare. Thanks!
3+
Please see [this page](https://www.cloudflare.com/.well-known/security.txt) for information on how to report a vulnerability to Cloudflare. Thanks!

0 commit comments

Comments
 (0)