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 @@
{
".": "0.21.0"
".": "0.21.1"
}
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# Changelog

## 0.21.1 (2026-04-18)

Full Changelog: [v0.21.0...v0.21.1](https://github.com/isaacus-dev/isaacus-python/compare/v0.21.0...v0.21.1)

### Bug Fixes

* **client:** preserve hardcoded query params when merging with user params ([1e99aa4](https://github.com/isaacus-dev/isaacus-python/commit/1e99aa438e488d81e2e37ad5ea41a48e7b60f1eb))
* ensure file data are only sent as 1 parameter ([32dab0e](https://github.com/isaacus-dev/isaacus-python/commit/32dab0e1abc9f4f5ea0446cb8bb17c9ee2b55b7a))


### Performance Improvements

* **client:** optimize file structure copying in multipart requests ([3f32843](https://github.com/isaacus-dev/isaacus-python/commit/3f32843f81d5115e1c495cc42fdd095ff99f3822))


### Documentation

* update examples ([4186943](https://github.com/isaacus-dev/isaacus-python/commit/4186943a4a7c4571c7ee2a097bd1715ec074e5dd))

## 0.21.0 (2026-03-27)

Full Changelog: [v0.20.0...v0.21.0](https://github.com/isaacus-dev/isaacus-python/compare/v0.20.0...v0.21.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 = "isaacus"
version = "0.21.0"
version = "0.21.1"
description = "The official Python library for the isaacus API"
dynamic = ["readme"]
license = "Apache-2.0"
Expand Down
4 changes: 4 additions & 0 deletions src/isaacus/_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,10 @@ def _build_request(
files = cast(HttpxRequestFiles, ForceMultipartDict())

prepared_url = self._prepare_url(options.url)
# preserve hard-coded query params from the url
if params and prepared_url.query:
params = {**dict(prepared_url.params.items()), **params}
prepared_url = prepared_url.copy_with(raw_path=prepared_url.raw_path.split(b"?", 1)[0])
if "_" in prepared_url.host:
# work around https://github.com/encode/httpx/discussions/2880
kwargs["extensions"] = {"sni_hostname": prepared_url.host.replace("_", "-")}
Expand Down
56 changes: 53 additions & 3 deletions src/isaacus/_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 @@ -121,3 +123,51 @@ async def async_read_file_content(file: FileContent) -> HttpxFileContent:
return await anyio.Path(file).read_bytes()

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/isaacus/_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
20 changes: 3 additions & 17 deletions src/isaacus/_utils/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ def _extract_items(
index += 1
if is_dict(obj):
try:
# We are at the last entry in the path so we must remove the field
if (len(path)) == index:
# Remove the field if there are no more dict keys in the path,
# only "<array>" traversal markers or end.
if all(p == "<array>" for p in path[index:]):
item = obj.pop(key)
else:
item = obj[key]
Expand Down Expand Up @@ -176,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/isaacus/_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__ = "isaacus"
__version__ = "0.21.0" # x-release-please-version
__version__ = "0.21.1" # x-release-please-version
8 changes: 4 additions & 4 deletions tests/api_resources/classifications/test_universal.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def test_method_create_with_all_params(self, client: Isaacus) -> None:
scoring_method="auto",
chunking_options={
"size": 512,
"overlap_ratio": 0.1,
"overlap_tokens": 10,
"overlap_ratio": None,
"overlap_tokens": None,
},
)
assert_matches_type(UniversalClassificationResponse, universal, path=["response"])
Expand Down Expand Up @@ -101,8 +101,8 @@ async def test_method_create_with_all_params(self, async_client: AsyncIsaacus) -
scoring_method="auto",
chunking_options={
"size": 512,
"overlap_ratio": 0.1,
"overlap_tokens": 10,
"overlap_ratio": None,
"overlap_tokens": None,
},
)
assert_matches_type(UniversalClassificationResponse, universal, path=["response"])
Expand Down
12 changes: 6 additions & 6 deletions tests/api_resources/extractions/test_qa.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ def test_method_create_with_all_params(self, client: Isaacus) -> None:
ignore_inextractability=False,
top_k=1,
chunking_options={
"size": 512,
"overlap_ratio": 0.1,
"overlap_tokens": 10,
"size": None,
"overlap_ratio": None,
"overlap_tokens": None,
},
)
assert_matches_type(AnswerExtractionResponse, qa, path=["response"])
Expand Down Expand Up @@ -112,9 +112,9 @@ async def test_method_create_with_all_params(self, async_client: AsyncIsaacus) -
ignore_inextractability=False,
top_k=1,
chunking_options={
"size": 512,
"overlap_ratio": 0.1,
"overlap_tokens": 10,
"size": None,
"overlap_ratio": None,
"overlap_tokens": None,
},
)
assert_matches_type(AnswerExtractionResponse, qa, path=["response"])
Expand Down
4 changes: 2 additions & 2 deletions tests/api_resources/test_embeddings.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_method_create_with_all_params(self, client: Isaacus) -> None:
texts=["Are restraints of trade enforceable under English law?", "What is a non-compete clause?"],
task="retrieval/query",
overflow_strategy="drop_end",
dimensions=1,
dimensions=1792,
)
assert_matches_type(EmbeddingResponse, embedding, path=["response"])

Expand Down Expand Up @@ -89,7 +89,7 @@ async def test_method_create_with_all_params(self, async_client: AsyncIsaacus) -
texts=["Are restraints of trade enforceable under English law?", "What is a non-compete clause?"],
task="retrieval/query",
overflow_strategy="drop_end",
dimensions=1,
dimensions=1792,
)
assert_matches_type(EmbeddingResponse, embedding, path=["response"])

Expand Down
32 changes: 24 additions & 8 deletions tests/api_resources/test_enrichments.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ class TestEnrichments:
def test_method_create(self, client: Isaacus) -> None:
enrichment = client.enrichments.create(
model="kanon-2-enricher",
texts=['1.5 You (the "User") agree to be bound by these Terms.'],
texts=[
'[42] The U.S. Attorney General, Mr. McGill, argued at ¶ 21 of the Filing that "§ 206 of Title 29 of the U.S. Code (the "Labor Title") does not apply to the plaintiff, Ms. Moody, given the definition of an "employee" at §203(e)(4) of the Labor Title does not include volunteers, and, regardless, she lives in Austria."'
],
)
assert_matches_type(EnrichmentResponse, enrichment, path=["response"])

Expand All @@ -31,7 +33,9 @@ def test_method_create(self, client: Isaacus) -> None:
def test_method_create_with_all_params(self, client: Isaacus) -> None:
enrichment = client.enrichments.create(
model="kanon-2-enricher",
texts=['1.5 You (the "User") agree to be bound by these Terms.'],
texts=[
'[42] The U.S. Attorney General, Mr. McGill, argued at ¶ 21 of the Filing that "§ 206 of Title 29 of the U.S. Code (the "Labor Title") does not apply to the plaintiff, Ms. Moody, given the definition of an "employee" at §203(e)(4) of the Labor Title does not include volunteers, and, regardless, she lives in Austria."'
],
overflow_strategy="auto",
)
assert_matches_type(EnrichmentResponse, enrichment, path=["response"])
Expand All @@ -41,7 +45,9 @@ def test_method_create_with_all_params(self, client: Isaacus) -> None:
def test_raw_response_create(self, client: Isaacus) -> None:
response = client.enrichments.with_raw_response.create(
model="kanon-2-enricher",
texts=['1.5 You (the "User") agree to be bound by these Terms.'],
texts=[
'[42] The U.S. Attorney General, Mr. McGill, argued at ¶ 21 of the Filing that "§ 206 of Title 29 of the U.S. Code (the "Labor Title") does not apply to the plaintiff, Ms. Moody, given the definition of an "employee" at §203(e)(4) of the Labor Title does not include volunteers, and, regardless, she lives in Austria."'
],
)

assert response.is_closed is True
Expand All @@ -54,7 +60,9 @@ def test_raw_response_create(self, client: Isaacus) -> None:
def test_streaming_response_create(self, client: Isaacus) -> None:
with client.enrichments.with_streaming_response.create(
model="kanon-2-enricher",
texts=['1.5 You (the "User") agree to be bound by these Terms.'],
texts=[
'[42] The U.S. Attorney General, Mr. McGill, argued at ¶ 21 of the Filing that "§ 206 of Title 29 of the U.S. Code (the "Labor Title") does not apply to the plaintiff, Ms. Moody, given the definition of an "employee" at §203(e)(4) of the Labor Title does not include volunteers, and, regardless, she lives in Austria."'
],
) as response:
assert not response.is_closed
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
Expand All @@ -75,7 +83,9 @@ class TestAsyncEnrichments:
async def test_method_create(self, async_client: AsyncIsaacus) -> None:
enrichment = await async_client.enrichments.create(
model="kanon-2-enricher",
texts=['1.5 You (the "User") agree to be bound by these Terms.'],
texts=[
'[42] The U.S. Attorney General, Mr. McGill, argued at ¶ 21 of the Filing that "§ 206 of Title 29 of the U.S. Code (the "Labor Title") does not apply to the plaintiff, Ms. Moody, given the definition of an "employee" at §203(e)(4) of the Labor Title does not include volunteers, and, regardless, she lives in Austria."'
],
)
assert_matches_type(EnrichmentResponse, enrichment, path=["response"])

Expand All @@ -84,7 +94,9 @@ async def test_method_create(self, async_client: AsyncIsaacus) -> None:
async def test_method_create_with_all_params(self, async_client: AsyncIsaacus) -> None:
enrichment = await async_client.enrichments.create(
model="kanon-2-enricher",
texts=['1.5 You (the "User") agree to be bound by these Terms.'],
texts=[
'[42] The U.S. Attorney General, Mr. McGill, argued at ¶ 21 of the Filing that "§ 206 of Title 29 of the U.S. Code (the "Labor Title") does not apply to the plaintiff, Ms. Moody, given the definition of an "employee" at §203(e)(4) of the Labor Title does not include volunteers, and, regardless, she lives in Austria."'
],
overflow_strategy="auto",
)
assert_matches_type(EnrichmentResponse, enrichment, path=["response"])
Expand All @@ -94,7 +106,9 @@ async def test_method_create_with_all_params(self, async_client: AsyncIsaacus) -
async def test_raw_response_create(self, async_client: AsyncIsaacus) -> None:
response = await async_client.enrichments.with_raw_response.create(
model="kanon-2-enricher",
texts=['1.5 You (the "User") agree to be bound by these Terms.'],
texts=[
'[42] The U.S. Attorney General, Mr. McGill, argued at ¶ 21 of the Filing that "§ 206 of Title 29 of the U.S. Code (the "Labor Title") does not apply to the plaintiff, Ms. Moody, given the definition of an "employee" at §203(e)(4) of the Labor Title does not include volunteers, and, regardless, she lives in Austria."'
],
)

assert response.is_closed is True
Expand All @@ -107,7 +121,9 @@ async def test_raw_response_create(self, async_client: AsyncIsaacus) -> None:
async def test_streaming_response_create(self, async_client: AsyncIsaacus) -> None:
async with async_client.enrichments.with_streaming_response.create(
model="kanon-2-enricher",
texts=['1.5 You (the "User") agree to be bound by these Terms.'],
texts=[
'[42] The U.S. Attorney General, Mr. McGill, argued at ¶ 21 of the Filing that "§ 206 of Title 29 of the U.S. Code (the "Labor Title") does not apply to the plaintiff, Ms. Moody, given the definition of an "employee" at §203(e)(4) of the Labor Title does not include volunteers, and, regardless, she lives in Austria."'
],
) as response:
assert not response.is_closed
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
Expand Down
16 changes: 8 additions & 8 deletions tests/api_resources/test_rerankings.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ def test_method_create_with_all_params(self, client: Isaacus) -> None:
"Negligence in tort law requires establishing a duty of care that the defendant owed to the plaintiff.",
"The concept of negligence is central to tort law, with courts assessing whether a breach of duty caused harm.",
],
top_n=1,
top_n=None,
is_iql=False,
scoring_method="auto",
chunking_options={
"size": 512,
"overlap_ratio": 0.1,
"overlap_tokens": 10,
"size": None,
"overlap_ratio": None,
"overlap_tokens": None,
},
)
assert_matches_type(RerankingResponse, reranking, path=["response"])
Expand Down Expand Up @@ -134,13 +134,13 @@ async def test_method_create_with_all_params(self, async_client: AsyncIsaacus) -
"Negligence in tort law requires establishing a duty of care that the defendant owed to the plaintiff.",
"The concept of negligence is central to tort law, with courts assessing whether a breach of duty caused harm.",
],
top_n=1,
top_n=None,
is_iql=False,
scoring_method="auto",
chunking_options={
"size": 512,
"overlap_ratio": 0.1,
"overlap_tokens": 10,
"size": None,
"overlap_ratio": None,
"overlap_tokens": None,
},
)
assert_matches_type(RerankingResponse, reranking, path=["response"])
Expand Down
Loading
Loading