From 7a781df6004d204439b95cb1fba09871f4bf28b7 Mon Sep 17 00:00:00 2001 From: Zeke Sikelianos Date: Mon, 22 Sep 2025 17:36:02 -0700 Subject: [PATCH 1/6] feat: add api_token parameter support for legacy compatibility Adds support for the legacy api_token parameter in both Replicate and AsyncReplicate client initialization as an alternative to bearer_token. This enables backward compatibility with v1.x client code that uses: - Client(api_token="...") - AsyncClient(api_token="...") The implementation: - Accepts both api_token and bearer_token parameters - Raises clear error if both are provided - Maps api_token to bearer_token internally - Maintains existing environment variable behavior - Includes comprehensive test coverage --- src/replicate/_client.py | 22 +++++++ tests/test_api_token_compatibility.py | 89 +++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 tests/test_api_token_compatibility.py diff --git a/src/replicate/_client.py b/src/replicate/_client.py index 390a552..237cd87 100644 --- a/src/replicate/_client.py +++ b/src/replicate/_client.py @@ -102,6 +102,7 @@ def __init__( self, *, bearer_token: str | None = None, + api_token: str | None = None, # Legacy compatibility parameter base_url: str | httpx.URL | None = None, timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN, max_retries: int = DEFAULT_MAX_RETRIES, @@ -124,7 +125,17 @@ def __init__( """Construct a new synchronous Replicate client instance. This automatically infers the `bearer_token` argument from the `REPLICATE_API_TOKEN` environment variable if it is not provided. + + For legacy compatibility, you can also pass `api_token` instead of `bearer_token`. """ + # Handle legacy api_token parameter + if api_token is not None and bearer_token is not None: + raise ReplicateError( + "Cannot specify both 'bearer_token' and 'api_token'. Please use 'bearer_token' (recommended) or 'api_token' for legacy compatibility." + ) + if api_token is not None: + bearer_token = api_token + if bearer_token is None: bearer_token = _get_api_token_from_environment() if bearer_token is None: @@ -477,6 +488,7 @@ def __init__( self, *, bearer_token: str | None = None, + api_token: str | None = None, # Legacy compatibility parameter base_url: str | httpx.URL | None = None, timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN, max_retries: int = DEFAULT_MAX_RETRIES, @@ -499,7 +511,17 @@ def __init__( """Construct a new async AsyncReplicate client instance. This automatically infers the `bearer_token` argument from the `REPLICATE_API_TOKEN` environment variable if it is not provided. + + For legacy compatibility, you can also pass `api_token` instead of `bearer_token`. """ + # Handle legacy api_token parameter + if api_token is not None and bearer_token is not None: + raise ReplicateError( + "Cannot specify both 'bearer_token' and 'api_token'. Please use 'bearer_token' (recommended) or 'api_token' for legacy compatibility." + ) + if api_token is not None: + bearer_token = api_token + if bearer_token is None: bearer_token = _get_api_token_from_environment() if bearer_token is None: diff --git a/tests/test_api_token_compatibility.py b/tests/test_api_token_compatibility.py new file mode 100644 index 0000000..3d2ef51 --- /dev/null +++ b/tests/test_api_token_compatibility.py @@ -0,0 +1,89 @@ +"""Tests for api_token legacy compatibility during client instantiation.""" + +from __future__ import annotations + +import os +import pytest + +from replicate import Replicate, AsyncReplicate, ReplicateError +from replicate._client import Client + + +class TestApiTokenCompatibility: + """Test that api_token parameter works as a legacy compatibility option.""" + + def test_sync_client_with_api_token(self) -> None: + """Test that Replicate accepts api_token parameter.""" + client = Replicate(api_token="test_token_123") + assert client.bearer_token == "test_token_123" + + def test_async_client_with_api_token(self) -> None: + """Test that AsyncReplicate accepts api_token parameter.""" + client = AsyncReplicate(api_token="test_token_123") + assert client.bearer_token == "test_token_123" + + def test_sync_client_with_bearer_token(self) -> None: + """Test that Replicate still accepts bearer_token parameter.""" + client = Replicate(bearer_token="test_token_123") + assert client.bearer_token == "test_token_123" + + def test_async_client_with_bearer_token(self) -> None: + """Test that AsyncReplicate still accepts bearer_token parameter.""" + client = AsyncReplicate(bearer_token="test_token_123") + assert client.bearer_token == "test_token_123" + + def test_sync_client_both_tokens_error(self) -> None: + """Test that providing both api_token and bearer_token raises an error.""" + with pytest.raises(ReplicateError, match="Cannot specify both 'bearer_token' and 'api_token'"): + Replicate(api_token="test_api", bearer_token="test_bearer") + + def test_async_client_both_tokens_error(self) -> None: + """Test that providing both api_token and bearer_token raises an error.""" + with pytest.raises(ReplicateError, match="Cannot specify both 'bearer_token' and 'api_token'"): + AsyncReplicate(api_token="test_api", bearer_token="test_bearer") + + def test_sync_client_no_token_with_env(self, monkeypatch: pytest.MonkeyPatch) -> None: + """Test that client reads from environment when no token is provided.""" + monkeypatch.setenv("REPLICATE_API_TOKEN", "env_token_123") + client = Replicate() + assert client.bearer_token == "env_token_123" + + def test_async_client_no_token_with_env(self, monkeypatch: pytest.MonkeyPatch) -> None: + """Test that async client reads from environment when no token is provided.""" + monkeypatch.setenv("REPLICATE_API_TOKEN", "env_token_123") + client = AsyncReplicate() + assert client.bearer_token == "env_token_123" + + def test_sync_client_no_token_no_env(self, monkeypatch: pytest.MonkeyPatch) -> None: + """Test that client raises error when no token is provided and env is not set.""" + monkeypatch.delenv("REPLICATE_API_TOKEN", raising=False) + with pytest.raises(ReplicateError, match="The bearer_token client option must be set"): + Replicate() + + def test_async_client_no_token_no_env(self, monkeypatch: pytest.MonkeyPatch) -> None: + """Test that async client raises error when no token is provided and env is not set.""" + monkeypatch.delenv("REPLICATE_API_TOKEN", raising=False) + with pytest.raises(ReplicateError, match="The bearer_token client option must be set"): + AsyncReplicate() + + def test_legacy_client_alias(self) -> None: + """Test that legacy Client import still works as an alias.""" + assert Client is Replicate + + def test_legacy_client_with_api_token(self) -> None: + """Test that legacy Client alias works with api_token parameter.""" + client = Client(api_token="test_token_123") + assert client.bearer_token == "test_token_123" + assert isinstance(client, Replicate) + + def test_api_token_overrides_env(self, monkeypatch: pytest.MonkeyPatch) -> None: + """Test that explicit api_token overrides environment variable.""" + monkeypatch.setenv("REPLICATE_API_TOKEN", "env_token") + client = Replicate(api_token="explicit_token") + assert client.bearer_token == "explicit_token" + + def test_bearer_token_overrides_env(self, monkeypatch: pytest.MonkeyPatch) -> None: + """Test that explicit bearer_token overrides environment variable.""" + monkeypatch.setenv("REPLICATE_API_TOKEN", "env_token") + client = Replicate(bearer_token="explicit_token") + assert client.bearer_token == "explicit_token" \ No newline at end of file From c25957134868ba40e70b52ce44f0d4f0e1cd2cc5 Mon Sep 17 00:00:00 2001 From: Zeke Sikelianos Date: Tue, 23 Sep 2025 10:00:28 -0700 Subject: [PATCH 2/6] Revert "feat: add api_token parameter support for legacy compatibility" This reverts commit 8c05e64f51460f2dd0587146c0e46be05a1aea51. --- src/replicate/_client.py | 22 ------- tests/test_api_token_compatibility.py | 89 --------------------------- 2 files changed, 111 deletions(-) delete mode 100644 tests/test_api_token_compatibility.py diff --git a/src/replicate/_client.py b/src/replicate/_client.py index 237cd87..390a552 100644 --- a/src/replicate/_client.py +++ b/src/replicate/_client.py @@ -102,7 +102,6 @@ def __init__( self, *, bearer_token: str | None = None, - api_token: str | None = None, # Legacy compatibility parameter base_url: str | httpx.URL | None = None, timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN, max_retries: int = DEFAULT_MAX_RETRIES, @@ -125,17 +124,7 @@ def __init__( """Construct a new synchronous Replicate client instance. This automatically infers the `bearer_token` argument from the `REPLICATE_API_TOKEN` environment variable if it is not provided. - - For legacy compatibility, you can also pass `api_token` instead of `bearer_token`. """ - # Handle legacy api_token parameter - if api_token is not None and bearer_token is not None: - raise ReplicateError( - "Cannot specify both 'bearer_token' and 'api_token'. Please use 'bearer_token' (recommended) or 'api_token' for legacy compatibility." - ) - if api_token is not None: - bearer_token = api_token - if bearer_token is None: bearer_token = _get_api_token_from_environment() if bearer_token is None: @@ -488,7 +477,6 @@ def __init__( self, *, bearer_token: str | None = None, - api_token: str | None = None, # Legacy compatibility parameter base_url: str | httpx.URL | None = None, timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN, max_retries: int = DEFAULT_MAX_RETRIES, @@ -511,17 +499,7 @@ def __init__( """Construct a new async AsyncReplicate client instance. This automatically infers the `bearer_token` argument from the `REPLICATE_API_TOKEN` environment variable if it is not provided. - - For legacy compatibility, you can also pass `api_token` instead of `bearer_token`. """ - # Handle legacy api_token parameter - if api_token is not None and bearer_token is not None: - raise ReplicateError( - "Cannot specify both 'bearer_token' and 'api_token'. Please use 'bearer_token' (recommended) or 'api_token' for legacy compatibility." - ) - if api_token is not None: - bearer_token = api_token - if bearer_token is None: bearer_token = _get_api_token_from_environment() if bearer_token is None: diff --git a/tests/test_api_token_compatibility.py b/tests/test_api_token_compatibility.py deleted file mode 100644 index 3d2ef51..0000000 --- a/tests/test_api_token_compatibility.py +++ /dev/null @@ -1,89 +0,0 @@ -"""Tests for api_token legacy compatibility during client instantiation.""" - -from __future__ import annotations - -import os -import pytest - -from replicate import Replicate, AsyncReplicate, ReplicateError -from replicate._client import Client - - -class TestApiTokenCompatibility: - """Test that api_token parameter works as a legacy compatibility option.""" - - def test_sync_client_with_api_token(self) -> None: - """Test that Replicate accepts api_token parameter.""" - client = Replicate(api_token="test_token_123") - assert client.bearer_token == "test_token_123" - - def test_async_client_with_api_token(self) -> None: - """Test that AsyncReplicate accepts api_token parameter.""" - client = AsyncReplicate(api_token="test_token_123") - assert client.bearer_token == "test_token_123" - - def test_sync_client_with_bearer_token(self) -> None: - """Test that Replicate still accepts bearer_token parameter.""" - client = Replicate(bearer_token="test_token_123") - assert client.bearer_token == "test_token_123" - - def test_async_client_with_bearer_token(self) -> None: - """Test that AsyncReplicate still accepts bearer_token parameter.""" - client = AsyncReplicate(bearer_token="test_token_123") - assert client.bearer_token == "test_token_123" - - def test_sync_client_both_tokens_error(self) -> None: - """Test that providing both api_token and bearer_token raises an error.""" - with pytest.raises(ReplicateError, match="Cannot specify both 'bearer_token' and 'api_token'"): - Replicate(api_token="test_api", bearer_token="test_bearer") - - def test_async_client_both_tokens_error(self) -> None: - """Test that providing both api_token and bearer_token raises an error.""" - with pytest.raises(ReplicateError, match="Cannot specify both 'bearer_token' and 'api_token'"): - AsyncReplicate(api_token="test_api", bearer_token="test_bearer") - - def test_sync_client_no_token_with_env(self, monkeypatch: pytest.MonkeyPatch) -> None: - """Test that client reads from environment when no token is provided.""" - monkeypatch.setenv("REPLICATE_API_TOKEN", "env_token_123") - client = Replicate() - assert client.bearer_token == "env_token_123" - - def test_async_client_no_token_with_env(self, monkeypatch: pytest.MonkeyPatch) -> None: - """Test that async client reads from environment when no token is provided.""" - monkeypatch.setenv("REPLICATE_API_TOKEN", "env_token_123") - client = AsyncReplicate() - assert client.bearer_token == "env_token_123" - - def test_sync_client_no_token_no_env(self, monkeypatch: pytest.MonkeyPatch) -> None: - """Test that client raises error when no token is provided and env is not set.""" - monkeypatch.delenv("REPLICATE_API_TOKEN", raising=False) - with pytest.raises(ReplicateError, match="The bearer_token client option must be set"): - Replicate() - - def test_async_client_no_token_no_env(self, monkeypatch: pytest.MonkeyPatch) -> None: - """Test that async client raises error when no token is provided and env is not set.""" - monkeypatch.delenv("REPLICATE_API_TOKEN", raising=False) - with pytest.raises(ReplicateError, match="The bearer_token client option must be set"): - AsyncReplicate() - - def test_legacy_client_alias(self) -> None: - """Test that legacy Client import still works as an alias.""" - assert Client is Replicate - - def test_legacy_client_with_api_token(self) -> None: - """Test that legacy Client alias works with api_token parameter.""" - client = Client(api_token="test_token_123") - assert client.bearer_token == "test_token_123" - assert isinstance(client, Replicate) - - def test_api_token_overrides_env(self, monkeypatch: pytest.MonkeyPatch) -> None: - """Test that explicit api_token overrides environment variable.""" - monkeypatch.setenv("REPLICATE_API_TOKEN", "env_token") - client = Replicate(api_token="explicit_token") - assert client.bearer_token == "explicit_token" - - def test_bearer_token_overrides_env(self, monkeypatch: pytest.MonkeyPatch) -> None: - """Test that explicit bearer_token overrides environment variable.""" - monkeypatch.setenv("REPLICATE_API_TOKEN", "env_token") - client = Replicate(bearer_token="explicit_token") - assert client.bearer_token == "explicit_token" \ No newline at end of file From 3223abfcc308e1eeee45eea0549623fdad5a583f Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 18 Sep 2025 14:55:08 +0000 Subject: [PATCH 3/6] chore(types): change optional parameter type from NotGiven to Omit --- src/replicate/__init__.py | 4 +- src/replicate/_base_client.py | 18 ++++---- src/replicate/_qs.py | 14 +++---- src/replicate/_types.py | 29 ++++++++----- src/replicate/_utils/_transform.py | 4 +- src/replicate/_utils/_utils.py | 8 ++-- src/replicate/resources/account.py | 6 +-- src/replicate/resources/collections.py | 10 ++--- .../resources/deployments/deployments.py | 38 ++++++++--------- .../resources/deployments/predictions.py | 22 +++++----- src/replicate/resources/files.py | 34 +++++++-------- src/replicate/resources/hardware.py | 6 +-- src/replicate/resources/models/examples.py | 6 +-- src/replicate/resources/models/models.py | 42 +++++++++---------- src/replicate/resources/models/predictions.py | 6 +-- src/replicate/resources/models/readme.py | 6 +-- src/replicate/resources/models/versions.py | 14 +++---- src/replicate/resources/trainings.py | 26 ++++++------ .../resources/webhooks/default/secret.py | 6 +-- tests/test_transform.py | 11 ++++- 20 files changed, 163 insertions(+), 147 deletions(-) diff --git a/src/replicate/__init__.py b/src/replicate/__init__.py index f424c6b..1cfff56 100644 --- a/src/replicate/__init__.py +++ b/src/replicate/__init__.py @@ -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, @@ -54,7 +54,9 @@ "ProxiesTypes", "NotGiven", "NOT_GIVEN", + "not_given", "Omit", + "omit", "ReplicateError", "APIError", "APIStatusError", diff --git a/src/replicate/_base_client.py b/src/replicate/_base_client.py index 0c06232..db19212 100644 --- a/src/replicate/_base_client.py +++ b/src/replicate/_base_client.py @@ -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, @@ -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 @@ -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 @@ -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) @@ -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, @@ -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, @@ -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 = {} diff --git a/src/replicate/_qs.py b/src/replicate/_qs.py index 274320c..ada6fd3 100644 --- a/src/replicate/_qs.py +++ b/src/replicate/_qs.py @@ -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") @@ -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( @@ -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, @@ -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 diff --git a/src/replicate/_types.py b/src/replicate/_types.py index 11aa377..4a8e5b2 100644 --- a/src/replicate/_types.py +++ b/src/replicate/_types.py @@ -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 ``` """ @@ -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 @@ -156,8 +160,8 @@ 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}) ``` """ @@ -165,6 +169,9 @@ def __bool__(self) -> Literal[False]: return False +omit = Omit() + + @runtime_checkable class ModelBuilderProtocol(Protocol): @classmethod diff --git a/src/replicate/_utils/_transform.py b/src/replicate/_utils/_transform.py index c19124f..5207549 100644 --- a/src/replicate/_utils/_transform.py +++ b/src/replicate/_utils/_transform.py @@ -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 @@ -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 diff --git a/src/replicate/_utils/_utils.py b/src/replicate/_utils/_utils.py index f081859..50d5926 100644 --- a/src/replicate/_utils/_utils.py +++ b/src/replicate/_utils/_utils.py @@ -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, ...]) @@ -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 [] @@ -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. diff --git a/src/replicate/resources/account.py b/src/replicate/resources/account.py index 304cc64..411545e 100644 --- a/src/replicate/resources/account.py +++ b/src/replicate/resources/account.py @@ -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 ( @@ -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 @@ -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 diff --git a/src/replicate/resources/collections.py b/src/replicate/resources/collections.py index 3852d35..1a89c01 100644 --- a/src/replicate/resources/collections.py +++ b/src/replicate/resources/collections.py @@ -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 ( @@ -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: @@ -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: @@ -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: @@ -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: diff --git a/src/replicate/resources/deployments/deployments.py b/src/replicate/resources/deployments/deployments.py index 613d0e9..604e501 100644 --- a/src/replicate/resources/deployments/deployments.py +++ b/src/replicate/resources/deployments/deployments.py @@ -5,7 +5,7 @@ import httpx from ...types import deployment_create_params, deployment_update_params -from ..._types import NOT_GIVEN, Body, Query, Headers, NoneType, NotGiven +from ..._types import Body, Omit, Query, Headers, NoneType, NotGiven, omit, not_given from ..._utils import maybe_transform, async_maybe_transform from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource @@ -71,7 +71,7 @@ def create( 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, ) -> DeploymentCreateResponse: """ Create a new deployment: @@ -167,16 +167,16 @@ def update( *, deployment_owner: str, deployment_name: str, - hardware: str | NotGiven = NOT_GIVEN, - max_instances: int | NotGiven = NOT_GIVEN, - min_instances: int | NotGiven = NOT_GIVEN, - version: str | NotGiven = NOT_GIVEN, + hardware: str | Omit = omit, + max_instances: int | Omit = omit, + min_instances: int | Omit = omit, + version: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. 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, ) -> DeploymentUpdateResponse: """ Update properties of an existing deployment, including hardware, min/max @@ -271,7 +271,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[DeploymentListResponse]: """ Get a list of deployments associated with the current account, including the @@ -338,7 +338,7 @@ def delete( 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, ) -> None: """ Delete a deployment @@ -390,7 +390,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, ) -> DeploymentGetResponse: """ Get information about a deployment by name including the current release. @@ -490,7 +490,7 @@ async def create( 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, ) -> DeploymentCreateResponse: """ Create a new deployment: @@ -586,16 +586,16 @@ async def update( *, deployment_owner: str, deployment_name: str, - hardware: str | NotGiven = NOT_GIVEN, - max_instances: int | NotGiven = NOT_GIVEN, - min_instances: int | NotGiven = NOT_GIVEN, - version: str | NotGiven = NOT_GIVEN, + hardware: str | Omit = omit, + max_instances: int | Omit = omit, + min_instances: int | Omit = omit, + version: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. 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, ) -> DeploymentUpdateResponse: """ Update properties of an existing deployment, including hardware, min/max @@ -690,7 +690,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[DeploymentListResponse, AsyncCursorURLPage[DeploymentListResponse]]: """ Get a list of deployments associated with the current account, including the @@ -757,7 +757,7 @@ async def delete( 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, ) -> None: """ Delete a deployment @@ -809,7 +809,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, ) -> DeploymentGetResponse: """ Get information about a deployment by name including the current release. diff --git a/src/replicate/resources/deployments/predictions.py b/src/replicate/resources/deployments/predictions.py index d4eb71f..572ba33 100644 --- a/src/replicate/resources/deployments/predictions.py +++ b/src/replicate/resources/deployments/predictions.py @@ -7,7 +7,7 @@ import httpx -from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven +from ..._types import Body, Omit, Query, Headers, NotGiven, omit, not_given from ..._utils import maybe_transform, strip_not_given, async_maybe_transform from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource @@ -50,16 +50,16 @@ def create( deployment_owner: str, deployment_name: str, input: object, - stream: bool | NotGiven = NOT_GIVEN, - webhook: str | NotGiven = NOT_GIVEN, - webhook_events_filter: List[Literal["start", "output", "logs", "completed"]] | NotGiven = NOT_GIVEN, - prefer: str | NotGiven = NOT_GIVEN, + stream: bool | Omit = omit, + webhook: str | Omit = omit, + webhook_events_filter: List[Literal["start", "output", "logs", "completed"]] | Omit = omit, + prefer: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. 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, ) -> Prediction: """ Create a prediction for the deployment and inputs you provide. @@ -207,16 +207,16 @@ async def create( deployment_owner: str, deployment_name: str, input: object, - stream: bool | NotGiven = NOT_GIVEN, - webhook: str | NotGiven = NOT_GIVEN, - webhook_events_filter: List[Literal["start", "output", "logs", "completed"]] | NotGiven = NOT_GIVEN, - prefer: str | NotGiven = NOT_GIVEN, + stream: bool | Omit = omit, + webhook: str | Omit = omit, + webhook_events_filter: List[Literal["start", "output", "logs", "completed"]] | Omit = omit, + prefer: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. 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, ) -> Prediction: """ Create a prediction for the deployment and inputs you provide. diff --git a/src/replicate/resources/files.py b/src/replicate/resources/files.py index a9f5034..447f03c 100644 --- a/src/replicate/resources/files.py +++ b/src/replicate/resources/files.py @@ -7,7 +7,7 @@ import httpx from ..types import file_create_params, file_download_params -from .._types import NOT_GIVEN, Body, Query, Headers, NoneType, NotGiven, FileTypes +from .._types import Body, Omit, Query, Headers, NoneType, NotGiven, FileTypes, omit, not_given from .._utils import extract_files, maybe_transform, deepcopy_minimal, async_maybe_transform from .._compat import cached_property from .._resource import SyncAPIResource, AsyncAPIResource @@ -58,15 +58,15 @@ def create( self, *, content: FileTypes, - filename: str | NotGiven = NOT_GIVEN, - metadata: object | NotGiven = NOT_GIVEN, - type: str | NotGiven = NOT_GIVEN, + filename: str | Omit = omit, + metadata: object | Omit = omit, + type: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. 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, ) -> FileCreateResponse: """ Create a file by uploading its content and optional metadata. @@ -138,7 +138,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[FileListResponse]: """ Get a paginated list of all files created by the user or organization associated @@ -173,7 +173,7 @@ def delete( 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, ) -> None: """Delete a file. @@ -220,7 +220,7 @@ def download( 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, ) -> BinaryAPIResponse: """ Download a file by providing the file owner, access expiry, and a valid @@ -279,7 +279,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, ) -> FileGetResponse: """ Get the details of a file. @@ -336,15 +336,15 @@ async def create( self, *, content: FileTypes, - filename: str | NotGiven = NOT_GIVEN, - metadata: object | NotGiven = NOT_GIVEN, - type: str | NotGiven = NOT_GIVEN, + filename: str | Omit = omit, + metadata: object | Omit = omit, + type: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. 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, ) -> FileCreateResponse: """ Create a file by uploading its content and optional metadata. @@ -416,7 +416,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[FileListResponse, AsyncCursorURLPage[FileListResponse]]: """ Get a paginated list of all files created by the user or organization associated @@ -451,7 +451,7 @@ async def delete( 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, ) -> None: """Delete a file. @@ -498,7 +498,7 @@ async def download( 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, ) -> AsyncBinaryAPIResponse: """ Download a file by providing the file owner, access expiry, and a valid @@ -557,7 +557,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, ) -> FileGetResponse: """ Get the details of a file. diff --git a/src/replicate/resources/hardware.py b/src/replicate/resources/hardware.py index 3cea6e4..2b8e361 100644 --- a/src/replicate/resources/hardware.py +++ b/src/replicate/resources/hardware.py @@ -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 ( @@ -47,7 +47,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, ) -> HardwareListResponse: """ Example cURL request: @@ -106,7 +106,7 @@ async 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, ) -> HardwareListResponse: """ Example cURL request: diff --git a/src/replicate/resources/models/examples.py b/src/replicate/resources/models/examples.py index 4425953..0bc5539 100644 --- a/src/replicate/resources/models/examples.py +++ b/src/replicate/resources/models/examples.py @@ -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 ( @@ -50,7 +50,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[Prediction]: """ List @@ -138,7 +138,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[Prediction, AsyncCursorURLPage[Prediction]]: """ List diff --git a/src/replicate/resources/models/models.py b/src/replicate/resources/models/models.py index 671f482..b9fa139 100644 --- a/src/replicate/resources/models/models.py +++ b/src/replicate/resources/models/models.py @@ -15,7 +15,7 @@ AsyncReadmeResourceWithStreamingResponse, ) from ...types import model_create_params, model_search_params -from ..._types import NOT_GIVEN, Body, Query, Headers, NoneType, NotGiven +from ..._types import Body, Omit, Query, Headers, NoneType, NotGiven, omit, not_given from ..._utils import maybe_transform, async_maybe_transform from .examples import ( ExamplesResource, @@ -102,17 +102,17 @@ def create( name: str, owner: str, visibility: Literal["public", "private"], - cover_image_url: str | NotGiven = NOT_GIVEN, - description: str | NotGiven = NOT_GIVEN, - github_url: str | NotGiven = NOT_GIVEN, - license_url: str | NotGiven = NOT_GIVEN, - paper_url: str | NotGiven = NOT_GIVEN, + cover_image_url: str | Omit = omit, + description: str | Omit = omit, + github_url: str | Omit = omit, + license_url: str | Omit = omit, + paper_url: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. 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, ) -> ModelCreateResponse: """ Create a model. @@ -214,7 +214,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[ModelListResponse]: """ Get a paginated list of public models. @@ -251,7 +251,7 @@ def delete( 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, ) -> None: """ Delete a model @@ -307,7 +307,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, ) -> ModelGetResponse: """ Example cURL request: @@ -414,7 +414,7 @@ def search( 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[ModelSearchResponse]: """ Get a list of public models matching a search query. @@ -501,17 +501,17 @@ async def create( name: str, owner: str, visibility: Literal["public", "private"], - cover_image_url: str | NotGiven = NOT_GIVEN, - description: str | NotGiven = NOT_GIVEN, - github_url: str | NotGiven = NOT_GIVEN, - license_url: str | NotGiven = NOT_GIVEN, - paper_url: str | NotGiven = NOT_GIVEN, + cover_image_url: str | Omit = omit, + description: str | Omit = omit, + github_url: str | Omit = omit, + license_url: str | Omit = omit, + paper_url: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. 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, ) -> ModelCreateResponse: """ Create a model. @@ -613,7 +613,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[ModelListResponse, AsyncCursorURLPage[ModelListResponse]]: """ Get a paginated list of public models. @@ -650,7 +650,7 @@ async def delete( 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, ) -> None: """ Delete a model @@ -706,7 +706,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, ) -> ModelGetResponse: """ Example cURL request: @@ -813,7 +813,7 @@ def search( 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[ModelSearchResponse, AsyncCursorURLPage[ModelSearchResponse]]: """ Get a list of public models matching a search query. diff --git a/src/replicate/resources/models/predictions.py b/src/replicate/resources/models/predictions.py index dcfb784..a5f4b06 100644 --- a/src/replicate/resources/models/predictions.py +++ b/src/replicate/resources/models/predictions.py @@ -9,7 +9,7 @@ from replicate.lib._files import FileEncodingStrategy, encode_json, async_encode_json -from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven +from ..._types import Body, Omit, Query, Headers, NotGiven, omit, not_given from ..._utils import maybe_transform, strip_not_given, async_maybe_transform from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource @@ -62,7 +62,7 @@ def create( 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, ) -> Prediction: """ Create a prediction using an @@ -224,7 +224,7 @@ async def create( 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, ) -> Prediction: """ Create a prediction using an diff --git a/src/replicate/resources/models/readme.py b/src/replicate/resources/models/readme.py index 53d9f28..6637f77 100644 --- a/src/replicate/resources/models/readme.py +++ b/src/replicate/resources/models/readme.py @@ -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 ( @@ -48,7 +48,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, ) -> str: """ Get the README content for a model. @@ -122,7 +122,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, ) -> str: """ Get the README content for a model. diff --git a/src/replicate/resources/models/versions.py b/src/replicate/resources/models/versions.py index 13a0f1b..d13473e 100644 --- a/src/replicate/resources/models/versions.py +++ b/src/replicate/resources/models/versions.py @@ -4,7 +4,7 @@ import httpx -from ..._types import NOT_GIVEN, Body, Query, Headers, NoneType, NotGiven +from ..._types import Body, Query, Headers, NoneType, NotGiven, not_given from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource from ..._response import ( @@ -51,7 +51,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[VersionListResponse]: """ Example cURL request: @@ -113,7 +113,7 @@ def delete( 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, ) -> None: """ Delete a model version and all associated predictions, including all output @@ -176,7 +176,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, ) -> VersionGetResponse: """ Example cURL request: @@ -290,7 +290,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[VersionListResponse, AsyncCursorURLPage[VersionListResponse]]: """ Example cURL request: @@ -352,7 +352,7 @@ async def delete( 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, ) -> None: """ Delete a model version and all associated predictions, including all output @@ -415,7 +415,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, ) -> VersionGetResponse: """ Example cURL request: diff --git a/src/replicate/resources/trainings.py b/src/replicate/resources/trainings.py index 033c21b..67600a9 100644 --- a/src/replicate/resources/trainings.py +++ b/src/replicate/resources/trainings.py @@ -8,7 +8,7 @@ import httpx from ..types import training_create_params -from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven +from .._types import Body, Omit, Query, Headers, NotGiven, omit, not_given from .._utils import maybe_transform, async_maybe_transform from .._compat import cached_property from .._resource import SyncAPIResource, AsyncAPIResource @@ -56,14 +56,14 @@ def create( version_id: str, destination: str, input: object, - webhook: str | NotGiven = NOT_GIVEN, - webhook_events_filter: List[Literal["start", "output", "logs", "completed"]] | NotGiven = NOT_GIVEN, + webhook: str | Omit = omit, + webhook_events_filter: List[Literal["start", "output", "logs", "completed"]] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. 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, ) -> TrainingCreateResponse: """ Start a new training of the model version you specify. @@ -207,7 +207,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[TrainingListResponse]: """ Get a paginated list of all trainings created by the user or organization @@ -293,7 +293,7 @@ def cancel( 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, ) -> TrainingCancelResponse: """ Cancel a training @@ -326,7 +326,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, ) -> TrainingGetResponse: """ Get the current state of a training. @@ -440,14 +440,14 @@ async def create( version_id: str, destination: str, input: object, - webhook: str | NotGiven = NOT_GIVEN, - webhook_events_filter: List[Literal["start", "output", "logs", "completed"]] | NotGiven = NOT_GIVEN, + webhook: str | Omit = omit, + webhook_events_filter: List[Literal["start", "output", "logs", "completed"]] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. 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, ) -> TrainingCreateResponse: """ Start a new training of the model version you specify. @@ -591,7 +591,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[TrainingListResponse, AsyncCursorURLPage[TrainingListResponse]]: """ Get a paginated list of all trainings created by the user or organization @@ -677,7 +677,7 @@ async def cancel( 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, ) -> TrainingCancelResponse: """ Cancel a training @@ -710,7 +710,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, ) -> TrainingGetResponse: """ Get the current state of a training. diff --git a/src/replicate/resources/webhooks/default/secret.py b/src/replicate/resources/webhooks/default/secret.py index 9430140..18aea1b 100644 --- a/src/replicate/resources/webhooks/default/secret.py +++ b/src/replicate/resources/webhooks/default/secret.py @@ -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 ( @@ -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, ) -> SecretGetResponse: """Get the signing secret for the default webhook endpoint. @@ -107,7 +107,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, ) -> SecretGetResponse: """Get the signing secret for the default webhook endpoint. diff --git a/tests/test_transform.py b/tests/test_transform.py index 2bf92ec..5d88302 100644 --- a/tests/test_transform.py +++ b/tests/test_transform.py @@ -8,7 +8,7 @@ import pytest -from replicate._types import NOT_GIVEN, Base64FileInput +from replicate._types import Base64FileInput, omit, not_given from replicate._utils import ( PropertyInfo, transform as _transform, @@ -450,4 +450,11 @@ async def test_transform_skipping(use_async: bool) -> None: @pytest.mark.asyncio async def test_strips_notgiven(use_async: bool) -> None: assert await transform({"foo_bar": "bar"}, Foo1, use_async) == {"fooBar": "bar"} - assert await transform({"foo_bar": NOT_GIVEN}, Foo1, use_async) == {} + assert await transform({"foo_bar": not_given}, Foo1, use_async) == {} + + +@parametrize +@pytest.mark.asyncio +async def test_strips_omit(use_async: bool) -> None: + assert await transform({"foo_bar": "bar"}, Foo1, use_async) == {"fooBar": "bar"} + assert await transform({"foo_bar": omit}, Foo1, use_async) == {} From d1bebb6109cf3c79de4f3796eb65ec40ce7b592d Mon Sep 17 00:00:00 2001 From: Robert Craigie Date: Mon, 29 Sep 2025 11:46:15 +0100 Subject: [PATCH 4/6] chore(internal): update formatting --- src/replicate/resources/models/predictions.py | 2 +- tests/test_legacy_exceptions.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/replicate/resources/models/predictions.py b/src/replicate/resources/models/predictions.py index a5f4b06..6abd411 100644 --- a/src/replicate/resources/models/predictions.py +++ b/src/replicate/resources/models/predictions.py @@ -9,7 +9,7 @@ from replicate.lib._files import FileEncodingStrategy, encode_json, async_encode_json -from ..._types import Body, Omit, Query, Headers, NotGiven, omit, not_given +from ..._types import Body, Query, Headers, NotGiven, not_given from ..._utils import maybe_transform, strip_not_given, async_maybe_transform from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource diff --git a/tests/test_legacy_exceptions.py b/tests/test_legacy_exceptions.py index e07ee72..df9ec48 100644 --- a/tests/test_legacy_exceptions.py +++ b/tests/test_legacy_exceptions.py @@ -75,4 +75,4 @@ def test_exception_module_all_exports(): # Also verify they can all be accessed for exc_name in expected_exceptions: - assert hasattr(replicate.exceptions, exc_name) \ No newline at end of file + assert hasattr(replicate.exceptions, exc_name) From 6f1011624cd05a82422386332917748fc821fdc6 Mon Sep 17 00:00:00 2001 From: Robert Craigie Date: Mon, 29 Sep 2025 11:47:44 +0100 Subject: [PATCH 5/6] fix(predictions): use Omit instead of NotGiven --- src/replicate/resources/models/predictions.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/replicate/resources/models/predictions.py b/src/replicate/resources/models/predictions.py index 6abd411..f88e551 100644 --- a/src/replicate/resources/models/predictions.py +++ b/src/replicate/resources/models/predictions.py @@ -9,7 +9,7 @@ from replicate.lib._files import FileEncodingStrategy, encode_json, async_encode_json -from ..._types import Body, Query, Headers, NotGiven, not_given +from ..._types import Body, Omit, Query, Headers, NotGiven, omit, not_given from ..._utils import maybe_transform, strip_not_given, async_maybe_transform from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource @@ -52,10 +52,10 @@ def create( model_owner: str, model_name: str, input: object, - stream: bool | NotGiven = NOT_GIVEN, - webhook: str | NotGiven = NOT_GIVEN, - webhook_events_filter: List[Literal["start", "output", "logs", "completed"]] | NotGiven = NOT_GIVEN, - prefer: str | NotGiven = NOT_GIVEN, + stream: bool | Omit = omit, + webhook: str | Omit = omit, + webhook_events_filter: List[Literal["start", "output", "logs", "completed"]] | Omit = omit, + prefer: str | Omit = omit, file_encoding_strategy: Optional["FileEncodingStrategy"] = None, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. @@ -214,10 +214,10 @@ async def create( model_owner: str, model_name: str, input: object, - stream: bool | NotGiven = NOT_GIVEN, - webhook: str | NotGiven = NOT_GIVEN, - webhook_events_filter: List[Literal["start", "output", "logs", "completed"]] | NotGiven = NOT_GIVEN, - prefer: str | NotGiven = NOT_GIVEN, + stream: bool | Omit = omit, + webhook: str | Omit = omit, + webhook_events_filter: List[Literal["start", "output", "logs", "completed"]] | Omit = omit, + prefer: str | Omit = omit, file_encoding_strategy: Optional["FileEncodingStrategy"] = None, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. From 55a06969a8c5c0d9c59a3246b2f0a58dac079205 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 29 Sep 2025 10:48:07 +0000 Subject: [PATCH 6/6] release: 2.0.0-alpha.27 --- .release-please-manifest.json | 2 +- CHANGELOG.md | 20 ++++++++++++++++++++ pyproject.toml | 2 +- src/replicate/_version.py | 2 +- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 01c33a5..ec9417a 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "2.0.0-alpha.26" + ".": "2.0.0-alpha.27" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 2bbfc35..1dae4bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/pyproject.toml b/pyproject.toml index 044be7f..9ba41af 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" diff --git a/src/replicate/_version.py b/src/replicate/_version.py index 52084c8..da0284e 100644 --- a/src/replicate/_version.py +++ b/src/replicate/_version.py @@ -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