Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "1.11.0"
".": "1.11.1"
}
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 7
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/landingai%2Fade-7247e8d6fb71965ebfc666fb0c1379394b2d7744be2bb304e30e04acfa8855f8.yml
openapi_spec_hash: 5511c4c03ee213ceaf68c9f9d889f861
config_hash: 2b7c8ce95f04ab9eea27533da72f6234
config_hash: 56c9f6570b7996559a642d8de67b400f
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 1.11.1 (2026-04-18)

Full Changelog: [v1.11.0...v1.11.1](https://github.com/landing-ai/ade-python/compare/v1.11.0...v1.11.1)

### Performance Improvements

* **client:** optimize file structure copying in multipart requests ([e78f8c0](https://github.com/landing-ai/ade-python/commit/e78f8c0604a7d59671998f02b7bb1832d8c09aa3))

## 1.11.0 (2026-04-13)

Full Changelog: [v1.10.0...v1.11.0](https://github.com/landing-ai/ade-python/compare/v1.10.0...v1.11.0)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "landingai-ade"
version = "1.11.0"
version = "1.11.1"
description = "The official Python library for the landingai-ade API"
dynamic = ["readme"]
license = "Apache-2.0"
Expand Down
42 changes: 25 additions & 17 deletions src/landingai_ade/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from . import _exceptions
from ._qs import Querystring
from .types import client_parse_params, client_split_params, client_extract_params, client_extract_build_schema_params
from ._files import deepcopy_with_paths
from ._types import (
Body,
Omit,
Expand All @@ -33,7 +34,6 @@
is_given,
extract_files,
maybe_transform,
deepcopy_minimal,
get_async_library,
async_maybe_transform,
)
Expand Down Expand Up @@ -348,14 +348,15 @@ def extract(
# Convert local file paths to file parameters
markdown, markdown_url = convert_url_to_file_if_local(markdown, markdown_url)

body = deepcopy_minimal(
body = deepcopy_with_paths(
{
"schema": schema,
"markdown": markdown,
"markdown_url": markdown_url,
"model": model,
"strict": strict,
}
},
[["markdown"]],
)
files = extract_files(cast(Mapping[str, object], body), paths=[["markdown"]])
# It should be noted that the actual Content-Type header that will be
Expand Down Expand Up @@ -430,14 +431,15 @@ def extract_build_schema(

timeout: Override the client-level default timeout for this request, in seconds
"""
body = deepcopy_minimal(
body = deepcopy_with_paths(
{
"markdown_urls": markdown_urls,
"markdowns": markdowns,
"model": model,
"prompt": prompt,
"schema": schema,
}
},
[["markdowns", "<array>"]],
)
files = extract_files(cast(Mapping[str, object], body), paths=[["markdowns", "<array>"]])
# It should be noted that the actual Content-Type header that will be
Expand Down Expand Up @@ -520,15 +522,16 @@ def parse(
# Convert local file paths to file parameters
document, document_url = convert_url_to_file_if_local(document, document_url)

body = deepcopy_minimal(
body = deepcopy_with_paths(
{
"custom_prompts": custom_prompts,
"document": document,
"document_url": document_url,
"model": model,
"password": password,
"split": split,
}
},
[["document"]],
)
files = extract_files(cast(Mapping[str, object], body), paths=[["document"]])
# It should be noted that the actual Content-Type header that will be
Expand Down Expand Up @@ -606,13 +609,14 @@ def split(
# Store original inputs for filename extraction
original_markdown = markdown
original_markdown_url = markdown_url
body = deepcopy_minimal(
body = deepcopy_with_paths(
{
"split_class": split_class,
"markdown": markdown,
"markdown_url": markdown_url,
"model": model,
}
},
[["markdown"]],
)
files = extract_files(cast(Mapping[str, object], body), paths=[["markdown"]])
# It should be noted that the actual Content-Type header that will be
Expand Down Expand Up @@ -885,14 +889,15 @@ async def extract(
# Convert local file paths to file parameters
markdown, markdown_url = convert_url_to_file_if_local(markdown, markdown_url)

body = deepcopy_minimal(
body = deepcopy_with_paths(
{
"schema": schema,
"markdown": markdown,
"markdown_url": markdown_url,
"model": model,
"strict": strict,
}
},
[["markdown"]],
)
files = extract_files(cast(Mapping[str, object], body), paths=[["markdown"]])
# It should be noted that the actual Content-Type header that will be
Expand Down Expand Up @@ -963,14 +968,15 @@ async def extract_build_schema(

timeout: Override the client-level default timeout for this request, in seconds
"""
body = deepcopy_minimal(
body = deepcopy_with_paths(
{
"markdown_urls": markdown_urls,
"markdowns": markdowns,
"model": model,
"prompt": prompt,
"schema": schema,
}
},
[["markdowns", "<array>"]],
)
files = extract_files(cast(Mapping[str, object], body), paths=[["markdowns", "<array>"]])
# It should be noted that the actual Content-Type header that will be
Expand Down Expand Up @@ -1045,15 +1051,16 @@ async def parse(
# Convert local file paths to file parameters
document, document_url = convert_url_to_file_if_local(document, document_url)

body = deepcopy_minimal(
body = deepcopy_with_paths(
{
"custom_prompts": custom_prompts,
"document": document,
"document_url": document_url,
"model": model,
"password": password,
"split": split,
}
},
[["document"]],
)
files = extract_files(cast(Mapping[str, object], body), paths=[["document"]])
# It should be noted that the actual Content-Type header that will be
Expand Down Expand Up @@ -1119,13 +1126,14 @@ async def split(

timeout: Override the client-level default timeout for this request, in seconds
"""
body = deepcopy_minimal(
body = deepcopy_with_paths(
{
"split_class": split_class,
"markdown": markdown,
"markdown_url": markdown_url,
"model": model,
}
},
[["markdown"]],
)
files = extract_files(cast(Mapping[str, object], body), paths=[["markdown"]])
# It should be noted that the actual Content-Type header that will be
Expand Down
56 changes: 53 additions & 3 deletions src/landingai_ade/_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import io
import os
import pathlib
from typing import overload
from typing_extensions import TypeGuard
from typing import Sequence, cast, overload
from typing_extensions import TypeVar, TypeGuard

import anyio

Expand All @@ -17,7 +17,9 @@
HttpxFileContent,
HttpxRequestFiles,
)
from ._utils import is_tuple_t, is_mapping_t, is_sequence_t
from ._utils import is_list, is_mapping, is_tuple_t, is_mapping_t, is_sequence_t

_T = TypeVar("_T")


def is_base64_file_input(obj: object) -> TypeGuard[Base64FileInput]:
Expand Down Expand Up @@ -132,3 +134,51 @@ async def async_read_file_content(file: FileContent) -> HttpxFileContent:
return file.encode('utf-8')

return file


def deepcopy_with_paths(item: _T, paths: Sequence[Sequence[str]]) -> _T:
"""Copy only the containers along the given paths.

Used to guard against mutation by extract_files without copying the entire structure.
Only dicts and lists that lie on a path are copied; everything else
is returned by reference.

For example, given paths=[["foo", "files", "file"]] and the structure:
{
"foo": {
"bar": {"baz": {}},
"files": {"file": <content>}
}
}
The root dict, "foo", and "files" are copied (they lie on the path).
"bar" and "baz" are returned by reference (off the path).
"""
return _deepcopy_with_paths(item, paths, 0)


def _deepcopy_with_paths(item: _T, paths: Sequence[Sequence[str]], index: int) -> _T:
if not paths:
return item
if is_mapping(item):
key_to_paths: dict[str, list[Sequence[str]]] = {}
for path in paths:
if index < len(path):
key_to_paths.setdefault(path[index], []).append(path)

# if no path continues through this mapping, it won't be mutated and copying it is redundant
if not key_to_paths:
return item

result = dict(item)
for key, subpaths in key_to_paths.items():
if key in result:
result[key] = _deepcopy_with_paths(result[key], subpaths, index + 1)
return cast(_T, result)
if is_list(item):
array_paths = [path for path in paths if index < len(path) and path[index] == "<array>"]

# if no path expects a list here, nothing will be mutated inside it - return by reference
if not array_paths:
return cast(_T, item)
return cast(_T, [_deepcopy_with_paths(entry, array_paths, index + 1) for entry in item])
return item
1 change: 0 additions & 1 deletion src/landingai_ade/_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
coerce_integer as coerce_integer,
file_from_path as file_from_path,
strip_not_given as strip_not_given,
deepcopy_minimal as deepcopy_minimal,
get_async_library as get_async_library,
maybe_coerce_float as maybe_coerce_float,
get_required_header as get_required_header,
Expand Down
15 changes: 0 additions & 15 deletions src/landingai_ade/_utils/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,21 +177,6 @@ def is_iterable(obj: object) -> TypeGuard[Iterable[object]]:
return isinstance(obj, Iterable)


def deepcopy_minimal(item: _T) -> _T:
"""Minimal reimplementation of copy.deepcopy() that will only copy certain object types:

- mappings, e.g. `dict`
- list

This is done for performance reasons.
"""
if is_mapping(item):
return cast(_T, {k: deepcopy_minimal(v) for k, v in item.items()})
if is_list(item):
return cast(_T, [deepcopy_minimal(entry) for entry in item])
return item


# copied from https://github.com/Rapptz/RoboDanny
def human_join(seq: Sequence[str], *, delim: str = ", ", final: str = "or") -> str:
size = len(seq)
Expand Down
2 changes: 1 addition & 1 deletion src/landingai_ade/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

__title__ = "landingai_ade"
__version__ = "1.11.0" # x-release-please-version
__version__ = "1.11.1" # x-release-please-version
13 changes: 8 additions & 5 deletions src/landingai_ade/resources/parse_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
import httpx

from ..types import parse_job_list_params, parse_job_create_params
from .._files import deepcopy_with_paths
from .._types import Body, Omit, Query, Headers, NotGiven, FileTypes, omit, not_given
from .._utils import extract_files, path_template, maybe_transform, deepcopy_minimal, async_maybe_transform
from .._utils import extract_files, path_template, maybe_transform, async_maybe_transform
from .._compat import cached_property
from .._resource import SyncAPIResource, AsyncAPIResource
from .._response import (
Expand Down Expand Up @@ -106,7 +107,7 @@ def create(

timeout: Override the client-level default timeout for this request, in seconds
"""
body = deepcopy_minimal(
body = deepcopy_with_paths(
{
"custom_prompts": custom_prompts,
"document": document,
Expand All @@ -115,7 +116,8 @@ def create(
"output_save_url": output_save_url,
"password": password,
"split": split,
}
},
[["document"]],
)
files = extract_files(cast(Mapping[str, object], body), paths=[["document"]])
# It should be noted that the actual Content-Type header that will be
Expand Down Expand Up @@ -304,7 +306,7 @@ async def create(

timeout: Override the client-level default timeout for this request, in seconds
"""
body = deepcopy_minimal(
body = deepcopy_with_paths(
{
"custom_prompts": custom_prompts,
"document": document,
Expand All @@ -313,7 +315,8 @@ async def create(
"output_save_url": output_save_url,
"password": password,
"split": split,
}
},
[["document"]],
)
files = extract_files(cast(Mapping[str, object], body), paths=[["document"]])
# It should be noted that the actual Content-Type header that will be
Expand Down
Loading