You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jun 29, 2022. It is now read-only.
Inspired by the offical `python-cloudflare` library developed by `Cloudflare`_. This project is created to be competible to use with `asyncio` for non-blocking IO.
40
+
Inspired by the offical ``python-cloudflare`` library developed by `Cloudflare`_. This project is created to be compatible with ``asyncio`` for non-blocking IO.
36
41
37
-
For sync code, it is recommanded to use `python-cloudflare` via `pip install python-cloudflare` as it is used by hundreds and offically maintained by cloudflare. This ensure that APIs are always updated according to Cloudflare API release.
42
+
For sync code, it is recommanded to use ``python-cloudflare`` via ``pip install python-cloudflare`` as it is used by hundreds and offically maintained by Cloudflare. This ensure that APIs are always updated according to Cloudflare API release.
38
43
39
-
*NOTE:* This library is in Pre-Alpha, this means things might break. 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.
44
+
*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.
40
45
41
46
Having said that, do submit an issue if you encounter any bug so we can move away from the Alpha stage sooner.
42
47
@@ -47,6 +52,15 @@ Features
47
52
* Autocompletion on IDE.
48
53
* Fully type hinted.
49
54
55
+
Feature Roadmap
56
+
---------------
57
+
58
+
* to support cert token
59
+
* to support sync API client
60
+
61
+
These are some alternative use cases that are not in the top of my priority now as I have not received
62
+
any request for. If you are interested, you may want to submit a pull request to contribute some of these features.
63
+
50
64
51
65
Requirements
52
66
------------
@@ -73,19 +87,82 @@ Usage
73
87
74
88
asyncdefget_zone():
75
89
asyncwith Cloudflare() as cf:
76
-
result =await cf.zones.get()
90
+
response =await cf.zones.get()
91
+
92
+
Unlike the offical ``python-cloudflare`` library, ``aiocloudflare`` does not parse and handle http responses.
93
+
94
+
So the awaited response object will have to be handled just as any http request, response pattern. the ``Response`` object is the same as ``httpx``'s ``Response``.
95
+
96
+
.. code:: Python
97
+
98
+
from aiocloudflare import Cloudflare
99
+
100
+
asyncdefget_zone():
101
+
asyncwith Cloudflare() as cf:
102
+
response =await cf.zones.get()
103
+
104
+
# check status code
105
+
if response.status_code ==200:
106
+
107
+
# get json data
108
+
resp_json = response.json()
109
+
110
+
# Cloudflare API typically store results in a ``result`` key.
111
+
return resp_json["result"]
77
112
78
-
Full configuration can be done using `Config()` class.
113
+
else:
114
+
# to get texture data from response
115
+
print(response.text)
116
+
117
+
118
+
Full configuration can be done using ``Config()`` class.
config = Config(email="[email protected]", token="<secret>")# for demo only, do not hardcode secrets
85
125
asyncdefget_zone():
86
126
asyncwith Cloudflare(config=config) as cf:
87
127
result =await cf.zones.get()
88
128
129
+
Configuration can also be stored in a ``.env`` file for a "global" configuration without needing to create a ``Config()`` class. Keys available are:
130
+
131
+
.. code:: console
132
+
133
+
CF_API_EMAIL=""
134
+
CF_API_KEY=""
135
+
CF_API_CERTKEY=""
136
+
CF_API_URL=""
137
+
DEBUG=false
138
+
CF_PROFILE=""
139
+
USER_AGENT=""
140
+
141
+
Advance Usage
142
+
_____________
143
+
144
+
You may wish to wrap ``Cloudflare()`` into you own class for customised settings or requirements. To do that, just provide a ``__aenter__()`` and ``__aexit__()`` method to your class like so.
145
+
146
+
.. code:: Python
147
+
148
+
classMyCfClient:
149
+
def__init__(self):
150
+
self._config = Config(email="[email protected]", token="<secret>") # for demo only, do not hardcode secrets
0 commit comments