Skip to content

Commit 3d1cde0

Browse files
feat(api): update via SDK Studio
1 parent 6cb72bf commit 3d1cde0

File tree

149 files changed

+1525
-217
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

149 files changed

+1525
-217
lines changed

.stats.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
configured_endpoints: 30
1+
configured_endpoints: 33
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/contextual-ai%2Fsunrise-017875f5f67473ff4fe764239419149714a7941e4e670101078926b06414ea8d.yml

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ $ pip install -r requirements-dev.lock
3737

3838
Most of the SDK is generated code. Modifications to code will be persisted between generations, but may
3939
result in merge conflicts between manual patches and changes from the generator. The generator will never
40-
modify the contents of the `src/contextual/lib/` and `examples/` directories.
40+
modify the contents of the `src/contextual_sdk/lib/` and `examples/` directories.
4141

4242
## Adding and running examples
4343

README.md

+84-21
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Contextual AI Python API library
22

3-
[![PyPI version](https://img.shields.io/pypi/v/contextual.svg)](https://pypi.org/project/contextual/)
3+
[![PyPI version](https://img.shields.io/pypi/v/contextual-sdk.svg)](https://pypi.org/project/contextual-sdk/)
44

55
The Contextual AI Python library provides convenient access to the Contextual AI REST API from any Python 3.8+
66
application. The library includes type definitions for all request params and response fields,
@@ -20,15 +20,15 @@ pip install git+ssh://git@github.com/stainless-sdks/sunrise-python.git
2020
```
2121

2222
> [!NOTE]
23-
> Once this package is [published to PyPI](https://app.stainlessapi.com/docs/guides/publish), this will become: `pip install --pre contextual`
23+
> Once this package is [published to PyPI](https://app.stainlessapi.com/docs/guides/publish), this will become: `pip install --pre contextual-sdk`
2424
2525
## Usage
2626

2727
The full API of this library can be found in [api.md](api.md).
2828

2929
```python
3030
import os
31-
from contextual import ContextualAI
31+
from contextual_sdk import ContextualAI
3232

3333
client = ContextualAI(
3434
api_key=os.environ.get("CONTEXTUAL_API_KEY"), # This is the default and can be omitted
@@ -52,7 +52,7 @@ Simply import `AsyncContextualAI` instead of `ContextualAI` and use `await` with
5252
```python
5353
import os
5454
import asyncio
55-
from contextual import AsyncContextualAI
55+
from contextual_sdk import AsyncContextualAI
5656

5757
client = AsyncContextualAI(
5858
api_key=os.environ.get("CONTEXTUAL_API_KEY"), # This is the default and can be omitted
@@ -80,31 +80,94 @@ Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typ
8080

8181
Typed requests and responses provide autocomplete and documentation within your editor. If you would like to see type errors in VS Code to help catch bugs earlier, set `python.analysis.typeCheckingMode` to `basic`.
8282

83+
## Pagination
84+
85+
List methods in the Contextual AI API are paginated.
86+
87+
This library provides auto-paginating iterators with each list response, so you do not have to request successive pages manually:
88+
89+
```python
90+
from contextual_sdk import ContextualAI
91+
92+
client = ContextualAI()
93+
94+
all_datastores = []
95+
# Automatically fetches more pages as needed.
96+
for datastore in client.datastores.list():
97+
# Do something with datastore here
98+
all_datastores.append(datastore)
99+
print(all_datastores)
100+
```
101+
102+
Or, asynchronously:
103+
104+
```python
105+
import asyncio
106+
from contextual_sdk import AsyncContextualAI
107+
108+
client = AsyncContextualAI()
109+
110+
111+
async def main() -> None:
112+
all_datastores = []
113+
# Iterate through items across all pages, issuing requests as needed.
114+
async for datastore in client.datastores.list():
115+
all_datastores.append(datastore)
116+
print(all_datastores)
117+
118+
119+
asyncio.run(main())
120+
```
121+
122+
Alternatively, you can use the `.has_next_page()`, `.next_page_info()`, or `.get_next_page()` methods for more granular control working with pages:
123+
124+
```python
125+
first_page = await client.datastores.list()
126+
if first_page.has_next_page():
127+
print(f"will fetch next page using these details: {first_page.next_page_info()}")
128+
next_page = await first_page.get_next_page()
129+
print(f"number of items we just fetched: {len(next_page.datastores)}")
130+
131+
# Remove `await` for non-async usage.
132+
```
133+
134+
Or just work directly with the returned data:
135+
136+
```python
137+
first_page = await client.datastores.list()
138+
139+
print(f"next page cursor: {first_page.next_cursor}") # => "next page cursor: ..."
140+
for datastore in first_page.datastores:
141+
print(datastore.id)
142+
143+
# Remove `await` for non-async usage.
144+
```
145+
83146
## Handling errors
84147

85-
When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of `contextual.APIConnectionError` is raised.
148+
When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of `contextual_sdk.APIConnectionError` is raised.
86149

87150
When the API returns a non-success status code (that is, 4xx or 5xx
88-
response), a subclass of `contextual.APIStatusError` is raised, containing `status_code` and `response` properties.
151+
response), a subclass of `contextual_sdk.APIStatusError` is raised, containing `status_code` and `response` properties.
89152

90-
All errors inherit from `contextual.APIError`.
153+
All errors inherit from `contextual_sdk.APIError`.
91154

92155
```python
93-
import contextual
94-
from contextual import ContextualAI
156+
import contextual_sdk
157+
from contextual_sdk import ContextualAI
95158

96159
client = ContextualAI()
97160

98161
try:
99162
client.datastores.create(
100163
name="name",
101164
)
102-
except contextual.APIConnectionError as e:
165+
except contextual_sdk.APIConnectionError as e:
103166
print("The server could not be reached")
104167
print(e.__cause__) # an underlying Exception, likely raised within httpx.
105-
except contextual.RateLimitError as e:
168+
except contextual_sdk.RateLimitError as e:
106169
print("A 429 status code was received; we should back off a bit.")
107-
except contextual.APIStatusError as e:
170+
except contextual_sdk.APIStatusError as e:
108171
print("Another non-200-range status code was received")
109172
print(e.status_code)
110173
print(e.response)
@@ -132,7 +195,7 @@ Connection errors (for example, due to a network connectivity problem), 408 Requ
132195
You can use the `max_retries` option to configure or disable retry settings:
133196

134197
```python
135-
from contextual import ContextualAI
198+
from contextual_sdk import ContextualAI
136199

137200
# Configure the default for all requests:
138201
client = ContextualAI(
@@ -152,7 +215,7 @@ By default requests time out after 1 minute. You can configure this with a `time
152215
which accepts a float or an [`httpx.Timeout`](https://www.python-httpx.org/advanced/#fine-tuning-the-configuration) object:
153216

154217
```python
155-
from contextual import ContextualAI
218+
from contextual_sdk import ContextualAI
156219

157220
# Configure the default for all requests:
158221
client = ContextualAI(
@@ -206,7 +269,7 @@ if response.my_field is None:
206269
The "raw" Response object can be accessed by prefixing `.with_raw_response.` to any HTTP method call, e.g.,
207270

208271
```py
209-
from contextual import ContextualAI
272+
from contextual_sdk import ContextualAI
210273

211274
client = ContextualAI()
212275
response = client.datastores.with_raw_response.create(
@@ -218,9 +281,9 @@ datastore = response.parse() # get the object that `datastores.create()` would
218281
print(datastore.id)
219282
```
220283

221-
These methods return an [`APIResponse`](https://github.com/stainless-sdks/sunrise-python/tree/main/src/contextual/_response.py) object.
284+
These methods return an [`APIResponse`](https://github.com/stainless-sdks/sunrise-python/tree/main/src/contextual_sdk/_response.py) object.
222285

223-
The async client returns an [`AsyncAPIResponse`](https://github.com/stainless-sdks/sunrise-python/tree/main/src/contextual/_response.py) with the same structure, the only difference being `await`able methods for reading the response content.
286+
The async client returns an [`AsyncAPIResponse`](https://github.com/stainless-sdks/sunrise-python/tree/main/src/contextual_sdk/_response.py) with the same structure, the only difference being `await`able methods for reading the response content.
224287

225288
#### `.with_streaming_response`
226289

@@ -285,7 +348,7 @@ You can directly override the [httpx client](https://www.python-httpx.org/api/#c
285348

286349
```python
287350
import httpx
288-
from contextual import ContextualAI, DefaultHttpxClient
351+
from contextual_sdk import ContextualAI, DefaultHttpxClient
289352

290353
client = ContextualAI(
291354
# Or use the `CONTEXTUAL_AI_BASE_URL` env var
@@ -308,7 +371,7 @@ client.with_options(http_client=DefaultHttpxClient(...))
308371
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.
309372

310373
```py
311-
from contextual import ContextualAI
374+
from contextual_sdk import ContextualAI
312375

313376
with ContextualAI() as client:
314377
# make requests here
@@ -336,8 +399,8 @@ If you've upgraded to the latest version but aren't seeing any new features you
336399
You can determine the version that is being used at runtime with:
337400

338401
```py
339-
import contextual
340-
print(contextual.__version__)
402+
import contextual_sdk
403+
print(contextual_sdk.__version__)
341404
```
342405

343406
## Requirements

0 commit comments

Comments
 (0)