diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 2aca35a..4208b5c 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.5.0" + ".": "0.6.0" } \ No newline at end of file diff --git a/.stats.yml b/.stats.yml index 259052d..601b377 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 34 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/linq%2Flinq-api-v3-0fe30cdf449f22baad8404374d9bc484831e210d9ff09ffbd3bc8669029a868c.yml -openapi_spec_hash: abf0ae319f3847e6e97c9241f4e2348f +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/linq%2Flinq-api-v3-37a94929911f4b5944524a51b722bb0eea0b0b167fd79814181f58ed877aa341.yml +openapi_spec_hash: 795bd7e48e4d2affc5943c57ee111d52 config_hash: 3ab31decde29ec61e02db7dcb5313f82 diff --git a/CHANGELOG.md b/CHANGELOG.md index fc7573b..ca07fb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +## 0.6.0 (2026-04-28) + +Full Changelog: [v0.5.0...v0.6.0](https://github.com/linq-team/linq-python/compare/v0.5.0...v0.6.0) + +### Features + +* support setting headers via env ([d4398f4](https://github.com/linq-team/linq-python/commit/d4398f434cc4a920f59625eee7be9f1cdef8725b)) + + +### Bug Fixes + +* **openapi:** enforce mutual exclusivity constraints on reaction and voice memo schemas ([e057279](https://github.com/linq-team/linq-python/commit/e05727975ba84c6a022bd8e8d7a9d212cd864082)) +* use correct field name format for multipart file arrays ([0e992dc](https://github.com/linq-team/linq-python/commit/0e992dc83b80f05698e9cc3d2e656f6ca890576a)) + ## 0.5.0 (2026-04-26) Full Changelog: [v0.4.1...v0.5.0](https://github.com/linq-team/linq-python/compare/v0.4.1...v0.5.0) diff --git a/pyproject.toml b/pyproject.toml index f384d2b..c9e0630 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "linq-python" -version = "0.5.0" +version = "0.6.0" description = "The official Python library for the linq-api-v3 API" dynamic = ["readme"] license = "Apache-2.0" diff --git a/src/linq/_client.py b/src/linq/_client.py index 04a786c..b334b6b 100644 --- a/src/linq/_client.py +++ b/src/linq/_client.py @@ -19,7 +19,11 @@ RequestOptions, not_given, ) -from ._utils import is_given, get_async_library +from ._utils import ( + is_given, + is_mapping_t, + get_async_library, +) from ._compat import cached_property from ._models import SecurityOptions from ._version import __version__ @@ -110,6 +114,15 @@ def __init__( if base_url is None: base_url = f"https://api.linqapp.com/api/partner" + custom_headers_env = os.environ.get("LINQ_API_V3_CUSTOM_HEADERS") + if custom_headers_env is not None: + parsed: dict[str, str] = {} + for line in custom_headers_env.split("\n"): + colon = line.find(":") + if colon >= 0: + parsed[line[:colon].strip()] = line[colon + 1 :].strip() + default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})} + super().__init__( version=__version__, base_url=base_url, @@ -626,6 +639,15 @@ def __init__( if base_url is None: base_url = f"https://api.linqapp.com/api/partner" + custom_headers_env = os.environ.get("LINQ_API_V3_CUSTOM_HEADERS") + if custom_headers_env is not None: + parsed: dict[str, str] = {} + for line in custom_headers_env.split("\n"): + colon = line.find(":") + if colon >= 0: + parsed[line[:colon].strip()] = line[colon + 1 :].strip() + default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})} + super().__init__( version=__version__, base_url=base_url, diff --git a/src/linq/_qs.py b/src/linq/_qs.py index de8c99b..4127c19 100644 --- a/src/linq/_qs.py +++ b/src/linq/_qs.py @@ -2,17 +2,13 @@ from typing import Any, List, Tuple, Union, Mapping, TypeVar from urllib.parse import parse_qs, urlencode -from typing_extensions import Literal, get_args +from typing_extensions import get_args -from ._types import NotGiven, not_given +from ._types import NotGiven, ArrayFormat, NestedFormat, not_given from ._utils import flatten _T = TypeVar("_T") - -ArrayFormat = Literal["comma", "repeat", "indices", "brackets"] -NestedFormat = Literal["dots", "brackets"] - PrimitiveData = Union[str, int, float, bool, None] # this should be Data = Union[PrimitiveData, "List[Data]", "Tuple[Data]", "Mapping[str, Data]"] # https://github.com/microsoft/pyright/issues/3555 diff --git a/src/linq/_types.py b/src/linq/_types.py index bf2aca2..9da8ad0 100644 --- a/src/linq/_types.py +++ b/src/linq/_types.py @@ -47,6 +47,9 @@ ModelT = TypeVar("ModelT", bound=pydantic.BaseModel) _T = TypeVar("_T") +ArrayFormat = Literal["comma", "repeat", "indices", "brackets"] +NestedFormat = Literal["dots", "brackets"] + # Approximates httpx internal ProxiesTypes and RequestFiles types # while adding support for `PathLike` instances diff --git a/src/linq/_utils/_utils.py b/src/linq/_utils/_utils.py index 771859f..199cd23 100644 --- a/src/linq/_utils/_utils.py +++ b/src/linq/_utils/_utils.py @@ -17,11 +17,11 @@ ) from pathlib import Path from datetime import date, datetime -from typing_extensions import TypeGuard +from typing_extensions import TypeGuard, get_args import sniffio -from .._types import Omit, NotGiven, FileTypes, HeadersLike +from .._types import Omit, NotGiven, FileTypes, ArrayFormat, HeadersLike _T = TypeVar("_T") _TupleT = TypeVar("_TupleT", bound=Tuple[object, ...]) @@ -40,25 +40,45 @@ def extract_files( query: Mapping[str, object], *, paths: Sequence[Sequence[str]], + array_format: ArrayFormat = "brackets", ) -> list[tuple[str, FileTypes]]: """Recursively extract files from the given dictionary based on specified paths. A path may look like this ['foo', 'files', '', 'data']. + ``array_format`` controls how ```` segments contribute to the emitted + field name. Supported values: ``"brackets"`` (``foo[]``), ``"repeat"`` and + ``"comma"`` (``foo``), ``"indices"`` (``foo[0]``, ``foo[1]``). + Note: this mutates the given dictionary. """ files: list[tuple[str, FileTypes]] = [] for path in paths: - files.extend(_extract_items(query, path, index=0, flattened_key=None)) + files.extend(_extract_items(query, path, index=0, flattened_key=None, array_format=array_format)) return files +def _array_suffix(array_format: ArrayFormat, array_index: int) -> str: + if array_format == "brackets": + return "[]" + if array_format == "indices": + return f"[{array_index}]" + if array_format == "repeat" or array_format == "comma": + # Both repeat the bare field name for each file part; there is no + # meaningful way to comma-join binary parts. + return "" + raise NotImplementedError( + f"Unknown array_format value: {array_format}, choose from {', '.join(get_args(ArrayFormat))}" + ) + + def _extract_items( obj: object, path: Sequence[str], *, index: int, flattened_key: str | None, + array_format: ArrayFormat, ) -> list[tuple[str, FileTypes]]: try: key = path[index] @@ -75,9 +95,11 @@ def _extract_items( if is_list(obj): files: list[tuple[str, FileTypes]] = [] - for entry in obj: - assert_is_file_content(entry, key=flattened_key + "[]" if flattened_key else "") - files.append((flattened_key + "[]", cast(FileTypes, entry))) + for array_index, entry in enumerate(obj): + suffix = _array_suffix(array_format, array_index) + emitted_key = (flattened_key + suffix) if flattened_key else suffix + assert_is_file_content(entry, key=emitted_key) + files.append((emitted_key, cast(FileTypes, entry))) return files assert_is_file_content(obj, key=flattened_key) @@ -106,6 +128,7 @@ def _extract_items( path, index=index, flattened_key=flattened_key, + array_format=array_format, ) elif is_list(obj): if key != "": @@ -117,9 +140,12 @@ def _extract_items( item, path, index=index, - flattened_key=flattened_key + "[]" if flattened_key is not None else "[]", + flattened_key=( + (flattened_key if flattened_key is not None else "") + _array_suffix(array_format, array_index) + ), + array_format=array_format, ) - for item in obj + for array_index, item in enumerate(obj) ] ) diff --git a/src/linq/_version.py b/src/linq/_version.py index 6a0d15d..0586a24 100644 --- a/src/linq/_version.py +++ b/src/linq/_version.py @@ -1,4 +1,4 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. __title__ = "linq" -__version__ = "0.5.0" # x-release-please-version +__version__ = "0.6.0" # x-release-please-version diff --git a/tests/api_resources/test_chats.py b/tests/api_resources/test_chats.py index 4102fd5..fbdad2e 100644 --- a/tests/api_resources/test_chats.py +++ b/tests/api_resources/test_chats.py @@ -354,7 +354,7 @@ def test_method_send_voicememo(self, client: LinqAPIV3) -> None: def test_method_send_voicememo_with_all_params(self, client: LinqAPIV3) -> None: chat = client.chats.send_voicememo( chat_id="f19ee7b8-8533-4c5c-83ec-4ef8d6d1ddbd", - attachment_id="550e8400-e29b-41d4-a716-446655440000", + attachment_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", voice_memo_url="https://example.com/voice-memo.m4a", ) assert_matches_type(ChatSendVoicememoResponse, chat, path=["response"]) @@ -771,7 +771,7 @@ async def test_method_send_voicememo(self, async_client: AsyncLinqAPIV3) -> None async def test_method_send_voicememo_with_all_params(self, async_client: AsyncLinqAPIV3) -> None: chat = await async_client.chats.send_voicememo( chat_id="f19ee7b8-8533-4c5c-83ec-4ef8d6d1ddbd", - attachment_id="550e8400-e29b-41d4-a716-446655440000", + attachment_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", voice_memo_url="https://example.com/voice-memo.m4a", ) assert_matches_type(ChatSendVoicememoResponse, chat, path=["response"]) diff --git a/tests/api_resources/test_messages.py b/tests/api_resources/test_messages.py index cc38749..7b9d2b9 100644 --- a/tests/api_resources/test_messages.py +++ b/tests/api_resources/test_messages.py @@ -178,7 +178,7 @@ def test_method_add_reaction_with_all_params(self, client: LinqAPIV3) -> None: message_id="69a37c7d-af4f-4b5e-af42-e28e98ce873a", operation="add", type="love", - custom_emoji="😍", + custom_emoji="custom_emoji", part_index=1, ) assert_matches_type(MessageAddReactionResponse, message, path=["response"]) @@ -439,7 +439,7 @@ async def test_method_add_reaction_with_all_params(self, async_client: AsyncLinq message_id="69a37c7d-af4f-4b5e-af42-e28e98ce873a", operation="add", type="love", - custom_emoji="😍", + custom_emoji="custom_emoji", part_index=1, ) assert_matches_type(MessageAddReactionResponse, message, path=["response"]) diff --git a/tests/test_extract_files.py b/tests/test_extract_files.py index f3e5af5..beb930d 100644 --- a/tests/test_extract_files.py +++ b/tests/test_extract_files.py @@ -4,7 +4,7 @@ import pytest -from linq._types import FileTypes +from linq._types import FileTypes, ArrayFormat from linq._utils import extract_files @@ -37,10 +37,7 @@ def test_multiple_files() -> None: def test_top_level_file_array() -> None: query = {"files": [b"file one", b"file two"], "title": "hello"} - assert extract_files(query, paths=[["files", ""]]) == [ - ("files[]", b"file one"), - ("files[]", b"file two"), - ] + assert extract_files(query, paths=[["files", ""]]) == [("files[]", b"file one"), ("files[]", b"file two")] assert query == {"title": "hello"} @@ -71,3 +68,24 @@ def test_ignores_incorrect_paths( expected: list[tuple[str, FileTypes]], ) -> None: assert extract_files(query, paths=paths) == expected + + +@pytest.mark.parametrize( + "array_format,expected_top_level,expected_nested", + [ + ("brackets", [("files[]", b"a"), ("files[]", b"b")], [("items[][file]", b"a"), ("items[][file]", b"b")]), + ("repeat", [("files", b"a"), ("files", b"b")], [("items[file]", b"a"), ("items[file]", b"b")]), + ("comma", [("files", b"a"), ("files", b"b")], [("items[file]", b"a"), ("items[file]", b"b")]), + ("indices", [("files[0]", b"a"), ("files[1]", b"b")], [("items[0][file]", b"a"), ("items[1][file]", b"b")]), + ], +) +def test_array_format_controls_file_field_names( + array_format: ArrayFormat, + expected_top_level: list[tuple[str, FileTypes]], + expected_nested: list[tuple[str, FileTypes]], +) -> None: + top_level = {"files": [b"a", b"b"]} + assert extract_files(top_level, paths=[["files", ""]], array_format=array_format) == expected_top_level + + nested = {"items": [{"file": b"a"}, {"file": b"b"}]} + assert extract_files(nested, paths=[["items", "", "file"]], array_format=array_format) == expected_nested diff --git a/tests/test_files.py b/tests/test_files.py index 863d906..40bb68e 100644 --- a/tests/test_files.py +++ b/tests/test_files.py @@ -131,7 +131,7 @@ def test_extract_files_does_not_mutate_original_nested_array_path(self) -> None: copied = deepcopy_with_paths(original, [["items", "", "file"]]) extracted = extract_files(copied, paths=[["items", "", "file"]]) - assert extracted == [("items[][file]", file1), ("items[][file]", file2)] + assert [entry for _, entry in extracted] == [file1, file2] assert original == { "items": [ {"file": file1, "extra": 1},