Package: cloudflare-api
Python client for Cloudflare API v4Require Python 3.9+UsagePython Packagepipinstallcloudflare-apiSample code can be found inside/test.pySource Codegitclonehttps://github.com/nikhiljohn10/cloudflare-apicdcloudflare-apiInstructions to get new API TokenGo toDashboardCreate TokenUseEdit Cloudflare WorkerstemplateSelect one account fromAccount ResourcesSelectAll Zonesor specific zones underZone ResourcesContinue to summaryCreate TokenCopy the token and save it somewhere secret & secure.Then run the following command in terminal:makeinit
.venv/bin/activate
maketestIf it is running for first time, you will be asked to enter API Token. Paste the api token copied from Dashboard.ExampleFor this example,poetryis used for easy setup.python3-mpipinstall--userpoetry
mkdir-pmyapp&&cdmyapp
poetryinit-n
poetryaddcloudflare-apiCopy the code below in to a new file./myapp/app.py.#!/usr/bin/env python3fromCloudflareAPIimportCloudflaredefmain():cf=Cloudflare()print(cf.account.list())print(cf.user.details())print(cf.worker.list())print(cf.store.list())if__name__=="__main__":main()You can now run the program using following command:poetryrunpythonapp.pyIf it is running for first time, you will be asked to enter API Token. Paste the api token copied from Dashboard. This will createcf-config.inifile in your current working directory for future reference of the api token.You can find more examples inexamplesdirectoryDefault Permissions1. AccountWorkers Tail ( Read )Workers KV Storage ( Edit )Workers Scripts ( Edit )Account Settings ( Read )2. ZonesWorkers Routes ( Edit )3. UsersUser Details ( Read )Available endpointsAccountlist- 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 accountAccountDataAccountSettingsUserdetails- Display details of the account's userUserDataWorkerlist- List all existing workersupload- Upload a new worker with binding if givenUpload file along as javascriptUpload file along with metadata as multipart form-dataKV BindingsEnvironment variablesSecretsdownload- Download an existing workerdeploy- Deploy an existing worker using the subdomainundeploy- Undeploy an existing workerdelete- Delete an existing workerSubdomaincreate- Create a new subdomain if none existsget- Get the current subdomain from cloudflare accountCronupdate- Update an existing cron or create new cron for a workerget- Get the cron task list of specified workerStore(Workers KV)list- List all existing Namespacesget_ns- Returns requested Namespace objectcreate- Create a new namespacerename- Rename an existing namespacedelete- Delete an existing namespaceNamespacekeys- Display all the keys in the Namespaceread- Read the value of given key in the Namespacewrite- Write given key-value pair to the Namespacebulk_write- Write given key-value pairs in bulk to the Namespacedelete- Delete given key from the Namespacebulk_delete- Delete given keys in bulk from the NamespaceMetadataNSKeyNSBundleradd- Add key-value pair with metadata to bundler( * : Not accessable with default Worker permissions )DevelopmentVersion BumpTo display current version:make versionTo bump to new version, where x.y.z is major,minor & patch versions respectively:make VERSION=x.y.z bumpThe above command does the following:Update version in__version__.pyinside packageCreate a commit for the above changeTag the commit with VERSIONPush the content in to main branch with tagsPython publish workflow action activatesRelease the version pushedBuild python packagePublish python package in to pypi.org