landingai-ade 0.14.1__py3-none-any.whl → 0.21.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
landingai_ade/_client.py CHANGED
@@ -41,6 +41,7 @@ from ._response import (
41
41
  async_to_raw_response_wrapper,
42
42
  async_to_streamed_response_wrapper,
43
43
  )
44
+ from .resources import parse_jobs
44
45
  from ._streaming import Stream as Stream, AsyncStream as AsyncStream
45
46
  from ._exceptions import APIStatusError, LandingAiadeError
46
47
  from ._base_client import (
@@ -74,6 +75,7 @@ ENVIRONMENTS: Dict[str, str] = {
74
75
 
75
76
 
76
77
  class LandingAIADE(SyncAPIClient):
78
+ parse_jobs: parse_jobs.ParseJobsResource
77
79
  with_raw_response: LandingAIADEWithRawResponse
78
80
  with_streaming_response: LandingAIADEWithStreamedResponse
79
81
 
@@ -155,6 +157,7 @@ class LandingAIADE(SyncAPIClient):
155
157
  _strict_response_validation=_strict_response_validation,
156
158
  )
157
159
 
160
+ self.parse_jobs = parse_jobs.ParseJobsResource(self)
158
161
  self.with_raw_response = LandingAIADEWithRawResponse(self)
159
162
  self.with_streaming_response = LandingAIADEWithStreamedResponse(self)
160
163
 
@@ -237,7 +240,7 @@ class LandingAIADE(SyncAPIClient):
237
240
  schema: str,
238
241
  markdown: Optional[FileTypes] | Omit = omit,
239
242
  markdown_url: Optional[str] | Omit = omit,
240
- model: Optional[Literal["extract-20250630", "extract-20250930"]] | Omit = omit,
243
+ model: Optional[str] | Omit = omit,
241
244
  # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
242
245
  # The extra values given here take precedence over values defined on the client or passed to this method.
243
246
  extra_headers: Headers | None = None,
@@ -264,7 +267,8 @@ class LandingAIADE(SyncAPIClient):
264
267
 
265
268
  markdown_url: The URL to the Markdown file to extract data from.
266
269
 
267
- model: The version of the model to use for extraction.
270
+ model: The version of the model to use for extraction. Use `extract-latest` to use the
271
+ latest version.
268
272
 
269
273
  extra_headers: Send extra headers
270
274
 
@@ -322,9 +326,10 @@ class LandingAIADE(SyncAPIClient):
322
326
  timeout: float | httpx.Timeout | None | NotGiven = not_given,
323
327
  ) -> ParseResponse:
324
328
  """
325
- Parse a document.
329
+ Parse a document or spreadsheet.
326
330
 
327
- This endpoint parses documents and structured Markdown, chunks, and metadata.
331
+ This endpoint parses documents (PDF, images) and spreadsheets (XLSX, CSV) into
332
+ structured Markdown, chunks, and metadata.
328
333
 
329
334
  For EU users, use this endpoint:
330
335
 
@@ -421,6 +426,7 @@ class LandingAIADE(SyncAPIClient):
421
426
 
422
427
 
423
428
  class AsyncLandingAIADE(AsyncAPIClient):
429
+ parse_jobs: parse_jobs.AsyncParseJobsResource
424
430
  with_raw_response: AsyncLandingAIADEWithRawResponse
425
431
  with_streaming_response: AsyncLandingAIADEWithStreamedResponse
426
432
 
@@ -502,6 +508,7 @@ class AsyncLandingAIADE(AsyncAPIClient):
502
508
  _strict_response_validation=_strict_response_validation,
503
509
  )
504
510
 
511
+ self.parse_jobs = parse_jobs.AsyncParseJobsResource(self)
505
512
  self.with_raw_response = AsyncLandingAIADEWithRawResponse(self)
506
513
  self.with_streaming_response = AsyncLandingAIADEWithStreamedResponse(self)
507
514
 
@@ -584,7 +591,7 @@ class AsyncLandingAIADE(AsyncAPIClient):
584
591
  schema: str,
585
592
  markdown: Optional[FileTypes] | Omit = omit,
586
593
  markdown_url: Optional[str] | Omit = omit,
587
- model: Optional[Literal["extract-20250630", "extract-20250930"]] | Omit = omit,
594
+ model: Optional[str] | Omit = omit,
588
595
  # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
589
596
  # The extra values given here take precedence over values defined on the client or passed to this method.
590
597
  extra_headers: Headers | None = None,
@@ -611,7 +618,8 @@ class AsyncLandingAIADE(AsyncAPIClient):
611
618
 
612
619
  markdown_url: The URL to the Markdown file to extract data from.
613
620
 
614
- model: The version of the model to use for extraction.
621
+ model: The version of the model to use for extraction. Use `extract-latest` to use the
622
+ latest version.
615
623
 
616
624
  extra_headers: Send extra headers
617
625
 
@@ -669,9 +677,10 @@ class AsyncLandingAIADE(AsyncAPIClient):
669
677
  timeout: float | httpx.Timeout | None | NotGiven = not_given,
670
678
  ) -> ParseResponse:
671
679
  """
672
- Parse a document.
680
+ Parse a document or spreadsheet.
673
681
 
674
- This endpoint parses documents and structured Markdown, chunks, and metadata.
682
+ This endpoint parses documents (PDF, images) and spreadsheets (XLSX, CSV) into
683
+ structured Markdown, chunks, and metadata.
675
684
 
676
685
  For EU users, use this endpoint:
677
686
 
@@ -769,6 +778,8 @@ class AsyncLandingAIADE(AsyncAPIClient):
769
778
 
770
779
  class LandingAIADEWithRawResponse:
771
780
  def __init__(self, client: LandingAIADE) -> None:
781
+ self.parse_jobs = parse_jobs.ParseJobsResourceWithRawResponse(client.parse_jobs)
782
+
772
783
  self.extract = to_raw_response_wrapper(
773
784
  client.extract,
774
785
  )
@@ -779,6 +790,8 @@ class LandingAIADEWithRawResponse:
779
790
 
780
791
  class AsyncLandingAIADEWithRawResponse:
781
792
  def __init__(self, client: AsyncLandingAIADE) -> None:
793
+ self.parse_jobs = parse_jobs.AsyncParseJobsResourceWithRawResponse(client.parse_jobs)
794
+
782
795
  self.extract = async_to_raw_response_wrapper(
783
796
  client.extract,
784
797
  )
@@ -789,6 +802,8 @@ class AsyncLandingAIADEWithRawResponse:
789
802
 
790
803
  class LandingAIADEWithStreamedResponse:
791
804
  def __init__(self, client: LandingAIADE) -> None:
805
+ self.parse_jobs = parse_jobs.ParseJobsResourceWithStreamingResponse(client.parse_jobs)
806
+
792
807
  self.extract = to_streamed_response_wrapper(
793
808
  client.extract,
794
809
  )
@@ -799,6 +814,8 @@ class LandingAIADEWithStreamedResponse:
799
814
 
800
815
  class AsyncLandingAIADEWithStreamedResponse:
801
816
  def __init__(self, client: AsyncLandingAIADE) -> None:
817
+ self.parse_jobs = parse_jobs.AsyncParseJobsResourceWithStreamingResponse(client.parse_jobs)
818
+
802
819
  self.extract = async_to_streamed_response_wrapper(
803
820
  client.extract,
804
821
  )
@@ -5,8 +5,8 @@ import httpx
5
5
  RAW_RESPONSE_HEADER = "X-Stainless-Raw-Response"
6
6
  OVERRIDE_CAST_TO_HEADER = "____stainless_override_cast_to"
7
7
 
8
- # default timeout is 1 minute
9
- DEFAULT_TIMEOUT = httpx.Timeout(timeout=60, connect=5.0)
8
+ # default timeout is 8 minutes
9
+ DEFAULT_TIMEOUT = httpx.Timeout(timeout=480, connect=5.0)
10
10
  DEFAULT_MAX_RETRIES = 2
11
11
  DEFAULT_CONNECTION_LIMITS = httpx.Limits(max_connections=100, max_keepalive_connections=20)
12
12
 
landingai_ade/_files.py CHANGED
@@ -26,7 +26,7 @@ def is_base64_file_input(obj: object) -> TypeGuard[Base64FileInput]:
26
26
 
27
27
  def is_file_content(obj: object) -> TypeGuard[FileContent]:
28
28
  return (
29
- isinstance(obj, bytes) or isinstance(obj, tuple) or isinstance(obj, io.IOBase) or isinstance(obj, os.PathLike)
29
+ isinstance(obj, bytes) or isinstance(obj, str) or isinstance(obj, tuple) or isinstance(obj, io.IOBase) or isinstance(obj, os.PathLike)
30
30
  )
31
31
 
32
32
 
@@ -66,6 +66,9 @@ def _transform_file(file: FileTypes) -> HttpxFileTypes:
66
66
  path = pathlib.Path(file)
67
67
  return (path.name, path.read_bytes())
68
68
 
69
+ if isinstance(file, str):
70
+ return file.encode('utf-8')
71
+
69
72
  return file
70
73
 
71
74
  if is_tuple_t(file):
@@ -77,6 +80,8 @@ def _transform_file(file: FileTypes) -> HttpxFileTypes:
77
80
  def read_file_content(file: FileContent) -> HttpxFileContent:
78
81
  if isinstance(file, os.PathLike):
79
82
  return pathlib.Path(file).read_bytes()
83
+ if isinstance(file, str):
84
+ return file.encode('utf-8')
80
85
  return file
81
86
 
82
87
 
@@ -108,6 +113,9 @@ async def _async_transform_file(file: FileTypes) -> HttpxFileTypes:
108
113
  path = anyio.Path(file)
109
114
  return (path.name, await path.read_bytes())
110
115
 
116
+ if isinstance(file, str):
117
+ return file.encode('utf-8')
118
+
111
119
  return file
112
120
 
113
121
  if is_tuple_t(file):
@@ -120,4 +128,7 @@ async def async_read_file_content(file: FileContent) -> HttpxFileContent:
120
128
  if isinstance(file, os.PathLike):
121
129
  return await anyio.Path(file).read_bytes()
122
130
 
131
+ if isinstance(file, str):
132
+ return file.encode('utf-8')
133
+
123
134
  return file
landingai_ade/_models.py CHANGED
@@ -2,6 +2,7 @@ from __future__ import annotations
2
2
 
3
3
  import os
4
4
  import inspect
5
+ import weakref
5
6
  from typing import TYPE_CHECKING, Any, Type, Union, Generic, TypeVar, Callable, Optional, cast
6
7
  from datetime import date, datetime
7
8
  from typing_extensions import (
@@ -573,6 +574,9 @@ class CachedDiscriminatorType(Protocol):
573
574
  __discriminator__: DiscriminatorDetails
574
575
 
575
576
 
577
+ DISCRIMINATOR_CACHE: weakref.WeakKeyDictionary[type, DiscriminatorDetails] = weakref.WeakKeyDictionary()
578
+
579
+
576
580
  class DiscriminatorDetails:
577
581
  field_name: str
578
582
  """The name of the discriminator field in the variant class, e.g.
@@ -615,8 +619,9 @@ class DiscriminatorDetails:
615
619
 
616
620
 
617
621
  def _build_discriminated_union_meta(*, union: type, meta_annotations: tuple[Any, ...]) -> DiscriminatorDetails | None:
618
- if isinstance(union, CachedDiscriminatorType):
619
- return union.__discriminator__
622
+ cached = DISCRIMINATOR_CACHE.get(union)
623
+ if cached is not None:
624
+ return cached
620
625
 
621
626
  discriminator_field_name: str | None = None
622
627
 
@@ -669,7 +674,7 @@ def _build_discriminated_union_meta(*, union: type, meta_annotations: tuple[Any,
669
674
  discriminator_field=discriminator_field_name,
670
675
  discriminator_alias=discriminator_alias,
671
676
  )
672
- cast(CachedDiscriminatorType, union).__discriminator__ = details
677
+ DISCRIMINATOR_CACHE.setdefault(union, details)
673
678
  return details
674
679
 
675
680
 
@@ -57,9 +57,8 @@ class Stream(Generic[_T]):
57
57
  for sse in iterator:
58
58
  yield process_data(data=sse.json(), cast_to=cast_to, response=response)
59
59
 
60
- # Ensure the entire stream is consumed
61
- for _sse in iterator:
62
- ...
60
+ # As we might not fully consume the response stream, we need to close it explicitly
61
+ response.close()
63
62
 
64
63
  def __enter__(self) -> Self:
65
64
  return self
@@ -121,9 +120,8 @@ class AsyncStream(Generic[_T]):
121
120
  async for sse in iterator:
122
121
  yield process_data(data=sse.json(), cast_to=cast_to, response=response)
123
122
 
124
- # Ensure the entire stream is consumed
125
- async for _sse in iterator:
126
- ...
123
+ # As we might not fully consume the response stream, we need to close it explicitly
124
+ await response.aclose()
127
125
 
128
126
  async def __aenter__(self) -> Self:
129
127
  return self
landingai_ade/_types.py CHANGED
@@ -52,10 +52,10 @@ ProxiesDict = Dict["str | URL", Union[None, str, URL, Proxy]]
52
52
  ProxiesTypes = Union[str, Proxy, ProxiesDict]
53
53
  if TYPE_CHECKING:
54
54
  Base64FileInput = Union[IO[bytes], PathLike[str]]
55
- FileContent = Union[IO[bytes], bytes, PathLike[str]]
55
+ FileContent = Union[IO[bytes], bytes, str, PathLike[str]]
56
56
  else:
57
57
  Base64FileInput = Union[IO[bytes], PathLike]
58
- FileContent = Union[IO[bytes], bytes, PathLike] # PathLike is not subscriptable in Python 3.8.
58
+ FileContent = Union[IO[bytes], bytes, str, PathLike] # PathLike is not subscriptable in Python 3.8.
59
59
  FileTypes = Union[
60
60
  # file (or bytes)
61
61
  FileContent,
@@ -1,10 +1,8 @@
1
1
  from __future__ import annotations
2
2
 
3
- import sys
4
3
  import asyncio
5
4
  import functools
6
- import contextvars
7
- from typing import Any, TypeVar, Callable, Awaitable
5
+ from typing import TypeVar, Callable, Awaitable
8
6
  from typing_extensions import ParamSpec
9
7
 
10
8
  import anyio
@@ -15,34 +13,11 @@ T_Retval = TypeVar("T_Retval")
15
13
  T_ParamSpec = ParamSpec("T_ParamSpec")
16
14
 
17
15
 
18
- if sys.version_info >= (3, 9):
19
- _asyncio_to_thread = asyncio.to_thread
20
- else:
21
- # backport of https://docs.python.org/3/library/asyncio-task.html#asyncio.to_thread
22
- # for Python 3.8 support
23
- async def _asyncio_to_thread(
24
- func: Callable[T_ParamSpec, T_Retval], /, *args: T_ParamSpec.args, **kwargs: T_ParamSpec.kwargs
25
- ) -> Any:
26
- """Asynchronously run function *func* in a separate thread.
27
-
28
- Any *args and **kwargs supplied for this function are directly passed
29
- to *func*. Also, the current :class:`contextvars.Context` is propagated,
30
- allowing context variables from the main thread to be accessed in the
31
- separate thread.
32
-
33
- Returns a coroutine that can be awaited to get the eventual result of *func*.
34
- """
35
- loop = asyncio.events.get_running_loop()
36
- ctx = contextvars.copy_context()
37
- func_call = functools.partial(ctx.run, func, *args, **kwargs)
38
- return await loop.run_in_executor(None, func_call)
39
-
40
-
41
16
  async def to_thread(
42
17
  func: Callable[T_ParamSpec, T_Retval], /, *args: T_ParamSpec.args, **kwargs: T_ParamSpec.kwargs
43
18
  ) -> T_Retval:
44
19
  if sniffio.current_async_library() == "asyncio":
45
- return await _asyncio_to_thread(func, *args, **kwargs)
20
+ return await asyncio.to_thread(func, *args, **kwargs)
46
21
 
47
22
  return await anyio.to_thread.run_sync(
48
23
  functools.partial(func, *args, **kwargs),
@@ -53,10 +28,7 @@ async def to_thread(
53
28
  def asyncify(function: Callable[T_ParamSpec, T_Retval]) -> Callable[T_ParamSpec, Awaitable[T_Retval]]:
54
29
  """
55
30
  Take a blocking function and create an async one that receives the same
56
- positional and keyword arguments. For python version 3.9 and above, it uses
57
- asyncio.to_thread to run the function in a separate thread. For python version
58
- 3.8, it uses locally defined copy of the asyncio.to_thread function which was
59
- introduced in python 3.9.
31
+ positional and keyword arguments.
60
32
 
61
33
  Usage:
62
34
 
@@ -133,7 +133,7 @@ def is_given(obj: _T | NotGiven | Omit) -> TypeGuard[_T]:
133
133
  # Type safe methods for narrowing types with TypeVars.
134
134
  # The default narrowing for isinstance(obj, dict) is dict[unknown, unknown],
135
135
  # however this cause Pyright to rightfully report errors. As we know we don't
136
- # care about the contained types we can safely use `object` in it's place.
136
+ # care about the contained types we can safely use `object` in its place.
137
137
  #
138
138
  # There are two separate functions defined, `is_*` and `is_*_t` for different use cases.
139
139
  # `is_*` is for when you're dealing with an unknown input
landingai_ade/_version.py CHANGED
@@ -1,4 +1,4 @@
1
1
  # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
 
3
3
  __title__ = "landingai_ade"
4
- __version__ = "0.14.1" # x-release-please-version
4
+ __version__ = "0.21.1" # x-release-please-version
@@ -1 +1,19 @@
1
1
  # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ from .parse_jobs import (
4
+ ParseJobsResource,
5
+ AsyncParseJobsResource,
6
+ ParseJobsResourceWithRawResponse,
7
+ AsyncParseJobsResourceWithRawResponse,
8
+ ParseJobsResourceWithStreamingResponse,
9
+ AsyncParseJobsResourceWithStreamingResponse,
10
+ )
11
+
12
+ __all__ = [
13
+ "ParseJobsResource",
14
+ "AsyncParseJobsResource",
15
+ "ParseJobsResourceWithRawResponse",
16
+ "AsyncParseJobsResourceWithRawResponse",
17
+ "ParseJobsResourceWithStreamingResponse",
18
+ "AsyncParseJobsResourceWithStreamingResponse",
19
+ ]