diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 34dc535..6d78745 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.8.2" + ".": "0.9.0" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 257d542..93d2bce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,57 @@ # Changelog +## 0.9.0 (2026-04-28) + +Full Changelog: [v0.8.2...v0.9.0](https://github.com/mirurobotics/python-platform-sdk/compare/v0.8.2...v0.9.0) + +### Features + +* **api:** manual updates ([e15b371](https://github.com/mirurobotics/python-platform-sdk/commit/e15b371d7a9a5687b9fbc60524a818c167cba97a)) +* **api:** manual updates ([7c6d61a](https://github.com/mirurobotics/python-platform-sdk/commit/7c6d61aa3d231a787539fbe62138a46de725ee81)) +* **api:** manual updates ([80b0c17](https://github.com/mirurobotics/python-platform-sdk/commit/80b0c172dee57b78d5d1f2e17cd1283be0dc6740)) +* **api:** manual updates ([187dcb1](https://github.com/mirurobotics/python-platform-sdk/commit/187dcb1e4878640fdf1792f69151714697ae89ed)) +* **api:** update to 2026-03-09.tetons ([568d158](https://github.com/mirurobotics/python-platform-sdk/commit/568d158f7af263ec6433e38bbd847643f4b77bf6)) +* **api:** update to v2026-03-09.tetons-beta.2 spec ([1a97c7f](https://github.com/mirurobotics/python-platform-sdk/commit/1a97c7f1df22f5cfb6f5e4729af66630a50b3889)) +* **internal:** implement indices array format for query and form serialization ([81adbec](https://github.com/mirurobotics/python-platform-sdk/commit/81adbec701adf8e2952ae8211de868dafce42732)) +* support setting headers via env ([faef5b5](https://github.com/mirurobotics/python-platform-sdk/commit/faef5b50ecf9d5cdffc11468b845de8a9f3e4427)) + + +### Bug Fixes + +* **client:** preserve hardcoded query params when merging with user params ([c9d40ca](https://github.com/mirurobotics/python-platform-sdk/commit/c9d40cac501fd18c68af97b2928200a3e99cdd59)) +* **deps:** bump minimum typing-extensions version ([63f1814](https://github.com/mirurobotics/python-platform-sdk/commit/63f18147c08d24cae32665f5fd2f77de259a9900)) +* ensure file data are only sent as 1 parameter ([1ac879d](https://github.com/mirurobotics/python-platform-sdk/commit/1ac879de2432f0e5ea2abbfe28f4242c4a99f792)) +* pydantic model not being parsed on forward references ([5507c1c](https://github.com/mirurobotics/python-platform-sdk/commit/5507c1cc7c05c559a0f62e431005b472a7232796)) +* **pydantic:** do not pass `by_alias` unless set ([3a25c23](https://github.com/mirurobotics/python-platform-sdk/commit/3a25c23ed2863ea1b9b4670e53084d4a6e295321)) +* sanitize endpoint path params ([1b9b9e4](https://github.com/mirurobotics/python-platform-sdk/commit/1b9b9e4388cd49a78f128ff0c466c42442fb5d5a)) +* use correct field name format for multipart file arrays ([a8915f9](https://github.com/mirurobotics/python-platform-sdk/commit/a8915f98210a0f63463467a83257e0f6c2b85381)) + + +### Performance Improvements + +* **client:** optimize file structure copying in multipart requests ([954d6ab](https://github.com/mirurobotics/python-platform-sdk/commit/954d6ab91aea4648ec0f7a2cddf0e0fa4a44a73b)) + + +### Chores + +* **ci:** skip lint on metadata-only changes ([0fa2565](https://github.com/mirurobotics/python-platform-sdk/commit/0fa2565e73e4a5ff9a5a97375a541e4c858d00b1)) +* **ci:** skip uploading artifacts on stainless-internal branches ([983e18f](https://github.com/mirurobotics/python-platform-sdk/commit/983e18ff19e0214adf95819a74e1fd50a3da7dae)) +* **internal:** more robust bootstrap script ([81c815a](https://github.com/mirurobotics/python-platform-sdk/commit/81c815a4143a20ab796bbe18233f921f604d86f8)) +* **internal:** tweak CI branches ([14940d2](https://github.com/mirurobotics/python-platform-sdk/commit/14940d2920c3866e32c17169923aafe45e4f3a9a)) +* **internal:** update gitignore ([aa19164](https://github.com/mirurobotics/python-platform-sdk/commit/aa19164d96d62b5b345a740ed6260fc091637fe6)) +* update example ([615100b](https://github.com/mirurobotics/python-platform-sdk/commit/615100b4fece75e73c1bdddd28d625db7590c509)) +* update SDK settings ([b659dc5](https://github.com/mirurobotics/python-platform-sdk/commit/b659dc53534bf310a104987bd2ed3fefe325326e)) +* update SDK settings ([5414e23](https://github.com/mirurobotics/python-platform-sdk/commit/5414e23d37776786c9366747cd909bd9851d5231)) +* update SDK settings ([71e1217](https://github.com/mirurobotics/python-platform-sdk/commit/71e1217ae174784bda5e3c6052a3cdf70715b750)) +* update SDK settings ([8006dd3](https://github.com/mirurobotics/python-platform-sdk/commit/8006dd38b8ce3cdaa2b66d6e8fdebf6f86d95205)) +* update SDK settings ([c7d2a67](https://github.com/mirurobotics/python-platform-sdk/commit/c7d2a6715d15e3c535f1b3cc28f3fa9e01244eb4)) +* update SDK settings ([60b9e0e](https://github.com/mirurobotics/python-platform-sdk/commit/60b9e0ed6f722e3569145eb5f31d726bf0ca6bc0)) + + +### Refactors + +* require miru version header in client initialization ([8e8e267](https://github.com/mirurobotics/python-platform-sdk/commit/8e8e267fe7c72da12c02b04da297bda9161055bb)) + ## 0.8.2 (2026-04-18) Full Changelog: [v0.8.1...v0.8.2](https://github.com/mirurobotics/python-platform-sdk/compare/v0.8.1...v0.8.2) diff --git a/pyproject.toml b/pyproject.toml index e7fc8f4..177fc44 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "miru-platform-sdk" -version = "0.8.2" +version = "0.9.0" description = "The official Python library for the miru API" dynamic = ["readme"] license = "MIT" diff --git a/scripts/bootstrap b/scripts/bootstrap index 4638ec6..5a23841 100755 --- a/scripts/bootstrap +++ b/scripts/bootstrap @@ -4,7 +4,7 @@ set -e cd "$(dirname "$0")/.." -if [ -f "Brewfile" ] && [ "$(uname -s)" = "Darwin" ] && [ "$SKIP_BREW" != "1" ] && [ -t 0 ]; then +if [ -f "Brewfile" ] && [ "$(uname -s)" = "Darwin" ] && [ "${SKIP_BREW:-}" != "1" ] && [ -t 0 ]; then brew bundle check >/dev/null 2>&1 || { echo -n "==> Install Homebrew dependencies? (y/N): " read -r response diff --git a/src/miru_platform_sdk/_client.py b/src/miru_platform_sdk/_client.py index 8b9daa9..95ccfb8 100644 --- a/src/miru_platform_sdk/_client.py +++ b/src/miru_platform_sdk/_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 ._version import __version__ from ._streaming import Stream as Stream, AsyncStream as AsyncStream @@ -146,6 +150,15 @@ def __init__( except KeyError as exc: raise ValueError(f"Unknown environment: {environment}") from exc + custom_headers_env = os.environ.get("MIRU_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, @@ -399,6 +412,15 @@ def __init__( except KeyError as exc: raise ValueError(f"Unknown environment: {environment}") from exc + custom_headers_env = os.environ.get("MIRU_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/miru_platform_sdk/_qs.py b/src/miru_platform_sdk/_qs.py index de8c99b..4127c19 100644 --- a/src/miru_platform_sdk/_qs.py +++ b/src/miru_platform_sdk/_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/miru_platform_sdk/_types.py b/src/miru_platform_sdk/_types.py index ebf7ea8..fff7ddf 100644 --- a/src/miru_platform_sdk/_types.py +++ b/src/miru_platform_sdk/_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/miru_platform_sdk/_utils/_utils.py b/src/miru_platform_sdk/_utils/_utils.py index 771859f..199cd23 100644 --- a/src/miru_platform_sdk/_utils/_utils.py +++ b/src/miru_platform_sdk/_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/miru_platform_sdk/_version.py b/src/miru_platform_sdk/_version.py index 12bf6f0..4b492c7 100644 --- a/src/miru_platform_sdk/_version.py +++ b/src/miru_platform_sdk/_version.py @@ -1,4 +1,4 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. __title__ = "miru_platform_sdk" -__version__ = "0.8.2" # x-release-please-version +__version__ = "0.9.0" # x-release-please-version diff --git a/tests/test_extract_files.py b/tests/test_extract_files.py index ebec476..44b6f67 100644 --- a/tests/test_extract_files.py +++ b/tests/test_extract_files.py @@ -4,7 +4,7 @@ import pytest -from miru_platform_sdk._types import FileTypes +from miru_platform_sdk._types import FileTypes, ArrayFormat from miru_platform_sdk._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 2e96173..f5f7f35 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},