Package: aiocloudflare
Inspired by the officalpython-cloudflarelibrary developed byCloudflare. This project is created to be compatible withasynciofor non-blocking IO.For sync code, it is recommanded to usepython-cloudflareviapip installpython-cloudflareas it is used by hundreds and offically maintained by Cloudflare. This ensure that APIs are always updated according to Cloudflare API release.NOTE:This library is in Beta, this means fixes and updates are still going on every second. Do not use it in Production unless you have tested on the API route specific to your use case and that would be at your own risk.Having said that, do submit an issue if you encounter any bug so we can move away from the Alpha stage sooner.Featuresasync http API call using modern http libraryhttpx.Autocompletion on IDE.Fully type hinted.Feature Roadmapto support cert tokento support sync API clientThese are some alternative use cases that are not in the top of my priority now as I have not received
any request for. If you are interested, you may want to submit a pull request to contribute some of these features.RequirementsPython3.9+InstallationYou can installaiocloudflareviapipfromPyPI:$pipinstallaiocloudflareUsagefromaiocloudflareimportCloudflareasyncdefget_zone():asyncwithCloudflare()ascf:response=awaitcf.zones.get()Unlike the officalpython-cloudflarelibrary,aiocloudflaredoes not parse and handle http responses.So the awaited response object will have to be handled just as any http request, response pattern. theResponseobject is the same ashttpx’sResponse.fromaiocloudflareimportCloudflareasyncdefget_zone():asyncwithCloudflare()ascf:response=awaitcf.zones.get()# check status codeifresponse.status_code==200:# get json dataresp_json=response.json()# Cloudflare API typically store results in a ``result`` key.returnresp_json["result"]else:# to get texture data from responseprint(response.text)Full configuration can be done usingConfig()class.fromaioCloudflareimportCloudflare,Configconfig=Config(email="your@email.com",token="<secret>")# for demo only, do not hardcode secretsasyncdefget_zone():asyncwithCloudflare(config=config)ascf:result=awaitcf.zones.get()Configuration can also be stored in a.envfile for a “global” configuration without needing to create aConfig()class. Keys available are:CF_API_EMAIL=""
CF_API_KEY=""
CF_API_CERTKEY=""
CF_API_URL=""
DEBUG=false
CF_PROFILE=""
USER_AGENT=""Advance UsageYou may wish to wrapCloudflare()into you own class for customised settings or requirements. To do that, just provide a__aenter__()and__aexit__()method to your class like so.classMyCfClient:def__init__(self):self._config=Config(email="your@email.com",token="<secret>")# for demo only, do not hardcode secretsasyncdef__aenter__(self):self._client=Cloudflare(config=self._config)returnselfasyncdef__aexit__(self,exc_type,exc_value,traceback):awaitself._client.aclose()Then you can call your own class with async context manager.asyncwithMyCfClient()asown_class:awaitown_class.zones.get()ContributingContributions are very welcome.
To learn more, see theContributor Guide.LicenseDistributed under the terms of theMIT license,aioCloudflareis free and open source software.IssuesIf you encounter any problems,
pleasefile an issuealong with a detailed description.