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
The Keycard API Python library provides convenient access to the Keycard API REST API from any Python 3.9+
7
7
application. The library includes type definitions for all request params and response fields,
@@ -17,15 +17,15 @@ The REST API documentation can be found on [docs.keycard.ai](https://docs.keycar
17
17
18
18
```sh
19
19
# install from PyPI
20
-
pip install keycard_api
20
+
pip install keycardai-api
21
21
```
22
22
23
23
## Usage
24
24
25
25
The full API of this library can be found in [api.md](api.md).
26
26
27
27
```python
28
-
fromkeycard_apiimport KeycardAPI
28
+
fromkeycardai_apiimport KeycardAPI
29
29
30
30
client = KeycardAPI()
31
31
@@ -44,7 +44,7 @@ Simply import `AsyncKeycardAPI` instead of `KeycardAPI` and use `await` with eac
44
44
45
45
```python
46
46
import asyncio
47
-
fromkeycard_apiimport AsyncKeycardAPI
47
+
fromkeycardai_apiimport AsyncKeycardAPI
48
48
49
49
client = AsyncKeycardAPI()
50
50
@@ -67,15 +67,15 @@ You can enable this by installing `aiohttp`:
67
67
68
68
```sh
69
69
# install from PyPI
70
-
pip install keycard_api[aiohttp]
70
+
pip install keycardai-api[aiohttp]
71
71
```
72
72
73
73
Then you can enable it by instantiating the client with `http_client=DefaultAioHttpClient()`:
74
74
75
75
```python
76
76
import asyncio
77
-
fromkeycard_apiimport DefaultAioHttpClient
78
-
fromkeycard_apiimport AsyncKeycardAPI
77
+
fromkeycardai_apiimport DefaultAioHttpClient
78
+
fromkeycardai_apiimport AsyncKeycardAPI
79
79
80
80
81
81
asyncdefmain() -> None:
@@ -103,7 +103,7 @@ Typed requests and responses provide autocomplete and documentation within your
103
103
Nested parameters are dictionaries, typed using `TypedDict`, for example:
104
104
105
105
```python
106
-
fromkeycard_apiimport KeycardAPI
106
+
fromkeycardai_apiimport KeycardAPI
107
107
108
108
client = KeycardAPI()
109
109
@@ -119,27 +119,27 @@ print(zone.encryption_key)
119
119
120
120
## Handling errors
121
121
122
-
When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of `keycard_api.APIConnectionError` is raised.
122
+
When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of `keycardai_api.APIConnectionError` is raised.
123
123
124
124
When the API returns a non-success status code (that is, 4xx or 5xx
125
-
response), a subclass of `keycard_api.APIStatusError` is raised, containing `status_code` and `response` properties.
125
+
response), a subclass of `keycardai_api.APIStatusError` is raised, containing `status_code` and `response` properties.
126
126
127
-
All errors inherit from `keycard_api.APIError`.
127
+
All errors inherit from `keycardai_api.APIError`.
128
128
129
129
```python
130
-
importkeycard_api
131
-
fromkeycard_apiimport KeycardAPI
130
+
importkeycardai_api
131
+
fromkeycardai_apiimport KeycardAPI
132
132
133
133
client = KeycardAPI()
134
134
135
135
try:
136
136
client.zones.list()
137
-
exceptkeycard_api.APIConnectionError as e:
137
+
exceptkeycardai_api.APIConnectionError as e:
138
138
print("The server could not be reached")
139
139
print(e.__cause__) # an underlying Exception, likely raised within httpx.
140
-
exceptkeycard_api.RateLimitError as e:
140
+
exceptkeycardai_api.RateLimitError as e:
141
141
print("A 429 status code was received; we should back off a bit.")
142
-
exceptkeycard_api.APIStatusError as e:
142
+
exceptkeycardai_api.APIStatusError as e:
143
143
print("Another non-200-range status code was received")
144
144
print(e.status_code)
145
145
print(e.response)
@@ -167,7 +167,7 @@ Connection errors (for example, due to a network connectivity problem), 408 Requ
167
167
You can use the `max_retries` option to configure or disable retry settings:
168
168
169
169
```python
170
-
fromkeycard_apiimport KeycardAPI
170
+
fromkeycardai_apiimport KeycardAPI
171
171
172
172
# Configure the default for all requests:
173
173
client = KeycardAPI(
@@ -185,7 +185,7 @@ By default requests time out after 1 minute. You can configure this with a `time
185
185
which accepts a float or an [`httpx.Timeout`](https://www.python-httpx.org/advanced/timeouts/#fine-tuning-the-configuration) object:
186
186
187
187
```python
188
-
fromkeycard_apiimport KeycardAPI
188
+
fromkeycardai_apiimport KeycardAPI
189
189
190
190
# Configure the default for all requests:
191
191
client = KeycardAPI(
@@ -237,7 +237,7 @@ if response.my_field is None:
237
237
The "raw" Response object can be accessed by prefixing `.with_raw_response.` to any HTTP method call, e.g.,
238
238
239
239
```py
240
-
fromkeycard_apiimport KeycardAPI
240
+
fromkeycardai_apiimport KeycardAPI
241
241
242
242
client = KeycardAPI()
243
243
response = client.zones.with_raw_response.list()
@@ -247,9 +247,9 @@ zone = response.parse() # get the object that `zones.list()` would have returne
247
247
print(zone.items)
248
248
```
249
249
250
-
These methods return an [`APIResponse`](https://github.com/keycardlabs/keycard-python/tree/main/src/keycard_api/_response.py) object.
250
+
These methods return an [`APIResponse`](https://github.com/keycardlabs/keycard-python/tree/main/src/keycardai_api/_response.py) object.
251
251
252
-
The async client returns an [`AsyncAPIResponse`](https://github.com/keycardlabs/keycard-python/tree/main/src/keycard_api/_response.py) with the same structure, the only difference being `await`able methods for reading the response content.
252
+
The async client returns an [`AsyncAPIResponse`](https://github.com/keycardlabs/keycard-python/tree/main/src/keycardai_api/_response.py) with the same structure, the only difference being `await`able methods for reading the response content.
253
253
254
254
#### `.with_streaming_response`
255
255
@@ -311,7 +311,7 @@ You can directly override the [httpx client](https://www.python-httpx.org/api/#c
By default the library closes underlying HTTP connections whenever the client is [garbage collected](https://docs.python.org/3/reference/datamodel.html#object.__del__). You can manually close the client using the `.close()` method if desired, or with a context manager that closes when exiting.
335
335
336
336
```py
337
-
fromkeycard_apiimport KeycardAPI
337
+
fromkeycardai_apiimport KeycardAPI
338
338
339
339
with KeycardAPI() as client:
340
340
# make requests here
@@ -362,8 +362,8 @@ If you've upgraded to the latest version but aren't seeing any new features you
362
362
You can determine the version that is being used at runtime with:
0 commit comments