cloudflare
The official Python library for the cloudflare API
What it is and what it does
This is the official Python client for the Cloudflare REST API, generated using Stainless. It wraps Cloudflare's full API surface—zones, accounts, DNS records, KV storage, and more—in a typed, modern Python interface. The library ships with both synchronous and asynchronous clients powered by httpx, and includes full type definitions for request parameters and response objects using Pydantic models and TypedDicts.
The client handles pagination automatically, error classification (connection errors, rate limits, authentication failures, and HTTP status codes), and retries certain transient failures by default. It supports file uploads, nested parameters, and provides helper methods on response objects for serialization. You can optionally swap the HTTP backend to aiohttp for improved async concurrency. The library targets Python 3.9+ and is actively maintained.
Use it for:
- Manage DNS records, zones, and accounts programmatically for multi-tenant or infrastructure-as-code workflows.
- Build async applications that interact with Cloudflare's KV storage, Workers, or other edge services.
- Automate SSL/TLS certificate provisioning, firewall rules, or DDoS protection settings.
- Integrate Cloudflare API calls into monitoring or observability platforms with typed, autocomplete-friendly code.
- Paginate through large lists of accounts, zones, or DNS records without manual page handling.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides a Python client library for the Cloudflare REST API with both synchronous and asynchronous interfaces, full type hints, and automatic pagination support.
Yes. This is the official, actively maintained Cloudflare Python client with low install friction, no known vulnerabilities, permissive licensing, and strong type support. Install it if you need to interact with Cloudflare's API from Python—it is the canonical choice for this task.
Install
cloudflare on PyPI
pip
pip install cloudflareuv
uv add cloudflarepoetry
poetry add cloudflareInstalling cloudflare
Before you install
Low install friction with a pure-Python wheel. Actively maintained with a recent release (23 days old) and 494 repository stars. Supports current Python versions (3.9+) and has no known vulnerabilities.
License in practice
Licensed under Apache-2.0 (permissive), allowing commercial and private use with minimal restrictions beyond attribution and liability disclaimers.
Quickstart
pip install cloudflare
import os
from cloudflare import Cloudflare
client = Cloudflare(api_token=os.environ.get("CLOUDFLARE_API_TOKEN"))
zone = client.zones.create(
account={"id": "023e105f4ecef8ad9ca31a8372d0c353"},
name="example.com",
type="full",
)
print(zone.id)
Requires Python 3.9 or later and a valid Cloudflare API token (typically provided via environment variable).
Verify before relying
- Rate limit handling and retry behavior beyond the documented default 2 retries with exponential backoff.
- Performance characteristics of the async client with aiohttp versus httpx under high concurrency.
- Completeness of API coverage relative to the full Cloudflare REST API surface.
Package facts
| License | Apache-2.0 (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 6 — anyio, distro, httpx, pydantic, sniffio, typing-extensions |
| Maintenance | actively maintained — 23 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 10,122,213/month — #1,480 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: cloudflare-5.6.0-py3-none-any.whl
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
arcadepyProvides a typed Python client library for the…
permissive · top 15,000 on PyPI
runwaymlProvides a Python client library for the…
permissive · top 15,000 on PyPI
composio-clientA Python client library for the Composio REST…
permissive · top 5,000 on PyPI
steel-sdkProvides a typed Python client for the Steel…
permissive · top 15,000 on PyPI
flask-cloudflaredStarts a Cloudflare TryCloudflare tunnel for a…
permissive · top 15,000 on PyPI
sambanovaProvides a Python client library for accessing…
permissive · top 15,000 on PyPI
kernelProvides a Python client library for the Kernel…
permissive · top 15,000 on PyPI
postgrid-pythonProvides a typed Python client for the PostGrid…
permissive · top 15,000 on PyPI
supermemoryProvides a Python client library for the…
permissive · top 15,000 on PyPI
glean-api-clientA Python SDK for accessing Glean's REST API,…
unclear · top 15,000 on PyPI