Skip to content
Merged
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 @@
{
".": "2.0.0-alpha.26"
".": "2.0.0-alpha.27"
}
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# Changelog

## 2.0.0-alpha.27 (2025-09-29)

Full Changelog: [v2.0.0-alpha.26...v2.0.0-alpha.27](https://github.com/replicate/replicate-python-stainless/compare/v2.0.0-alpha.26...v2.0.0-alpha.27)

### Features

* add api_token parameter support for legacy compatibility ([7a781df](https://github.com/replicate/replicate-python-stainless/commit/7a781df6004d204439b95cb1fba09871f4bf28b7))
* add legacy exception compatibility aliases ([#70](https://github.com/replicate/replicate-python-stainless/issues/70)) ([1a66fc8](https://github.com/replicate/replicate-python-stainless/commit/1a66fc86cb9c258d16d4bf37d172216cd4206ccc))


### Bug Fixes

* **predictions:** use Omit instead of NotGiven ([6f10116](https://github.com/replicate/replicate-python-stainless/commit/6f1011624cd05a82422386332917748fc821fdc6))


### Chores

* **internal:** update formatting ([d1bebb6](https://github.com/replicate/replicate-python-stainless/commit/d1bebb6109cf3c79de4f3796eb65ec40ce7b592d))
* **types:** change optional parameter type from NotGiven to Omit ([3223abf](https://github.com/replicate/replicate-python-stainless/commit/3223abfcc308e1eeee45eea0549623fdad5a583f))

## 2.0.0-alpha.26 (2025-09-17)

Full Changelog: [v2.0.0-alpha.25...v2.0.0-alpha.26](https://github.com/replicate/replicate-python-stainless/compare/v2.0.0-alpha.25...v2.0.0-alpha.26)
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 = "replicate"
version = "2.0.0-alpha.26"
version = "2.0.0-alpha.27"
description = "The official Python library for the replicate API"
dynamic = ["readme"]
license = "Apache-2.0"
Expand Down
4 changes: 3 additions & 1 deletion src/replicate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing_extensions import override

from . import types
from ._types import NOT_GIVEN, Omit, NoneType, NotGiven, Transport, ProxiesTypes
from ._types import NOT_GIVEN, Omit, NoneType, NotGiven, Transport, ProxiesTypes, omit, not_given
from ._utils import file_from_path
from ._client import (
Client,
Expand Down Expand Up @@ -54,7 +54,9 @@
"ProxiesTypes",
"NotGiven",
"NOT_GIVEN",
"not_given",
"Omit",
"omit",
"ReplicateError",
"APIError",
"APIStatusError",
Expand Down
18 changes: 9 additions & 9 deletions src/replicate/_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
from ._qs import Querystring
from ._files import to_httpx_files, async_to_httpx_files
from ._types import (
NOT_GIVEN,
Body,
Omit,
Query,
Expand All @@ -57,6 +56,7 @@
RequestOptions,
HttpxRequestFiles,
ModelBuilderProtocol,
not_given,
)
from ._utils import is_dict, is_list, asyncify, is_given, lru_cache, is_mapping
from ._compat import PYDANTIC_V1, model_copy, model_dump
Expand Down Expand Up @@ -145,9 +145,9 @@ def __init__(
def __init__(
self,
*,
url: URL | NotGiven = NOT_GIVEN,
json: Body | NotGiven = NOT_GIVEN,
params: Query | NotGiven = NOT_GIVEN,
url: URL | NotGiven = not_given,
json: Body | NotGiven = not_given,
params: Query | NotGiven = not_given,
) -> None:
self.url = url
self.json = json
Expand Down Expand Up @@ -595,7 +595,7 @@ def _maybe_override_cast_to(self, cast_to: type[ResponseT], options: FinalReques
# we internally support defining a temporary header to override the
# default `cast_to` type for use with `.with_raw_response` and `.with_streaming_response`
# see _response.py for implementation details
override_cast_to = headers.pop(OVERRIDE_CAST_TO_HEADER, NOT_GIVEN)
override_cast_to = headers.pop(OVERRIDE_CAST_TO_HEADER, not_given)
if is_given(override_cast_to):
options.headers = headers
return cast(Type[ResponseT], override_cast_to)
Expand Down Expand Up @@ -825,7 +825,7 @@ def __init__(
version: str,
base_url: str | URL,
max_retries: int = DEFAULT_MAX_RETRIES,
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
timeout: float | Timeout | None | NotGiven = not_given,
http_client: httpx.Client | None = None,
custom_headers: Mapping[str, str] | None = None,
custom_query: Mapping[str, object] | None = None,
Expand Down Expand Up @@ -1370,7 +1370,7 @@ def __init__(
base_url: str | URL,
_strict_response_validation: bool,
max_retries: int = DEFAULT_MAX_RETRIES,
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
timeout: float | Timeout | None | NotGiven = not_given,
http_client: httpx.AsyncClient | None = None,
custom_headers: Mapping[str, str] | None = None,
custom_query: Mapping[str, object] | None = None,
Expand Down Expand Up @@ -1846,8 +1846,8 @@ def make_request_options(
extra_query: Query | None = None,
extra_body: Body | None = None,
idempotency_key: str | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
post_parser: PostParser | NotGiven = NOT_GIVEN,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
post_parser: PostParser | NotGiven = not_given,
) -> RequestOptions:
"""Create a dict of type RequestOptions without keys of NotGiven values."""
options: RequestOptions = {}
Expand Down
14 changes: 7 additions & 7 deletions src/replicate/_qs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from urllib.parse import parse_qs, urlencode
from typing_extensions import Literal, get_args

from ._types import NOT_GIVEN, NotGiven, NotGivenOr
from ._types import NotGiven, not_given
from ._utils import flatten

_T = TypeVar("_T")
Expand Down Expand Up @@ -41,8 +41,8 @@ def stringify(
self,
params: Params,
*,
array_format: NotGivenOr[ArrayFormat] = NOT_GIVEN,
nested_format: NotGivenOr[NestedFormat] = NOT_GIVEN,
array_format: ArrayFormat | NotGiven = not_given,
nested_format: NestedFormat | NotGiven = not_given,
) -> str:
return urlencode(
self.stringify_items(
Expand All @@ -56,8 +56,8 @@ def stringify_items(
self,
params: Params,
*,
array_format: NotGivenOr[ArrayFormat] = NOT_GIVEN,
nested_format: NotGivenOr[NestedFormat] = NOT_GIVEN,
array_format: ArrayFormat | NotGiven = not_given,
nested_format: NestedFormat | NotGiven = not_given,
) -> list[tuple[str, str]]:
opts = Options(
qs=self,
Expand Down Expand Up @@ -143,8 +143,8 @@ def __init__(
self,
qs: Querystring = _qs,
*,
array_format: NotGivenOr[ArrayFormat] = NOT_GIVEN,
nested_format: NotGivenOr[NestedFormat] = NOT_GIVEN,
array_format: ArrayFormat | NotGiven = not_given,
nested_format: NestedFormat | NotGiven = not_given,
) -> None:
self.array_format = qs.array_format if isinstance(array_format, NotGiven) else array_format
self.nested_format = qs.nested_format if isinstance(nested_format, NotGiven) else nested_format
29 changes: 18 additions & 11 deletions src/replicate/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,21 @@ class RequestOptions(TypedDict, total=False):
# Sentinel class used until PEP 0661 is accepted
class NotGiven:
"""
A sentinel singleton class used to distinguish omitted keyword arguments
from those passed in with the value None (which may have different behavior).
For parameters with a meaningful None value, we need to distinguish between
the user explicitly passing None, and the user not passing the parameter at
all.

User code shouldn't need to use not_given directly.

For example:

```py
def get(timeout: Union[int, NotGiven, None] = NotGiven()) -> Response: ...
def create(timeout: Timeout | None | NotGiven = not_given): ...


get(timeout=1) # 1s timeout
get(timeout=None) # No timeout
get() # Default timeout behavior, which may not be statically known at the method definition.
create(timeout=1) # 1s timeout
create(timeout=None) # No timeout
create() # Default timeout behavior
```
"""

Expand All @@ -140,13 +143,14 @@ def __repr__(self) -> str:
return "NOT_GIVEN"


NotGivenOr = Union[_T, NotGiven]
not_given = NotGiven()
# for backwards compatibility:
NOT_GIVEN = NotGiven()


class Omit:
"""In certain situations you need to be able to represent a case where a default value has
to be explicitly removed and `None` is not an appropriate substitute, for example:
"""
To explicitly omit something from being sent in a request, use `omit`.

```py
# as the default `Content-Type` header is `application/json` that will be sent
Expand All @@ -156,15 +160,18 @@ class Omit:
# to look something like: 'multipart/form-data; boundary=0d8382fcf5f8c3be01ca2e11002d2983'
client.post(..., headers={"Content-Type": "multipart/form-data"})

# instead you can remove the default `application/json` header by passing Omit
client.post(..., headers={"Content-Type": Omit()})
# instead you can remove the default `application/json` header by passing omit
client.post(..., headers={"Content-Type": omit})
```
"""

def __bool__(self) -> Literal[False]:
return False


omit = Omit()


@runtime_checkable
class ModelBuilderProtocol(Protocol):
@classmethod
Expand Down
4 changes: 2 additions & 2 deletions src/replicate/_utils/_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def _transform_typeddict(
annotations = get_type_hints(expected_type, include_extras=True)
for key, value in data.items():
if not is_given(value):
# we don't need to include `NotGiven` values here as they'll
# we don't need to include omitted values here as they'll
# be stripped out before the request is sent anyway
continue

Expand Down Expand Up @@ -434,7 +434,7 @@ async def _async_transform_typeddict(
annotations = get_type_hints(expected_type, include_extras=True)
for key, value in data.items():
if not is_given(value):
# we don't need to include `NotGiven` values here as they'll
# we don't need to include omitted values here as they'll
# be stripped out before the request is sent anyway
continue

Expand Down
8 changes: 4 additions & 4 deletions src/replicate/_utils/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import sniffio

from .._types import NotGiven, FileTypes, NotGivenOr, HeadersLike
from .._types import Omit, NotGiven, FileTypes, HeadersLike

_T = TypeVar("_T")
_TupleT = TypeVar("_TupleT", bound=Tuple[object, ...])
Expand Down Expand Up @@ -63,7 +63,7 @@ def _extract_items(
try:
key = path[index]
except IndexError:
if isinstance(obj, NotGiven):
if not is_given(obj):
# no value was provided - we can safely ignore
return []

Expand Down Expand Up @@ -126,8 +126,8 @@ def _extract_items(
return []


def is_given(obj: NotGivenOr[_T]) -> TypeGuard[_T]:
return not isinstance(obj, NotGiven)
def is_given(obj: _T | NotGiven | Omit) -> TypeGuard[_T]:
return not isinstance(obj, NotGiven) and not isinstance(obj, Omit)


# Type safe methods for narrowing types with TypeVars.
Expand Down
2 changes: 1 addition & 1 deletion src/replicate/_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__ = "replicate"
__version__ = "2.0.0-alpha.26" # x-release-please-version
__version__ = "2.0.0-alpha.27" # x-release-please-version
6 changes: 3 additions & 3 deletions src/replicate/resources/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import httpx

from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven
from .._types import Body, Query, Headers, NotGiven, not_given
from .._compat import cached_property
from .._resource import SyncAPIResource, AsyncAPIResource
from .._response import (
Expand Down Expand Up @@ -47,7 +47,7 @@ def get(
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> AccountGetResponse:
"""
Returns information about the user or organization associated with the provided
Expand Down Expand Up @@ -109,7 +109,7 @@ async def get(
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> AccountGetResponse:
"""
Returns information about the user or organization associated with the provided
Expand Down
10 changes: 5 additions & 5 deletions src/replicate/resources/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import httpx

from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven
from .._types import Body, Query, Headers, NotGiven, not_given
from .._compat import cached_property
from .._resource import SyncAPIResource, AsyncAPIResource
from .._response import (
Expand Down Expand Up @@ -49,7 +49,7 @@ def list(
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> SyncCursorURLPage[CollectionListResponse]:
"""
Example cURL request:
Expand Down Expand Up @@ -94,7 +94,7 @@ def get(
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> CollectionGetResponse:
"""
Example cURL request:
Expand Down Expand Up @@ -165,7 +165,7 @@ def list(
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> AsyncPaginator[CollectionListResponse, AsyncCursorURLPage[CollectionListResponse]]:
"""
Example cURL request:
Expand Down Expand Up @@ -210,7 +210,7 @@ async def get(
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> CollectionGetResponse:
"""
Example cURL request:
Expand Down
Loading