{"id":1424,"library":"cloudflare","title":"Cloudflare Python SDK","description":"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.","status":"active","version":"4.3.1","language":"en","source_language":"en","source_url":"https://github.com/cloudflare/cloudflare-python","tags":["cloudflare","api","sdk","cloud"],"install":[{"cmd":"pip install cloudflare","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"The top-level `Cloudflare` module contains the client class and exceptions. It's imported directly, and the client is then accessed as `Cloudflare.Cloudflare`.","wrong":"from cloudflare import Cloudflare","symbol":"Cloudflare","correct":"import Cloudflare"}],"quickstart":{"code":"import os\nimport Cloudflare\n\n# Ensure CLOUDFLARE_API_TOKEN is set in your environment\n# Example: export CLOUDFLARE_API_TOKEN=\"your_api_token\"\n\ncf = Cloudflare.Cloudflare(token=os.environ.get('CLOUDFLARE_API_TOKEN', ''))\n\ntry:\n    # Example: List all zones associated with the API Token\n    zones = cf.zones.get()\n    print(f\"Found {len(zones)} zones:\")\n    for zone in zones:\n        print(f\"- {zone['name']} (ID: {zone['id']})\")\n\n    if zones:\n        # Example: Get details for the first zone\n        first_zone_id = zones[0]['id']\n        zone_details = cf.zones.get(first_zone_id)\n        print(f\"\\nDetails for {zone_details['name']}: {zone_details['status']}\")\n\nexcept Cloudflare.CloudflareAPIError as e:\n    print(f\"Cloudflare API Error: {e}\")\nexcept Exception as e:\n    print(f\"An unexpected error occurred: {e}\")","lang":"python","description":"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."},"warnings":[{"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.","message":"Version 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.","severity":"breaking","affected_versions":">=5.0.0-beta.1"},{"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.","message":"Version 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.","severity":"breaking","affected_versions":">=4.0.0"},{"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.","message":"Versions 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.","severity":"breaking","affected_versions":"3.x, 4.x"},{"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.","message":"Cloudflare 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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}