You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+28-24Lines changed: 28 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,9 +2,13 @@
2
2
3
3
### With Rye
4
4
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:
6
6
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:
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+
6
6
application. The library includes type definitions for all request params and response fields,
7
7
and offers both synchronous and asynchronous clients powered by [httpx](https://github.com/encode/httpx).
8
8
@@ -26,10 +26,8 @@ import os
26
26
from cloudflare import Cloudflare
27
27
28
28
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
33
31
)
34
32
35
33
zone = client.zones.create(
@@ -55,10 +53,8 @@ import asyncio
55
53
from cloudflare import AsyncCloudflare
56
54
57
55
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
62
58
)
63
59
64
60
@@ -92,7 +88,7 @@ List methods in the Cloudflare API are paginated.
92
88
This library provides auto-paginating iterators with each list response, so you do not have to request successive pages manually:
93
89
94
90
```python
95
-
import cloudflare
91
+
from cloudflareimport Cloudflare
96
92
97
93
client = Cloudflare()
98
94
@@ -108,7 +104,7 @@ Or, asynchronously:
108
104
109
105
```python
110
106
import asyncio
111
-
import cloudflare
107
+
from cloudflareimport AsyncCloudflare
112
108
113
109
client = AsyncCloudflare()
114
110
@@ -141,7 +137,7 @@ Or just work directly with the returned data:
141
137
```python
142
138
first_page =await client.accounts.list()
143
139
for account in first_page.result:
144
-
print(account)
140
+
print(account.id)
145
141
146
142
# Remove `await` for non-async usage.
147
143
```
@@ -176,7 +172,7 @@ except cloudflare.APIStatusError as e:
176
172
print(e.response)
177
173
```
178
174
179
-
Error codes are as followed:
175
+
Error codes are as follows:
180
176
181
177
| Status Code | Error Type |
182
178
| ----------- | -------------------------- |
@@ -247,12 +243,14 @@ Note that requests that time out are [retried twice by default](#retries).
247
243
248
244
We use the standard library [`logging`](https://docs.python.org/3/library/logging.html) module.
249
245
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`.
251
247
252
248
```shell
253
-
$ export CLOUDFLARE_LOG=debug
249
+
$ export CLOUDFLARE_LOG=info
254
250
```
255
251
252
+
Or to `debug` for more verbose logging.
253
+
256
254
### How to tell whether `None` means `null` or missing
257
255
258
256
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
319
317
#### Undocumented endpoints
320
318
321
319
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.
324
321
325
322
```py
326
323
import httpx
@@ -349,39 +346,67 @@ can also get all the extra fields on the Pydantic model as a dict with
349
346
350
347
You can directly override the [httpx client](https://www.python-httpx.org/api/#client) to customize it for your use case, including:
351
348
352
-
- Support for proxies
353
-
- Custom transports
349
+
- Support for [proxies](https://www.python-httpx.org/advanced/proxies/)
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.
372
376
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
+
373
387
## Semantic versioning
374
388
375
389
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:
376
390
377
391
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.
379
393
1. Changes that we do not expect to impact the vast majority of users in practice.
380
394
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
+
```
384
405
385
406
## Requirements
386
407
387
-
Python 3.7 or higher.
408
+
Python 3.8 or higher.
409
+
410
+
## Contributing
411
+
412
+
See [the contributing documentation](./CONTRIBUTING.md).
0 commit comments