Repolode
cloudflare

cloudflare/cloudflare-python

Official Python SDK for the Cloudflare REST API, with sync and async clients and typed requests and responses.

Stars
516
Forks
159
Open issues
33
Last commit
2 days ago

What is it?

cloudflare-python is the official Python client for the Cloudflare REST API. It lets Python code manage Cloudflare resources such as zones, accounts and KV namespaces through method calls instead of hand-written HTTP requests. The library supports Python 3.9 and later and ships type definitions for all request parameters and response fields.

Both synchronous (Cloudflare) and asynchronous (AsyncCloudflare) clients are provided, built on httpx, with an optional aiohttp backend for the async client. List methods return auto-paginating iterators, and file uploads accept bytes, paths or (filename, contents, media type) tuples. Responses are Pydantic models with to_json() and to_dict() helpers.

The client includes configurable retries with exponential backoff, per-request timeouts, a typed exception hierarchy keyed by HTTP status, and raw or streaming response access. The code is generated with Stainless, and undocumented endpoints can be called through the client's get and post methods.

Key features

  • 01Sync and async clients for the Cloudflare REST API.
  • 02Type definitions for request parameters and response fields, with Pydantic response models.
  • 03Auto-paginating iterators for list endpoints.
  • 04Automatic retries with exponential backoff, configurable timeouts and a status-code-based exception hierarchy.
  • 05Optional aiohttp backend for the async client.

Use cases

  • Automating DNS and zone configuration from Python scripts or infrastructure tooling.
  • Managing Cloudflare accounts and KV data in async Python services.
  • Calling Cloudflare API endpoints from a typed codebase with editor autocomplete.

Quick start

  1. 1

    Install the library from PyPI

    pip install cloudflare
  2. 2

    Create a client with your API token and call the API

Things to know

  • Requires a Cloudflare API token to make requests.
  • Requires Python 3.9 or newer.

In collections

Topics

FAQ

What is cloudflare-python?
Official Python SDK for the Cloudflare REST API, with sync and async clients and typed requests and responses. cloudflare-python is the official Python client for the Cloudflare REST API. It lets Python code manage Cloudflare resources such as zones, accounts and KV namespaces through method calls instead of hand-written HTTP requests. The library supports Python 3.9 and later and ships type definitions for all request parameters and response fields.
Is cloudflare-python free to use? What license does it have?
cloudflare-python is open source under the Apache-2.0 license. Check the license terms before using it in commercial products.
Is cloudflare-python still maintained?
Actively maintained. The last commit to cloudflare-python was on Nov 5, 2026.
What can I use cloudflare-python for?
Automating DNS and zone configuration from Python scripts or infrastructure tooling. Managing Cloudflare accounts and KV data in async Python services. Calling Cloudflare API endpoints from a typed codebase with editor autocomplete.
How do I install cloudflare-python?
Install the library from PyPI: pip install cloudflare Create a client with your API token and call the API
Where can I get cloudflare-python?
The source code and installation instructions are on GitHub: https://github.com/cloudflare/cloudflare-python

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects