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
Accounts
-
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 Script
-
list
- List all existing workers -
upload
- Upload a new worker with binding if given -
download
- Download an existing worker -
delete
- Delete an existing worker
Workers KV
-
list
- List all existing Namespaces -
id
- Find the namespace id of the namespace -
create
- Create a new namespace -
rename
- Rename an existing namespace -
delete
- 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
cloudflare-api-1.1.1.tar.gz
(6.1 kB
view hashes)
Built Distribution
Close
Hashes for cloudflare_api-1.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | afc2dcb89596a92e6aae72e1abb6039ea90b18a8e461813b51a84770e8fca3a6 |
|
MD5 | fb5c3bd57d2372a60d27ebe7ac174bee |
|
BLAKE2b-256 | a20606a44dae69ce2daeae983dff28952c4ec0f38f96a18d876763ca38839f8b |