Skip to content

Commit 3d12679

Browse files
feat(api): api update
1 parent d88ea55 commit 3d12679

41 files changed

Lines changed: 291 additions & 3055 deletions

Some content is hidden

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

.stats.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 9
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/nanonets%2Fdocstrange-f82f6b5e52eaf62639b7ae43348bbf66363cc95592391797a0ae297d3c7f738f.yml
3-
openapi_spec_hash: 02f7f52faae1eb42188c290c32c25f10
4-
config_hash: 52d207e1bd85f0522c9cae6ea8805784
1+
configured_endpoints: 2
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/nanonets%2Fdocstrange-00ea96039f73fd253b5042c3e5c1ae800ca6b3bbde585408d20a46f73ae87ecf.yml
3+
openapi_spec_hash: b4046d95714426b15edb8ac003f904c6
4+
config_hash: 6f0ab1fd6c4433590ee82d88ab5298a7

README.md

Lines changed: 9 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ client = Docstrange(
3333
)
3434

3535
extract_response = client.extract.sync(
36+
file=b"raw file contents",
3637
output_format="markdown",
3738
)
3839
print(extract_response.record_id)
@@ -59,6 +60,7 @@ client = AsyncDocstrange(
5960

6061
async def main() -> None:
6162
extract_response = await client.extract.sync(
63+
file=b"raw file contents",
6264
output_format="markdown",
6365
)
6466
print(extract_response.record_id)
@@ -95,6 +97,7 @@ async def main() -> None:
9597
http_client=DefaultAioHttpClient(),
9698
) as client:
9799
extract_response = await client.extract.sync(
100+
file=b"raw file contents",
98101
output_format="markdown",
99102
)
100103
print(extract_response.record_id)
@@ -112,67 +115,6 @@ Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typ
112115

113116
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`.
114117

115-
## Pagination
116-
117-
List methods in the Docstrange API are paginated.
118-
119-
This library provides auto-paginating iterators with each list response, so you do not have to request successive pages manually:
120-
121-
```python
122-
from docstrange import Docstrange
123-
124-
client = Docstrange()
125-
126-
all_results = []
127-
# Automatically fetches more pages as needed.
128-
for result in client.extract.results.list():
129-
# Do something with result here
130-
all_results.append(result)
131-
print(all_results)
132-
```
133-
134-
Or, asynchronously:
135-
136-
```python
137-
import asyncio
138-
from docstrange import AsyncDocstrange
139-
140-
client = AsyncDocstrange()
141-
142-
143-
async def main() -> None:
144-
all_results = []
145-
# Iterate through items across all pages, issuing requests as needed.
146-
async for result in client.extract.results.list():
147-
all_results.append(result)
148-
print(all_results)
149-
150-
151-
asyncio.run(main())
152-
```
153-
154-
Alternatively, you can use the `.has_next_page()`, `.next_page_info()`, or `.get_next_page()` methods for more granular control working with pages:
155-
156-
```python
157-
first_page = await client.extract.results.list()
158-
if first_page.has_next_page():
159-
print(f"will fetch next page using these details: {first_page.next_page_info()}")
160-
next_page = await first_page.get_next_page()
161-
print(f"number of items we just fetched: {len(next_page.results)}")
162-
163-
# Remove `await` for non-async usage.
164-
```
165-
166-
Or just work directly with the returned data:
167-
168-
```python
169-
first_page = await client.extract.results.list()
170-
for result in first_page.results:
171-
print(result.record_id)
172-
173-
# Remove `await` for non-async usage.
174-
```
175-
176118
## File uploads
177119

178120
Request parameters that correspond to file uploads can be passed as `bytes`, or a [`PathLike`](https://docs.python.org/3/library/os.html#os.PathLike) instance or a tuple of `(filename, contents, media type)`.
@@ -184,8 +126,8 @@ from docstrange import Docstrange
184126
client = Docstrange()
185127

186128
client.extract.sync(
187-
output_format="markdown",
188129
file=Path("/path/to/file"),
130+
output_format="output_format",
189131
)
190132
```
191133

@@ -208,6 +150,7 @@ client = Docstrange()
208150

209151
try:
210152
client.extract.sync(
153+
file=b"raw file contents",
211154
output_format="markdown",
212155
)
213156
except docstrange.APIConnectionError as e:
@@ -253,6 +196,7 @@ client = Docstrange(
253196

254197
# Or, configure per-request:
255198
client.with_options(max_retries=5).extract.sync(
199+
file=b"raw file contents",
256200
output_format="markdown",
257201
)
258202
```
@@ -278,6 +222,7 @@ client = Docstrange(
278222

279223
# Override per-request:
280224
client.with_options(timeout=5.0).extract.sync(
225+
file=b"raw file contents",
281226
output_format="markdown",
282227
)
283228
```
@@ -321,6 +266,7 @@ from docstrange import Docstrange
321266

322267
client = Docstrange()
323268
response = client.extract.with_raw_response.sync(
269+
file=b"raw file contents",
324270
output_format="markdown",
325271
)
326272
print(response.headers.get('X-My-Header'))
@@ -341,6 +287,7 @@ To stream the response body, use `.with_streaming_response` instead, which requi
341287

342288
```python
343289
with client.extract.with_streaming_response.sync(
290+
file=b"raw file contents",
344291
output_format="markdown",
345292
) as response:
346293
print(response.headers.get("X-My-Header"))

api.md

Lines changed: 3 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3,67 +3,21 @@
33
Types:
44

55
```python
6-
from docstrange.types import (
7-
BatchExtractRequestBody,
8-
BatchExtractResponse,
9-
ExtractRequestBody,
10-
ExtractResponse,
11-
ExtractionFormatResult,
12-
ExtractionMetadata,
13-
ExtractionResult,
14-
StreamExtractRequestBody,
15-
ExtractStreamResponse,
16-
)
6+
from docstrange.types import ExtractResponse
177
```
188

199
Methods:
2010

21-
- <code title="post /api/v1/extract/async">client.extract.<a href="./src/docstrange/resources/extract/extract.py">async\_</a>(\*\*<a href="src/docstrange/types/extract_async_params.py">params</a>) -> <a href="./src/docstrange/types/extract_response.py">ExtractResponse</a></code>
22-
- <code title="post /api/v1/extract/batch">client.extract.<a href="./src/docstrange/resources/extract/extract.py">batch</a>(\*\*<a href="src/docstrange/types/extract_batch_params.py">params</a>) -> <a href="./src/docstrange/types/batch_extract_response.py">BatchExtractResponse</a></code>
23-
- <code title="post /api/v1/extract/stream">client.extract.<a href="./src/docstrange/resources/extract/extract.py">stream</a>(\*\*<a href="src/docstrange/types/extract_stream_params.py">params</a>) -> str</code>
24-
- <code title="post /api/v1/extract/sync">client.extract.<a href="./src/docstrange/resources/extract/extract.py">sync</a>(\*\*<a href="src/docstrange/types/extract_sync_params.py">params</a>) -> <a href="./src/docstrange/types/extract_response.py">ExtractResponse</a></code>
25-
26-
## Results
27-
28-
Types:
29-
30-
```python
31-
from docstrange.types.extract import ExtractionListResponse, PaginationInfo
32-
```
33-
34-
Methods:
35-
36-
- <code title="get /api/v1/extract/results/{record_id}">client.extract.results.<a href="./src/docstrange/resources/extract/results.py">retrieve</a>(record_id, \*\*<a href="src/docstrange/types/extract/result_retrieve_params.py">params</a>) -> <a href="./src/docstrange/types/extract_response.py">ExtractResponse</a></code>
37-
- <code title="get /api/v1/extract/results">client.extract.results.<a href="./src/docstrange/resources/extract/results.py">list</a>(\*\*<a href="src/docstrange/types/extract/result_list_params.py">params</a>) -> <a href="./src/docstrange/types/extract_response.py">SyncPageNumberPagination[ExtractResponse]</a></code>
11+
- <code title="post /api/v1/extract/sync">client.extract.<a href="./src/docstrange/resources/extract.py">sync</a>(\*\*<a href="src/docstrange/types/extract_sync_params.py">params</a>) -> <a href="./src/docstrange/types/extract_response.py">ExtractResponse</a></code>
3812

3913
# Classify
4014

4115
Types:
4216

4317
```python
44-
from docstrange.types import (
45-
BatchClassifyRequestBody,
46-
BatchClassifyResponse,
47-
ClassifyRequestBody,
48-
ClassifyResponse,
49-
FileClassificationResult,
50-
PageClassification,
51-
)
18+
from docstrange.types import ClassifyResponse
5219
```
5320

5421
Methods:
5522

56-
- <code title="post /api/v1/classify/batch">client.classify.<a href="./src/docstrange/resources/classify.py">batch</a>(\*\*<a href="src/docstrange/types/classify_batch_params.py">params</a>) -> <a href="./src/docstrange/types/batch_classify_response.py">BatchClassifyResponse</a></code>
5723
- <code title="post /api/v1/classify/sync">client.classify.<a href="./src/docstrange/resources/classify.py">sync</a>(\*\*<a href="src/docstrange/types/classify_sync_params.py">params</a>) -> <a href="./src/docstrange/types/classify_response.py">ClassifyResponse</a></code>
58-
59-
# Chat
60-
61-
Types:
62-
63-
```python
64-
from docstrange.types import ChatCompletionsRequest
65-
```
66-
67-
Methods:
68-
69-
- <code title="post /v1/chat/completions">client.chat.<a href="./src/docstrange/resources/chat.py">create_completion</a>(\*\*<a href="src/docstrange/types/chat_create_completion_params.py">params</a>) -> object</code>

src/docstrange/_client.py

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@
3131
)
3232

3333
if TYPE_CHECKING:
34-
from .resources import chat, extract, classify
35-
from .resources.chat import ChatResource, AsyncChatResource
34+
from .resources import extract, classify
35+
from .resources.extract import ExtractResource, AsyncExtractResource
3636
from .resources.classify import ClassifyResource, AsyncClassifyResource
37-
from .resources.extract.extract import ExtractResource, AsyncExtractResource
3837

3938
__all__ = [
4039
"Timeout",
@@ -115,12 +114,6 @@ def classify(self) -> ClassifyResource:
115114

116115
return ClassifyResource(self)
117116

118-
@cached_property
119-
def chat(self) -> ChatResource:
120-
from .resources.chat import ChatResource
121-
122-
return ChatResource(self)
123-
124117
@cached_property
125118
def with_raw_response(self) -> DocstrangeWithRawResponse:
126119
return DocstrangeWithRawResponse(self)
@@ -301,12 +294,6 @@ def classify(self) -> AsyncClassifyResource:
301294

302295
return AsyncClassifyResource(self)
303296

304-
@cached_property
305-
def chat(self) -> AsyncChatResource:
306-
from .resources.chat import AsyncChatResource
307-
308-
return AsyncChatResource(self)
309-
310297
@cached_property
311298
def with_raw_response(self) -> AsyncDocstrangeWithRawResponse:
312299
return AsyncDocstrangeWithRawResponse(self)
@@ -438,12 +425,6 @@ def classify(self) -> classify.ClassifyResourceWithRawResponse:
438425

439426
return ClassifyResourceWithRawResponse(self._client.classify)
440427

441-
@cached_property
442-
def chat(self) -> chat.ChatResourceWithRawResponse:
443-
from .resources.chat import ChatResourceWithRawResponse
444-
445-
return ChatResourceWithRawResponse(self._client.chat)
446-
447428

448429
class AsyncDocstrangeWithRawResponse:
449430
_client: AsyncDocstrange
@@ -463,12 +444,6 @@ def classify(self) -> classify.AsyncClassifyResourceWithRawResponse:
463444

464445
return AsyncClassifyResourceWithRawResponse(self._client.classify)
465446

466-
@cached_property
467-
def chat(self) -> chat.AsyncChatResourceWithRawResponse:
468-
from .resources.chat import AsyncChatResourceWithRawResponse
469-
470-
return AsyncChatResourceWithRawResponse(self._client.chat)
471-
472447

473448
class DocstrangeWithStreamedResponse:
474449
_client: Docstrange
@@ -488,12 +463,6 @@ def classify(self) -> classify.ClassifyResourceWithStreamingResponse:
488463

489464
return ClassifyResourceWithStreamingResponse(self._client.classify)
490465

491-
@cached_property
492-
def chat(self) -> chat.ChatResourceWithStreamingResponse:
493-
from .resources.chat import ChatResourceWithStreamingResponse
494-
495-
return ChatResourceWithStreamingResponse(self._client.chat)
496-
497466

498467
class AsyncDocstrangeWithStreamedResponse:
499468
_client: AsyncDocstrange
@@ -513,12 +482,6 @@ def classify(self) -> classify.AsyncClassifyResourceWithStreamingResponse:
513482

514483
return AsyncClassifyResourceWithStreamingResponse(self._client.classify)
515484

516-
@cached_property
517-
def chat(self) -> chat.AsyncChatResourceWithStreamingResponse:
518-
from .resources.chat import AsyncChatResourceWithStreamingResponse
519-
520-
return AsyncChatResourceWithStreamingResponse(self._client.chat)
521-
522485

523486
Client = Docstrange
524487

src/docstrange/pagination.py

Lines changed: 0 additions & 67 deletions
This file was deleted.

0 commit comments

Comments
 (0)