Skip to content

Commit b543e85

Browse files
Merge pull request #20 from CASParser/release-please--branches--main--changes--next
release: 1.9.0
2 parents e31d874 + fb4d1ad commit b543e85

12 files changed

Lines changed: 111 additions & 27 deletions

File tree

.release-please-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
".": "1.8.0"
2+
".": "1.9.0"
33
}

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 21
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cas-parser%2Fcas-parser-e5c0c65637cdf3a6c4360b8193973b73a3d35ad1056ef607c3319ef03e591a55.yml
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cas-parser/cas-parser-2fd773786951b723a5d7d7342bf1c6ab46f08bd2851e916d188faae379d5aa4c.yml
33
openapi_spec_hash: 7515d1e5fe3130b9f5411f7aacbc8a64
44
config_hash: 5509bb7a961ae2e79114b24c381606d4

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
# Changelog
22

3+
## 1.9.0 (2026-05-01)
4+
5+
Full Changelog: [v1.8.0...v1.9.0](https://github.com/CASParser/cas-parser-python/compare/v1.8.0...v1.9.0)
6+
7+
### Features
8+
9+
* support setting headers via env ([cddcbfe](https://github.com/CASParser/cas-parser-python/commit/cddcbfeb1bc2304e73bc00e209a36e54835bff65))
10+
11+
12+
### Bug Fixes
13+
14+
* use correct field name format for multipart file arrays ([f944611](https://github.com/CASParser/cas-parser-python/commit/f9446112d528f85c0b81de683fb920173ccd419f))
15+
16+
17+
### Chores
18+
19+
* **internal:** more robust bootstrap script ([058a8e9](https://github.com/CASParser/cas-parser-python/commit/058a8e9da54a73314e16eb650e8e45e3982cc677))
20+
* **internal:** reformat pyproject.toml ([c619569](https://github.com/CASParser/cas-parser-python/commit/c619569d3b418561dc076a8e6eb11a080479e34e))
21+
322
## 1.8.0 (2026-04-19)
423

524
Full Changelog: [v1.7.0...v1.8.0](https://github.com/CASParser/cas-parser-python/compare/v1.7.0...v1.8.0)

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "cas-parser-python"
3-
version = "1.8.0"
3+
version = "1.9.0"
44
description = "The official Python library for the cas-parser API"
55
dynamic = ["readme"]
66
license = "Apache-2.0"
@@ -154,7 +154,7 @@ show_error_codes = true
154154
#
155155
# We also exclude our `tests` as mypy doesn't always infer
156156
# types correctly and Pyright will still catch any type errors.
157-
exclude = ['src/cas_parser/_files.py', '_dev/.*.py', 'tests/.*']
157+
exclude = ["src/cas_parser/_files.py", "_dev/.*.py", "tests/.*"]
158158

159159
strict_equality = true
160160
implicit_reexport = true

scripts/bootstrap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -e
44

55
cd "$(dirname "$0")/.."
66

7-
if [ -f "Brewfile" ] && [ "$(uname -s)" = "Darwin" ] && [ "$SKIP_BREW" != "1" ] && [ -t 0 ]; then
7+
if [ -f "Brewfile" ] && [ "$(uname -s)" = "Darwin" ] && [ "${SKIP_BREW:-}" != "1" ] && [ -t 0 ]; then
88
brew bundle check >/dev/null 2>&1 || {
99
echo -n "==> Install Homebrew dependencies? (y/N): "
1010
read -r response

src/cas_parser/_client.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@
1919
RequestOptions,
2020
not_given,
2121
)
22-
from ._utils import is_given, get_async_library
22+
from ._utils import (
23+
is_given,
24+
is_mapping_t,
25+
get_async_library,
26+
)
2327
from ._compat import cached_property
2428
from ._models import SecurityOptions
2529
from ._version import __version__
@@ -115,6 +119,15 @@ def __init__(
115119
if base_url is None:
116120
base_url = f"https://api.casparser.in"
117121

122+
custom_headers_env = os.environ.get("CAS_PARSER_CUSTOM_HEADERS")
123+
if custom_headers_env is not None:
124+
parsed: dict[str, str] = {}
125+
for line in custom_headers_env.split("\n"):
126+
colon = line.find(":")
127+
if colon >= 0:
128+
parsed[line[:colon].strip()] = line[colon + 1 :].strip()
129+
default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})}
130+
118131
super().__init__(
119132
version=__version__,
120133
base_url=base_url,
@@ -424,6 +437,15 @@ def __init__(
424437
if base_url is None:
425438
base_url = f"https://api.casparser.in"
426439

440+
custom_headers_env = os.environ.get("CAS_PARSER_CUSTOM_HEADERS")
441+
if custom_headers_env is not None:
442+
parsed: dict[str, str] = {}
443+
for line in custom_headers_env.split("\n"):
444+
colon = line.find(":")
445+
if colon >= 0:
446+
parsed[line[:colon].strip()] = line[colon + 1 :].strip()
447+
default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})}
448+
427449
super().__init__(
428450
version=__version__,
429451
base_url=base_url,

src/cas_parser/_qs.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,13 @@
22

33
from typing import Any, List, Tuple, Union, Mapping, TypeVar
44
from urllib.parse import parse_qs, urlencode
5-
from typing_extensions import Literal, get_args
5+
from typing_extensions import get_args
66

7-
from ._types import NotGiven, not_given
7+
from ._types import NotGiven, ArrayFormat, NestedFormat, not_given
88
from ._utils import flatten
99

1010
_T = TypeVar("_T")
1111

12-
13-
ArrayFormat = Literal["comma", "repeat", "indices", "brackets"]
14-
NestedFormat = Literal["dots", "brackets"]
15-
1612
PrimitiveData = Union[str, int, float, bool, None]
1713
# this should be Data = Union[PrimitiveData, "List[Data]", "Tuple[Data]", "Mapping[str, Data]"]
1814
# https://github.com/microsoft/pyright/issues/3555

src/cas_parser/_types.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
ModelT = TypeVar("ModelT", bound=pydantic.BaseModel)
4848
_T = TypeVar("_T")
4949

50+
ArrayFormat = Literal["comma", "repeat", "indices", "brackets"]
51+
NestedFormat = Literal["dots", "brackets"]
52+
5053

5154
# Approximates httpx internal ProxiesTypes and RequestFiles types
5255
# while adding support for `PathLike` instances

src/cas_parser/_utils/_utils.py

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
)
1818
from pathlib import Path
1919
from datetime import date, datetime
20-
from typing_extensions import TypeGuard
20+
from typing_extensions import TypeGuard, get_args
2121

2222
import sniffio
2323

24-
from .._types import Omit, NotGiven, FileTypes, HeadersLike
24+
from .._types import Omit, NotGiven, FileTypes, ArrayFormat, HeadersLike
2525

2626
_T = TypeVar("_T")
2727
_TupleT = TypeVar("_TupleT", bound=Tuple[object, ...])
@@ -40,25 +40,45 @@ def extract_files(
4040
query: Mapping[str, object],
4141
*,
4242
paths: Sequence[Sequence[str]],
43+
array_format: ArrayFormat = "brackets",
4344
) -> list[tuple[str, FileTypes]]:
4445
"""Recursively extract files from the given dictionary based on specified paths.
4546
4647
A path may look like this ['foo', 'files', '<array>', 'data'].
4748
49+
``array_format`` controls how ``<array>`` segments contribute to the emitted
50+
field name. Supported values: ``"brackets"`` (``foo[]``), ``"repeat"`` and
51+
``"comma"`` (``foo``), ``"indices"`` (``foo[0]``, ``foo[1]``).
52+
4853
Note: this mutates the given dictionary.
4954
"""
5055
files: list[tuple[str, FileTypes]] = []
5156
for path in paths:
52-
files.extend(_extract_items(query, path, index=0, flattened_key=None))
57+
files.extend(_extract_items(query, path, index=0, flattened_key=None, array_format=array_format))
5358
return files
5459

5560

61+
def _array_suffix(array_format: ArrayFormat, array_index: int) -> str:
62+
if array_format == "brackets":
63+
return "[]"
64+
if array_format == "indices":
65+
return f"[{array_index}]"
66+
if array_format == "repeat" or array_format == "comma":
67+
# Both repeat the bare field name for each file part; there is no
68+
# meaningful way to comma-join binary parts.
69+
return ""
70+
raise NotImplementedError(
71+
f"Unknown array_format value: {array_format}, choose from {', '.join(get_args(ArrayFormat))}"
72+
)
73+
74+
5675
def _extract_items(
5776
obj: object,
5877
path: Sequence[str],
5978
*,
6079
index: int,
6180
flattened_key: str | None,
81+
array_format: ArrayFormat,
6282
) -> list[tuple[str, FileTypes]]:
6383
try:
6484
key = path[index]
@@ -75,9 +95,11 @@ def _extract_items(
7595

7696
if is_list(obj):
7797
files: list[tuple[str, FileTypes]] = []
78-
for entry in obj:
79-
assert_is_file_content(entry, key=flattened_key + "[]" if flattened_key else "")
80-
files.append((flattened_key + "[]", cast(FileTypes, entry)))
98+
for array_index, entry in enumerate(obj):
99+
suffix = _array_suffix(array_format, array_index)
100+
emitted_key = (flattened_key + suffix) if flattened_key else suffix
101+
assert_is_file_content(entry, key=emitted_key)
102+
files.append((emitted_key, cast(FileTypes, entry)))
81103
return files
82104

83105
assert_is_file_content(obj, key=flattened_key)
@@ -106,6 +128,7 @@ def _extract_items(
106128
path,
107129
index=index,
108130
flattened_key=flattened_key,
131+
array_format=array_format,
109132
)
110133
elif is_list(obj):
111134
if key != "<array>":
@@ -117,9 +140,12 @@ def _extract_items(
117140
item,
118141
path,
119142
index=index,
120-
flattened_key=flattened_key + "[]" if flattened_key is not None else "[]",
143+
flattened_key=(
144+
(flattened_key if flattened_key is not None else "") + _array_suffix(array_format, array_index)
145+
),
146+
array_format=array_format,
121147
)
122-
for item in obj
148+
for array_index, item in enumerate(obj)
123149
]
124150
)
125151

src/cas_parser/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

33
__title__ = "cas_parser"
4-
__version__ = "1.8.0" # x-release-please-version
4+
__version__ = "1.9.0" # x-release-please-version

0 commit comments

Comments
 (0)