Registry / http-networking / cloudflare

cloudflare

JSON →
library5.6.0pypypi✓ verified 26d ago

The official Python library for interacting with the Cloudflare API. It provides a comprehensive client for accessing various Cloudflare services. The current stable version is 4.3.1. The library follows a frequent release cadence, often introducing new features and occasionally breaking changes due to underlying API updates.

pip install cloudflare
INSTALL
IMPORT
SIG · CLOUDFLARE
C
cloudflare
http-networkingpythonv5.6.0
Install
8.5s avg
Import
939ms
Disk
123MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v5.6.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.978s · 121.1MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 8.5s · import 0.900s · 121MB
123MB installed
● package 123MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Cloudflare
from cloudflare import Cloudflare
import Cloudflare
Client
from cloudflare import Client
AsyncCloudflare
from cloudflare import AsyncCloudflare

This quickstart initializes the Cloudflare client using an API Token from an environment variable and then lists your Cloudflare zones. It demonstrates basic API interaction and error handling.

import os import Cloudflare # Ensure CLOUDFLARE_API_TOKEN is set in your environment # Example: export CLOUDFLARE_API_TOKEN="your_api_token" cf = Cloudflare.Cloudflare(token=os.environ.get('CLOUDFLARE_API_TOKEN', '')) try: # Example: List all zones associated with the API Token zones = cf.zones.get() print(f"Found {len(zones)} zones:") for zone in zones: print(f"- {zone['name']} (ID: {zone['id']})") if zones: # Example: Get details for the first zone first_zone_id = zones[0]['id'] zone_details = cf.zones.get(first_zone_id) print(f"\nDetails for {zone_details['name']}: {zone_details['status']}") except Cloudflare.CloudflareAPIError as e: print(f"Cloudflare API Error: {e}") except Exception as e: print(f"An unexpected error occurred: {e}")
Debug
Known issues
breakingVersion 5.0.0 (currently in beta) introduces a large number of breaking changes due to updates in Cloudflare's OpenAPI definitions and the library's code generation process. Existing code will likely require significant updates.
fix
Review the official changelog for v5.0.0 when it is released. Be prepared for extensive updates to API call paths, request/response models, and potentially authentication methods. Consider pinning your dependency to `<5.0.0` until you are ready to migrate.
affects: >=5.0.0-beta.1
breakingVersion 4.0.0 introduced specific breaking changes, including reshuffling of the `addressing` namespace and renaming of the `cf-r2-jurisdiction` parameter to `jurisdiction` in R2 operations.
fix
If upgrading from <4.0.0, update code interacting with `addressing` endpoints or the `jurisdiction` parameter in R2 to reflect the new structure and parameter names as per the official documentation.
affects: >=4.0.0
breakingVersions 3.x marked a complete ground-up rewrite of the SDK, moving to code generation from Cloudflare's OpenAPI spec. This introduced frequent minor breaking changes in method names, types, and client structure compared to 2.x versions.
fix
If migrating from 2.x, expect a complete overhaul of your Cloudflare API calls. Pin your dependency to `cloudflare<3.0.0` if you need stability with the older API, or thoroughly review the 3.x/4.x changelogs for the new structure.
affects: 3.x, 4.x
gotchaCloudflare supports different authentication methods: API Tokens (recommended) and Global API Keys. The client can be initialized with `token` (for API Tokens) or `email` and `token` (for Global API Key). Mixing them incorrectly or providing the wrong type of key can lead to authentication failures.
fix
For API Tokens, use `Cloudflare.Cloudflare(token='YOUR_API_TOKEN')`. For Global API Keys, use `Cloudflare.Cloudflare(email='your_email@example.com', token='YOUR_GLOBAL_API_KEY')`. Ensure the API Token has the necessary permissions for the calls you are making.
affects: All versions
gotchaThe Cloudflare library must be installed using pip (e.g., `pip install cloudflare`) before it can be imported and used. A `ModuleNotFoundError` indicates the package is not found in your Python environment.
fix
Ensure the Cloudflare library is installed in your Python environment by running `pip install cloudflare`. If using a virtual environment, ensure it is activated before running your script.
affects: All versions
gotchaThe `Cloudflare` library must be installed (e.g., `pip install cloudflare`) before it can be imported. A `ModuleNotFoundError` indicates the package is not found in the Python environment. Ensure the correct package name is used for installation and the correct module name for import.
fix
Ensure the `cloudflare` package is installed in your Python environment using `pip install cloudflare`. Verify that your `import` statement uses the correct module name, typically `Cloudflare` for this library.
affects: All versions
Upgrade
Version history
5.6.0latest on PyPI · released Jul 22, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
26 hits · last 30 days
node
24
OpenAI (training)
1
Resources
cloudflare — pip install cloudflare · libregistry