Skip to content

Commit e4b3835

Browse files
authored
Merge pull request #2708 from cloudflare/docs/add-authentication-section
docs: add Authentication section to README
2 parents 5929e33 + 70d934a commit e4b3835

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,45 @@ The REST API documentation can be found on [developers.cloudflare.com](https://d
2929
pip install --pre cloudflare
3030
```
3131

32+
## Authentication
33+
34+
The SDK supports multiple authentication methods. Each can be provided as a constructor argument or read automatically from an environment variable.
35+
36+
### API Token (recommended)
37+
38+
[API tokens](https://developers.cloudflare.com/fundamentals/api/get-started/create-token/) are scoped to specific permissions and are the recommended way to authenticate.
39+
40+
```python
41+
from cloudflare import Cloudflare
42+
43+
client = Cloudflare(api_token="your-api-token")
44+
45+
# Or set the CLOUDFLARE_API_TOKEN environment variable and omit the argument:
46+
client = Cloudflare()
47+
```
48+
49+
### API Key + Email
50+
51+
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.
52+
53+
```python
54+
from cloudflare import Cloudflare
55+
56+
client = Cloudflare(
57+
api_key="your-global-api-key",
58+
api_email="user@example.com",
59+
)
60+
61+
# Or set CLOUDFLARE_API_KEY and CLOUDFLARE_EMAIL environment variables:
62+
client = Cloudflare()
63+
```
64+
65+
| Parameter | Environment variable | Header sent |
66+
|-----------|---------------------|-------------|
67+
| `api_token` | `CLOUDFLARE_API_TOKEN` | `Authorization: Bearer <token>` |
68+
| `api_key` | `CLOUDFLARE_API_KEY` | `X-Auth-Key: <key>` |
69+
| `api_email` | `CLOUDFLARE_EMAIL` | `X-Auth-Email: <email>` |
70+
3271
## Usage
3372

3473
The full API of this library can be found in [api.md](api.md).

0 commit comments

Comments
 (0)