skillfed

cloudflare

The official Python library for the cloudflare API

cloudflare v5.6.0 10.1M downloads/30d#1,480 on PyPI494
Permissive license Apache-2.0 Active released

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 cloudflare

uv

uv add cloudflare

poetry

poetry add cloudflare

Installing 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

Intended Audience :: DevelopersLicense :: OSI Approved :: Apache Software LicenseOperating System :: MacOSOperating System :: Microsoft :: WindowsOperating System :: OS IndependentOperating System :: POSIXOperating System :: POSIX :: LinuxProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.9Topic :: Software Development :: Libraries :: Python ModulesTyping :: Typed

Tags

cloudflare api clientcloudflare python sdkdns management pythoncdn api pythoncloudflare zones managementasync cloudflare clienttyped cloudflare api
cloudflare-apiasync-http-clienttyped-sdk

More Python Modules packages

Further reading