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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
timeout-minutes: 10
name: lint
runs-on: ${{ github.repository == 'stainless-sdks/formalize-python' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}
if: github.event_name == 'push' || github.event.pull_request.head.repo.fork
if: (github.event_name == 'push' || github.event.pull_request.head.repo.fork) && (github.event_name != 'push' || github.event.head_commit.message != 'codegen metadata')
steps:
- uses: actions/checkout@v6

Expand All @@ -35,7 +35,7 @@ jobs:
run: ./scripts/lint

build:
if: github.event_name == 'push' || github.event.pull_request.head.repo.fork
if: (github.event_name == 'push' || github.event.pull_request.head.repo.fork) && (github.event_name != 'push' || github.event.head_commit.message != 'codegen metadata')
timeout-minutes: 10
name: build
permissions:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.prism.log
.stdy.log
_dev

__pycache__
Expand Down
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.3.0"
".": "1.4.0"
}
6 changes: 3 additions & 3 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 4
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/benchify%2Fformalize-68622707ed43c0c2934d378d9c87b746a95967ca3d2764b0889889f771317611.yml
openapi_spec_hash: e46e13174b96c49dbca07afd1a97c2ed
configured_endpoints: 2
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/benchify%2Fformalize-f6e0e485f1191c10775d87291f7a76776c2af882ad6a9e32af17e676dde8521e.yml
openapi_spec_hash: b09b4f07b4f2796145d9a607d6dfa2e5
config_hash: 63fdaff946185aaff06e9fd59a007649
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# Changelog

## 1.4.0 (2026-03-31)

Full Changelog: [v1.3.0...v1.4.0](https://github.com/Benchify/formalize-python/compare/v1.3.0...v1.4.0)

### Features

* get rid of legacy routes ([5da5279](https://github.com/Benchify/formalize-python/commit/5da527973b1d2d994bf3dfeccd5e69bc65aa12f5))
* **internal:** implement indices array format for query and form serialization ([563c58c](https://github.com/Benchify/formalize-python/commit/563c58cb935ec2baf52614b9a2b8f7f2ac4178e7))


### Bug Fixes

* sanitize endpoint path params ([f9b35f6](https://github.com/Benchify/formalize-python/commit/f9b35f6d04184131168dde207f7d8dac47a7ecd7))


### Chores

* **ci:** skip lint on metadata-only changes ([f3ad8e3](https://github.com/Benchify/formalize-python/commit/f3ad8e3e3f5a4f4a49bad8f60ff3202d5e487152))
* **internal:** update gitignore ([05eef18](https://github.com/Benchify/formalize-python/commit/05eef18b272c2be5047fa6c51504fc1e49aca1cb))

## 1.3.0 (2026-03-17)

Full Changelog: [v1.2.0...v1.3.0](https://github.com/Benchify/formalize-python/compare/v1.2.0...v1.3.0)
Expand Down
12 changes: 0 additions & 12 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,3 @@ Methods:

- <code title="post /api/v1/contracts/{contract_id}/audit">client.api.v1.contracts.audit.<a href="./src/formalize/resources/api/v1/contracts/audit.py">create</a>(contract_id, \*\*<a href="src/formalize/types/api/v1/contracts/audit_create_params.py">params</a>) -> <a href="./src/formalize/types/api/v1/contracts/audit_create_response.py">AuditCreateResponse</a></code>
- <code title="post /api/v1/contracts/{contract_id}/audit/batch">client.api.v1.contracts.audit.<a href="./src/formalize/resources/api/v1/contracts/audit.py">batch</a>(contract_id, \*\*<a href="src/formalize/types/api/v1/contracts/audit_batch_params.py">params</a>) -> <a href="./src/formalize/types/api/v1/contracts/audit_batch_response.py">AuditBatchResponse</a></code>

## Contracts

Methods:

- <code title="post /api/contracts/{contract_id}/optimize">client.api.contracts.<a href="./src/formalize/resources/api/contracts/contracts.py">optimize</a>(contract_id, \*\*<a href="src/formalize/types/api/contract_optimize_params.py">params</a>) -> object</code>

### OptimizationResults

Methods:

- <code title="get /api/contracts/{contract_id}/optimization-results">client.api.contracts.optimization_results.<a href="./src/formalize/resources/api/contracts/optimization_results.py">retrieve_optimization_results</a>(contract_id) -> object</code>
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "benchify"
version = "1.3.0"
version = "1.4.0"
description = "The official Python library for the formalize API"
dynamic = ["readme"]
license = "Apache-2.0"
Expand Down
5 changes: 4 additions & 1 deletion src/formalize/_qs.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ def _stringify_item(
items.extend(self._stringify_item(key, item, opts))
return items
elif array_format == "indices":
raise NotImplementedError("The array indices format is not supported yet")
items = []
for i, item in enumerate(value):
items.extend(self._stringify_item(f"{key}[{i}]", item, opts))
return items
elif array_format == "brackets":
items = []
key = key + "[]"
Expand Down
1 change: 1 addition & 0 deletions src/formalize/_utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from ._path import path_template as path_template
from ._sync import asyncify as asyncify
from ._proxy import LazyProxy as LazyProxy
from ._utils import (
Expand Down
127 changes: 127 additions & 0 deletions src/formalize/_utils/_path.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
from __future__ import annotations

import re
from typing import (
Any,
Mapping,
Callable,
)
from urllib.parse import quote

# Matches '.' or '..' where each dot is either literal or percent-encoded (%2e / %2E).
_DOT_SEGMENT_RE = re.compile(r"^(?:\.|%2[eE]){1,2}$")

_PLACEHOLDER_RE = re.compile(r"\{(\w+)\}")


def _quote_path_segment_part(value: str) -> str:
"""Percent-encode `value` for use in a URI path segment.

Considers characters not in `pchar` set from RFC 3986 §3.3 to be unsafe.
https://datatracker.ietf.org/doc/html/rfc3986#section-3.3
"""
# quote() already treats unreserved characters (letters, digits, and -._~)
# as safe, so we only need to add sub-delims, ':', and '@'.
# Notably, unlike the default `safe` for quote(), / is unsafe and must be quoted.
return quote(value, safe="!$&'()*+,;=:@")


def _quote_query_part(value: str) -> str:
"""Percent-encode `value` for use in a URI query string.

Considers &, = and characters not in `query` set from RFC 3986 §3.4 to be unsafe.
https://datatracker.ietf.org/doc/html/rfc3986#section-3.4
"""
return quote(value, safe="!$'()*+,;:@/?")


def _quote_fragment_part(value: str) -> str:
"""Percent-encode `value` for use in a URI fragment.

Considers characters not in `fragment` set from RFC 3986 §3.5 to be unsafe.
https://datatracker.ietf.org/doc/html/rfc3986#section-3.5
"""
return quote(value, safe="!$&'()*+,;=:@/?")


def _interpolate(
template: str,
values: Mapping[str, Any],
quoter: Callable[[str], str],
) -> str:
"""Replace {name} placeholders in `template`, quoting each value with `quoter`.

Placeholder names are looked up in `values`.

Raises:
KeyError: If a placeholder is not found in `values`.
"""
# re.split with a capturing group returns alternating
# [text, name, text, name, ..., text] elements.
parts = _PLACEHOLDER_RE.split(template)

for i in range(1, len(parts), 2):
name = parts[i]
if name not in values:
raise KeyError(f"a value for placeholder {{{name}}} was not provided")
val = values[name]
if val is None:
parts[i] = "null"
elif isinstance(val, bool):
parts[i] = "true" if val else "false"
else:
parts[i] = quoter(str(values[name]))

return "".join(parts)


def path_template(template: str, /, **kwargs: Any) -> str:
"""Interpolate {name} placeholders in `template` from keyword arguments.

Args:
template: The template string containing {name} placeholders.
**kwargs: Keyword arguments to interpolate into the template.

Returns:
The template with placeholders interpolated and percent-encoded.

Safe characters for percent-encoding are dependent on the URI component.
Placeholders in path and fragment portions are percent-encoded where the `segment`
and `fragment` sets from RFC 3986 respectively are considered safe.
Placeholders in the query portion are percent-encoded where the `query` set from
RFC 3986 §3.3 is considered safe except for = and & characters.

Raises:
KeyError: If a placeholder is not found in `kwargs`.
ValueError: If resulting path contains /./ or /../ segments (including percent-encoded dot-segments).
"""
# Split the template into path, query, and fragment portions.
fragment_template: str | None = None
query_template: str | None = None

rest = template
if "#" in rest:
rest, fragment_template = rest.split("#", 1)
if "?" in rest:
rest, query_template = rest.split("?", 1)
path_template = rest

# Interpolate each portion with the appropriate quoting rules.
path_result = _interpolate(path_template, kwargs, _quote_path_segment_part)

# Reject dot-segments (. and ..) in the final assembled path. The check
# runs after interpolation so that adjacent placeholders or a mix of static
# text and placeholders that together form a dot-segment are caught.
# Also reject percent-encoded dot-segments to protect against incorrectly
# implemented normalization in servers/proxies.
for segment in path_result.split("/"):
if _DOT_SEGMENT_RE.match(segment):
raise ValueError(f"Constructed path {path_result!r} contains dot-segment {segment!r} which is not allowed")

result = path_result
if query_template is not None:
result += "?" + _interpolate(query_template, kwargs, _quote_query_part)
if fragment_template is not None:
result += "#" + _interpolate(fragment_template, kwargs, _quote_fragment_part)

return result
2 changes: 1 addition & 1 deletion src/formalize/_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__ = "formalize"
__version__ = "1.3.0" # x-release-please-version
__version__ = "1.4.0" # x-release-please-version
14 changes: 0 additions & 14 deletions src/formalize/resources/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@
APIResourceWithStreamingResponse,
AsyncAPIResourceWithStreamingResponse,
)
from .contracts import (
ContractsResource,
AsyncContractsResource,
ContractsResourceWithRawResponse,
AsyncContractsResourceWithRawResponse,
ContractsResourceWithStreamingResponse,
AsyncContractsResourceWithStreamingResponse,
)

__all__ = [
"V1Resource",
Expand All @@ -32,12 +24,6 @@
"AsyncV1ResourceWithRawResponse",
"V1ResourceWithStreamingResponse",
"AsyncV1ResourceWithStreamingResponse",
"ContractsResource",
"AsyncContractsResource",
"ContractsResourceWithRawResponse",
"AsyncContractsResourceWithRawResponse",
"ContractsResourceWithStreamingResponse",
"AsyncContractsResourceWithStreamingResponse",
"APIResource",
"AsyncAPIResource",
"APIResourceWithRawResponse",
Expand Down
38 changes: 0 additions & 38 deletions src/formalize/resources/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@
AsyncV1ResourceWithStreamingResponse,
)
from ..._compat import cached_property
from .contracts.contracts import (
ContractsResource,
AsyncContractsResource,
ContractsResourceWithRawResponse,
AsyncContractsResourceWithRawResponse,
ContractsResourceWithStreamingResponse,
AsyncContractsResourceWithStreamingResponse,
)

__all__ = ["APIResource", "AsyncAPIResource"]

Expand All @@ -29,11 +21,6 @@ class APIResource(_resource.SyncAPIResource):
def v1(self) -> V1Resource:
return V1Resource(self._client)

@cached_property
def contracts(self) -> ContractsResource:
"""Contract optimization and AI-powered redline generation"""
return ContractsResource(self._client)

@cached_property
def with_raw_response(self) -> APIResourceWithRawResponse:
"""
Expand All @@ -59,11 +46,6 @@ class AsyncAPIResource(_resource.AsyncAPIResource):
def v1(self) -> AsyncV1Resource:
return AsyncV1Resource(self._client)

@cached_property
def contracts(self) -> AsyncContractsResource:
"""Contract optimization and AI-powered redline generation"""
return AsyncContractsResource(self._client)

@cached_property
def with_raw_response(self) -> AsyncAPIResourceWithRawResponse:
"""
Expand Down Expand Up @@ -92,11 +74,6 @@ def __init__(self, api: APIResource) -> None:
def v1(self) -> V1ResourceWithRawResponse:
return V1ResourceWithRawResponse(self._api.v1)

@cached_property
def contracts(self) -> ContractsResourceWithRawResponse:
"""Contract optimization and AI-powered redline generation"""
return ContractsResourceWithRawResponse(self._api.contracts)


class AsyncAPIResourceWithRawResponse:
def __init__(self, api: AsyncAPIResource) -> None:
Expand All @@ -106,11 +83,6 @@ def __init__(self, api: AsyncAPIResource) -> None:
def v1(self) -> AsyncV1ResourceWithRawResponse:
return AsyncV1ResourceWithRawResponse(self._api.v1)

@cached_property
def contracts(self) -> AsyncContractsResourceWithRawResponse:
"""Contract optimization and AI-powered redline generation"""
return AsyncContractsResourceWithRawResponse(self._api.contracts)


class APIResourceWithStreamingResponse:
def __init__(self, api: APIResource) -> None:
Expand All @@ -120,11 +92,6 @@ def __init__(self, api: APIResource) -> None:
def v1(self) -> V1ResourceWithStreamingResponse:
return V1ResourceWithStreamingResponse(self._api.v1)

@cached_property
def contracts(self) -> ContractsResourceWithStreamingResponse:
"""Contract optimization and AI-powered redline generation"""
return ContractsResourceWithStreamingResponse(self._api.contracts)


class AsyncAPIResourceWithStreamingResponse:
def __init__(self, api: AsyncAPIResource) -> None:
Expand All @@ -133,8 +100,3 @@ def __init__(self, api: AsyncAPIResource) -> None:
@cached_property
def v1(self) -> AsyncV1ResourceWithStreamingResponse:
return AsyncV1ResourceWithStreamingResponse(self._api.v1)

@cached_property
def contracts(self) -> AsyncContractsResourceWithStreamingResponse:
"""Contract optimization and AI-powered redline generation"""
return AsyncContractsResourceWithStreamingResponse(self._api.contracts)
33 changes: 0 additions & 33 deletions src/formalize/resources/api/contracts/__init__.py

This file was deleted.

Loading
Loading