Skip to main content

Python client for the Cloudflare v4 API

Project description

cloudflare-api

Python Package PyPI - Status PyPI CodeFactor GitHub license

Python client for Cloudflare API v4

Usage

Python Package

pip install cloudflare-api

Sample code can be found inside /test.py

Source Code

git clone https://github.com/nikhiljohn10/cloudflare-api
cd cloudflare-api

Instructions to get new API Token

  1. Go to Dashboard
  2. Create Token
  3. Use Edit Cloudflare Workers template
  4. Select one account from Account Resources
  5. Select All Zones or specific zones under Zone Resources
  6. Continue to summary
  7. Create Token
  8. Copy the token and save it somewhere secret & secure.

Create a secret.py in the root directory with following content and replace API_TOKEN's value with the token obtained from Cloudflare Dashboard:

API_TOKEN = "API_TOKEN"

Then run the following command in terminal:

make test

Note: The secret.py file is ignored by git

Example

For this example, poetry is used for easy setup.

python3 -m pip install poetry
poetry new cloudflare-app
cd cloudflare-app
poetry add cloudflare-api

Copy the code below in to a new file ./cloudflare-app/__main__.py.

#!/usr/bin/env python3

from CloudflareAPI import Cloudflare, jsonPrint

def main():
  cf = Cloudflare(token="API_TOKEN")
  print(cf.worker.list())
  print(cf.store.list())

Now replace API_TOKEN values with values obtained from Cloudflare dashboard. You can now run the program using following command:

poetry run python cloudflare-app

Default Permissions

1. Account

  • Workers Tail ( Read )
  • Workers KV Storage ( Edit )
  • Workers Scripts ( Edit )
  • Account Settings ( Read )

2. Zones

  • Workers Routes ( Edit )

3. Users

  • User Details ( Read )

Available endpoints

Account

  • list - List all accounts where given token have access
  • get_id - Return account id if only one account exists. Otherwise display all accounts availabe and exit.
  • details - Display details of an account
  • rename* - Rename an existing account

Worker

  • list - List all existing workers

  • upload - Upload a new worker with binding if given

  • download - Download an existing worker

  • deploy - Deploy an existing worker using the subdomain

  • undeploy - Undeploy an existing worker

  • delete - Delete an existing worker

    Subdomain

    • create - Create a new subdomain if none exists
    • get - Get the current subdomain from cloudflare account

Store(Workers KV)

  • list - List all existing Namespaces
  • get_id - Find the namespace id of the namespace
  • create - Create a new namespace
  • rename - Rename an existing namespace
  • delete - Delete an existing namespace

( * : Not accessable with default Worker Token )

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cloudflare-api-1.2.6.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cloudflare_api-1.2.6-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file cloudflare-api-1.2.6.tar.gz.

File metadata

  • Download URL: cloudflare-api-1.2.6.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.7.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6

File hashes

Hashes for cloudflare-api-1.2.6.tar.gz
Algorithm Hash digest
SHA256 66ca5c4387e4ab34b6eeb132c2b7282e18f83c4418ad51d240a94bcc284e4413
MD5 365d8a28dea0dfc5af616c6f61cfd51a
BLAKE2b-256 482a0cba5d156088bee9ae6a86a9675f6981125000e9c0f96bb04c006d93a6fc

See more details on using hashes here.

File details

Details for the file cloudflare_api-1.2.6-py3-none-any.whl.

File metadata

  • Download URL: cloudflare_api-1.2.6-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.7.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6

File hashes

Hashes for cloudflare_api-1.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 44b59b5c3a148f4b7f81c79a9120eb8cbe8edd7feea53b7df3dfaa5b7e10fbac
MD5 075f90997aa65c71e7cd7e98bd6bf3f0
BLAKE2b-256 ef5a6256f5a777106ec02c2b87fd7724d3b21fe7a305b87a42de35ed50b6c6f7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page