Python client for the Cloudflare v4 API
Project description
cloudflare-api
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
- Go to Dashboard
- Create Token
- Use
Edit Cloudflare Workers
template - Select one account from Account Resources
- Select
All Zones
or specific zones under Zone Resources - Continue to summary
- Create Token
- Copy the token and save it somewhere secret & secure.
Create a secret.py
in the root directory with following content and replace API_TOKEN
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 accessget_id
- Return account id if only one account exists. Otherwise display all accounts availabe and exit.details
- Display details of an accountrename
* - 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 workerSubdomain
create
- Create a new subdomain if none existsget
- Get the current subdomain from cloudflare account
Store(Workers KV)
list
- List all existing Namespacesget_id
- Find the namespace id of the namespacecreate
- Create a new namespacerename
- Rename an existing namespacedelete
- Delete an existing namespace
( * : Not accessable with default Worker Token )
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for cloudflare_api-1.2.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1367fd2910c1348d656ab55b519a58a44aea48714c4c986d7061bf60497449a5 |
|
MD5 | 4dc6271db002251e5bfc55a6b530e5c6 |
|
BLAKE2b-256 | 117a8dd2cfa64092e85424e44913b058844910ed193b4e0e39c48b7e34900871 |