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
Create a secret.py in the root directory with following content:
API_TOKEN = ""
ACCOUNT_ID = ""
The above variable need to be assigned with your own api token and account id from Cloudflare dashboard.
Then run the following command in terminal:
make test
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. Then replace API_TOKEN & ACCOUNT_ID values with values obtained from Cloudflare dashboard.
#!/usr/bin/env python3
from CloudflareAPI import Cloudflare, jsonPrint
API_TOKEN = ""
ACCOUNT_ID = ""
def main():
cf = Cloudflare(token=API_TOKEN, account_id=ACCOUNT_ID)
print(cf.worker.list())
print(cf.store.list())
Now we can run our program using following command:
poetry run python cloudflare-app
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 Namespacesid- Find the namespace id of the namespacecreate- Create a new namespacerename- Rename an existing namespacedelete- Delete an existing namespace
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cloudflare-api-1.2.0.tar.gz.
File metadata
- Download URL: cloudflare-api-1.2.0.tar.gz
- Upload date:
- Size: 6.7 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
671670a26859a8b7fb0f9bf579e1699d66e1c658bd10fe2893a7f754ebf28f1e
|
|
| MD5 |
eab186694f4b3ff491a8f4689e9347f3
|
|
| BLAKE2b-256 |
880b4a8d6f7ca1d759a3510d67bd9b109dba1f7f245b527acd726ef0b5f5ef6b
|
File details
Details for the file cloudflare_api-1.2.0-py3-none-any.whl.
File metadata
- Download URL: cloudflare_api-1.2.0-py3-none-any.whl
- Upload date:
- Size: 9.7 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aad7fca605c2d446cd2f742762644b211a00c4a8257e0e347111072018d201dd
|
|
| MD5 |
7d6b98abe480816e4ed22222f8905973
|
|
| BLAKE2b-256 |
b00dc10d4540d6995b878c79c03f4c8cfece1992609c38fab50f6ef0afb6d9e0
|