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 Opencode Python library provides convenient access to the Opencode REST API from any Python 3.8+
6
6
application. The library includes type definitions for all request params and response fields,
@@ -16,15 +16,15 @@ The REST API documentation can be found on [opencode.ai](https://opencode.ai/doc
16
16
17
17
```sh
18
18
# install from PyPI
19
-
pip install --pre opencode
19
+
pip install --pre opencode-ai
20
20
```
21
21
22
22
## Usage
23
23
24
24
The full API of this library can be found in [api.md](api.md).
25
25
26
26
```python
27
-
fromopencodeimport Opencode
27
+
fromopencode_aiimport Opencode
28
28
29
29
client = Opencode()
30
30
@@ -37,7 +37,7 @@ Simply import `AsyncOpencode` instead of `Opencode` and use `await` with each AP
37
37
38
38
```python
39
39
import asyncio
40
-
fromopencodeimport AsyncOpencode
40
+
fromopencode_aiimport AsyncOpencode
41
41
42
42
client = AsyncOpencode()
43
43
@@ -59,15 +59,15 @@ You can enable this by installing `aiohttp`:
59
59
60
60
```sh
61
61
# install from PyPI
62
-
pip install --pre opencode[aiohttp]
62
+
pip install --pre opencode-ai[aiohttp]
63
63
```
64
64
65
65
Then you can enable it by instantiating the client with `http_client=DefaultAioHttpClient()`:
66
66
67
67
```python
68
68
import asyncio
69
-
fromopencodeimport DefaultAioHttpClient
70
-
fromopencodeimport AsyncOpencode
69
+
fromopencode_aiimport DefaultAioHttpClient
70
+
fromopencode_aiimport AsyncOpencode
71
71
72
72
73
73
asyncdefmain() -> None:
@@ -91,27 +91,27 @@ Typed requests and responses provide autocomplete and documentation within your
91
91
92
92
## Handling errors
93
93
94
-
When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of `opencode.APIConnectionError` is raised.
94
+
When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of `opencode_ai.APIConnectionError` is raised.
95
95
96
96
When the API returns a non-success status code (that is, 4xx or 5xx
97
-
response), a subclass of `opencode.APIStatusError` is raised, containing `status_code` and `response` properties.
97
+
response), a subclass of `opencode_ai.APIStatusError` is raised, containing `status_code` and `response` properties.
98
98
99
-
All errors inherit from `opencode.APIError`.
99
+
All errors inherit from `opencode_ai.APIError`.
100
100
101
101
```python
102
-
importopencode
103
-
fromopencodeimport Opencode
102
+
importopencode_ai
103
+
fromopencode_aiimport Opencode
104
104
105
105
client = Opencode()
106
106
107
107
try:
108
108
client.event.list()
109
-
exceptopencode.APIConnectionError as e:
109
+
exceptopencode_ai.APIConnectionError as e:
110
110
print("The server could not be reached")
111
111
print(e.__cause__) # an underlying Exception, likely raised within httpx.
112
-
exceptopencode.RateLimitError as e:
112
+
exceptopencode_ai.RateLimitError as e:
113
113
print("A 429 status code was received; we should back off a bit.")
114
-
exceptopencode.APIStatusError as e:
114
+
exceptopencode_ai.APIStatusError as e:
115
115
print("Another non-200-range status code was received")
116
116
print(e.status_code)
117
117
print(e.response)
@@ -139,7 +139,7 @@ Connection errors (for example, due to a network connectivity problem), 408 Requ
139
139
You can use the `max_retries` option to configure or disable retry settings:
140
140
141
141
```python
142
-
fromopencodeimport Opencode
142
+
fromopencode_aiimport Opencode
143
143
144
144
# Configure the default for all requests:
145
145
client = Opencode(
@@ -157,7 +157,7 @@ By default requests time out after 1 minute. You can configure this with a `time
157
157
which accepts a float or an [`httpx.Timeout`](https://www.python-httpx.org/advanced/timeouts/#fine-tuning-the-configuration) object:
158
158
159
159
```python
160
-
fromopencodeimport Opencode
160
+
fromopencode_aiimport Opencode
161
161
162
162
# Configure the default for all requests:
163
163
client = Opencode(
@@ -209,7 +209,7 @@ if response.my_field is None:
209
209
The "raw" Response object can be accessed by prefixing `.with_raw_response.` to any HTTP method call, e.g.,
210
210
211
211
```py
212
-
fromopencodeimport Opencode
212
+
fromopencode_aiimport Opencode
213
213
214
214
client = Opencode()
215
215
response = client.event.with_raw_response.list()
@@ -219,9 +219,9 @@ event = response.parse() # get the object that `event.list()` would have return
219
219
print(event)
220
220
```
221
221
222
-
These methods return an [`APIResponse`](https://github.com/sst/opencode-sdk-python/tree/main/src/opencode/_response.py) object.
222
+
These methods return an [`APIResponse`](https://github.com/sst/opencode-sdk-python/tree/main/src/opencode_ai/_response.py) object.
223
223
224
-
The async client returns an [`AsyncAPIResponse`](https://github.com/sst/opencode-sdk-python/tree/main/src/opencode/_response.py) with the same structure, the only difference being `await`able methods for reading the response content.
224
+
The async client returns an [`AsyncAPIResponse`](https://github.com/sst/opencode-sdk-python/tree/main/src/opencode_ai/_response.py) with the same structure, the only difference being `await`able methods for reading the response content.
225
225
226
226
#### `.with_streaming_response`
227
227
@@ -283,7 +283,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.
307
307
308
308
```py
309
-
fromopencodeimport Opencode
309
+
fromopencode_aiimport Opencode
310
310
311
311
with Opencode() as client:
312
312
# make requests here
@@ -334,8 +334,8 @@ If you've upgraded to the latest version but aren't seeing any new features you
334
334
You can determine the version that is being used at runtime with:
0 commit comments