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 @@
{
".": "0.10.0"
".": "0.11.0"
}
8 changes: 4 additions & 4 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 41
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-a7c1df5070fe59642d7a1f168aa902a468227752bfc930cbf38930f7c205dbb6.yml
openapi_spec_hash: eab65e39aef4f0a0952b82adeecf6b5b
config_hash: 5de78bc29ac060562575cb54bb26826c
configured_endpoints: 46
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-e98d46c55826cdf541a9ee0df04ce92806ac6d4d92957ae79f897270b7d85b23.yml
openapi_spec_hash: 8a1af54fc0a4417165b8a52e6354b685
config_hash: 043ddc54629c6d8b889123770cb4769f
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Changelog

## 0.11.0 (2025-09-04)

Full Changelog: [v0.10.0...v0.11.0](https://github.com/onkernel/kernel-python-sdk/compare/v0.10.0...v0.11.0)

### Features

* **api:** adding support for browser profiles ([52bcaa1](https://github.com/onkernel/kernel-python-sdk/commit/52bcaa136a1792fd9a9d06f3f81a622a53a89e9a))
* improve future compat with pydantic v3 ([72b0862](https://github.com/onkernel/kernel-python-sdk/commit/72b086280f3742cf34ddb7afe2082c4eee37c80a))
* **types:** replace List[str] with SequenceNotStr in params ([688059b](https://github.com/onkernel/kernel-python-sdk/commit/688059b50a261e84fd1ae125b65a1bd56b6243d2))


### Chores

* **internal:** add Sequence related utils ([e833554](https://github.com/onkernel/kernel-python-sdk/commit/e833554e7f222acf915621d5f0fdd2eef17e0738))

## 0.10.0 (2025-08-27)

Full Changelog: [v0.9.1...v0.10.0](https://github.com/onkernel/kernel-python-sdk/compare/v0.9.1...v0.10.0)
Expand Down
17 changes: 17 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Types:
```python
from kernel.types import (
BrowserPersistence,
Profile,
BrowserCreateResponse,
BrowserRetrieveResponse,
BrowserListResponse,
Expand Down Expand Up @@ -161,3 +162,19 @@ Methods:
Methods:

- <code title="get /browsers/{id}/logs/stream">client.browsers.logs.<a href="./src/kernel/resources/browsers/logs.py">stream</a>(id, \*\*<a href="src/kernel/types/browsers/log_stream_params.py">params</a>) -> <a href="./src/kernel/types/shared/log_event.py">LogEvent</a></code>

# Profiles

Types:

```python
from kernel.types import ProfileListResponse
```

Methods:

- <code title="post /profiles">client.profiles.<a href="./src/kernel/resources/profiles.py">create</a>(\*\*<a href="src/kernel/types/profile_create_params.py">params</a>) -> <a href="./src/kernel/types/profile.py">Profile</a></code>
- <code title="get /profiles/{id_or_name}">client.profiles.<a href="./src/kernel/resources/profiles.py">retrieve</a>(id_or_name) -> <a href="./src/kernel/types/profile.py">Profile</a></code>
- <code title="get /profiles">client.profiles.<a href="./src/kernel/resources/profiles.py">list</a>() -> <a href="./src/kernel/types/profile_list_response.py">ProfileListResponse</a></code>
- <code title="delete /profiles/{id_or_name}">client.profiles.<a href="./src/kernel/resources/profiles.py">delete</a>(id_or_name) -> None</code>
- <code title="get /profiles/{id_or_name}/download">client.profiles.<a href="./src/kernel/resources/profiles.py">download</a>(id_or_name) -> BinaryAPIResponse</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 = "kernel"
version = "0.10.0"
version = "0.11.0"
description = "The official Python library for the kernel API"
dynamic = ["readme"]
license = "Apache-2.0"
Expand Down
6 changes: 3 additions & 3 deletions src/kernel/_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
ModelBuilderProtocol,
)
from ._utils import is_dict, is_list, asyncify, is_given, lru_cache, is_mapping
from ._compat import PYDANTIC_V2, model_copy, model_dump
from ._compat import PYDANTIC_V1, model_copy, model_dump
from ._models import GenericModel, FinalRequestOptions, validate_type, construct_type
from ._response import (
APIResponse,
Expand Down Expand Up @@ -232,7 +232,7 @@ def _set_private_attributes(
model: Type[_T],
options: FinalRequestOptions,
) -> None:
if PYDANTIC_V2 and getattr(self, "__pydantic_private__", None) is None:
if (not PYDANTIC_V1) and getattr(self, "__pydantic_private__", None) is None:
self.__pydantic_private__ = {}

self._model = model
Expand Down Expand Up @@ -320,7 +320,7 @@ def _set_private_attributes(
client: AsyncAPIClient,
options: FinalRequestOptions,
) -> None:
if PYDANTIC_V2 and getattr(self, "__pydantic_private__", None) is None:
if (not PYDANTIC_V1) and getattr(self, "__pydantic_private__", None) is None:
self.__pydantic_private__ = {}

self._model = model
Expand Down
10 changes: 9 additions & 1 deletion src/kernel/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
)
from ._utils import is_given, get_async_library
from ._version import __version__
from .resources import apps, deployments, invocations
from .resources import apps, profiles, deployments, invocations
from ._streaming import Stream as Stream, AsyncStream as AsyncStream
from ._exceptions import KernelError, APIStatusError
from ._base_client import (
Expand Down Expand Up @@ -54,6 +54,7 @@ class Kernel(SyncAPIClient):
apps: apps.AppsResource
invocations: invocations.InvocationsResource
browsers: browsers.BrowsersResource
profiles: profiles.ProfilesResource
with_raw_response: KernelWithRawResponse
with_streaming_response: KernelWithStreamedResponse

Expand Down Expand Up @@ -139,6 +140,7 @@ def __init__(
self.apps = apps.AppsResource(self)
self.invocations = invocations.InvocationsResource(self)
self.browsers = browsers.BrowsersResource(self)
self.profiles = profiles.ProfilesResource(self)
self.with_raw_response = KernelWithRawResponse(self)
self.with_streaming_response = KernelWithStreamedResponse(self)

Expand Down Expand Up @@ -254,6 +256,7 @@ class AsyncKernel(AsyncAPIClient):
apps: apps.AsyncAppsResource
invocations: invocations.AsyncInvocationsResource
browsers: browsers.AsyncBrowsersResource
profiles: profiles.AsyncProfilesResource
with_raw_response: AsyncKernelWithRawResponse
with_streaming_response: AsyncKernelWithStreamedResponse

Expand Down Expand Up @@ -339,6 +342,7 @@ def __init__(
self.apps = apps.AsyncAppsResource(self)
self.invocations = invocations.AsyncInvocationsResource(self)
self.browsers = browsers.AsyncBrowsersResource(self)
self.profiles = profiles.AsyncProfilesResource(self)
self.with_raw_response = AsyncKernelWithRawResponse(self)
self.with_streaming_response = AsyncKernelWithStreamedResponse(self)

Expand Down Expand Up @@ -455,6 +459,7 @@ def __init__(self, client: Kernel) -> None:
self.apps = apps.AppsResourceWithRawResponse(client.apps)
self.invocations = invocations.InvocationsResourceWithRawResponse(client.invocations)
self.browsers = browsers.BrowsersResourceWithRawResponse(client.browsers)
self.profiles = profiles.ProfilesResourceWithRawResponse(client.profiles)


class AsyncKernelWithRawResponse:
Expand All @@ -463,6 +468,7 @@ def __init__(self, client: AsyncKernel) -> None:
self.apps = apps.AsyncAppsResourceWithRawResponse(client.apps)
self.invocations = invocations.AsyncInvocationsResourceWithRawResponse(client.invocations)
self.browsers = browsers.AsyncBrowsersResourceWithRawResponse(client.browsers)
self.profiles = profiles.AsyncProfilesResourceWithRawResponse(client.profiles)


class KernelWithStreamedResponse:
Expand All @@ -471,6 +477,7 @@ def __init__(self, client: Kernel) -> None:
self.apps = apps.AppsResourceWithStreamingResponse(client.apps)
self.invocations = invocations.InvocationsResourceWithStreamingResponse(client.invocations)
self.browsers = browsers.BrowsersResourceWithStreamingResponse(client.browsers)
self.profiles = profiles.ProfilesResourceWithStreamingResponse(client.profiles)


class AsyncKernelWithStreamedResponse:
Expand All @@ -479,6 +486,7 @@ def __init__(self, client: AsyncKernel) -> None:
self.apps = apps.AsyncAppsResourceWithStreamingResponse(client.apps)
self.invocations = invocations.AsyncInvocationsResourceWithStreamingResponse(client.invocations)
self.browsers = browsers.AsyncBrowsersResourceWithStreamingResponse(client.browsers)
self.profiles = profiles.AsyncProfilesResourceWithStreamingResponse(client.profiles)


Client = Kernel
Expand Down
96 changes: 48 additions & 48 deletions src/kernel/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
_T = TypeVar("_T")
_ModelT = TypeVar("_ModelT", bound=pydantic.BaseModel)

# --------------- Pydantic v2 compatibility ---------------
# --------------- Pydantic v2, v3 compatibility ---------------

# Pyright incorrectly reports some of our functions as overriding a method when they don't
# pyright: reportIncompatibleMethodOverride=false

PYDANTIC_V2 = pydantic.VERSION.startswith("2.")
PYDANTIC_V1 = pydantic.VERSION.startswith("1.")

# v1 re-exports
if TYPE_CHECKING:

def parse_date(value: date | StrBytesIntFloat) -> date: # noqa: ARG001
Expand All @@ -44,90 +43,92 @@ def is_typeddict(type_: type[Any]) -> bool: # noqa: ARG001
...

else:
if PYDANTIC_V2:
from pydantic.v1.typing import (
# v1 re-exports
if PYDANTIC_V1:
from pydantic.typing import (
get_args as get_args,
is_union as is_union,
get_origin as get_origin,
is_typeddict as is_typeddict,
is_literal_type as is_literal_type,
)
from pydantic.v1.datetime_parse import parse_date as parse_date, parse_datetime as parse_datetime
from pydantic.datetime_parse import parse_date as parse_date, parse_datetime as parse_datetime
else:
from pydantic.typing import (
from ._utils import (
get_args as get_args,
is_union as is_union,
get_origin as get_origin,
parse_date as parse_date,
is_typeddict as is_typeddict,
parse_datetime as parse_datetime,
is_literal_type as is_literal_type,
)
from pydantic.datetime_parse import parse_date as parse_date, parse_datetime as parse_datetime


# refactored config
if TYPE_CHECKING:
from pydantic import ConfigDict as ConfigDict
else:
if PYDANTIC_V2:
from pydantic import ConfigDict
else:
if PYDANTIC_V1:
# TODO: provide an error message here?
ConfigDict = None
else:
from pydantic import ConfigDict as ConfigDict


# renamed methods / properties
def parse_obj(model: type[_ModelT], value: object) -> _ModelT:
if PYDANTIC_V2:
return model.model_validate(value)
else:
if PYDANTIC_V1:
return cast(_ModelT, model.parse_obj(value)) # pyright: ignore[reportDeprecated, reportUnnecessaryCast]
else:
return model.model_validate(value)


def field_is_required(field: FieldInfo) -> bool:
if PYDANTIC_V2:
return field.is_required()
return field.required # type: ignore
if PYDANTIC_V1:
return field.required # type: ignore
return field.is_required()


def field_get_default(field: FieldInfo) -> Any:
value = field.get_default()
if PYDANTIC_V2:
from pydantic_core import PydanticUndefined

if value == PydanticUndefined:
return None
if PYDANTIC_V1:
return value
from pydantic_core import PydanticUndefined

if value == PydanticUndefined:
return None
return value


def field_outer_type(field: FieldInfo) -> Any:
if PYDANTIC_V2:
return field.annotation
return field.outer_type_ # type: ignore
if PYDANTIC_V1:
return field.outer_type_ # type: ignore
return field.annotation


def get_model_config(model: type[pydantic.BaseModel]) -> Any:
if PYDANTIC_V2:
return model.model_config
return model.__config__ # type: ignore
if PYDANTIC_V1:
return model.__config__ # type: ignore
return model.model_config


def get_model_fields(model: type[pydantic.BaseModel]) -> dict[str, FieldInfo]:
if PYDANTIC_V2:
return model.model_fields
return model.__fields__ # type: ignore
if PYDANTIC_V1:
return model.__fields__ # type: ignore
return model.model_fields


def model_copy(model: _ModelT, *, deep: bool = False) -> _ModelT:
if PYDANTIC_V2:
return model.model_copy(deep=deep)
return model.copy(deep=deep) # type: ignore
if PYDANTIC_V1:
return model.copy(deep=deep) # type: ignore
return model.model_copy(deep=deep)


def model_json(model: pydantic.BaseModel, *, indent: int | None = None) -> str:
if PYDANTIC_V2:
return model.model_dump_json(indent=indent)
return model.json(indent=indent) # type: ignore
if PYDANTIC_V1:
return model.json(indent=indent) # type: ignore
return model.model_dump_json(indent=indent)


def model_dump(
Expand All @@ -139,14 +140,14 @@ def model_dump(
warnings: bool = True,
mode: Literal["json", "python"] = "python",
) -> dict[str, Any]:
if PYDANTIC_V2 or hasattr(model, "model_dump"):
if (not PYDANTIC_V1) or hasattr(model, "model_dump"):
return model.model_dump(
mode=mode,
exclude=exclude,
exclude_unset=exclude_unset,
exclude_defaults=exclude_defaults,
# warnings are not supported in Pydantic v1
warnings=warnings if PYDANTIC_V2 else True,
warnings=True if PYDANTIC_V1 else warnings,
)
return cast(
"dict[str, Any]",
Expand All @@ -159,9 +160,9 @@ def model_dump(


def model_parse(model: type[_ModelT], data: Any) -> _ModelT:
if PYDANTIC_V2:
return model.model_validate(data)
return model.parse_obj(data) # pyright: ignore[reportDeprecated]
if PYDANTIC_V1:
return model.parse_obj(data) # pyright: ignore[reportDeprecated]
return model.model_validate(data)


# generic models
Expand All @@ -170,17 +171,16 @@ def model_parse(model: type[_ModelT], data: Any) -> _ModelT:
class GenericModel(pydantic.BaseModel): ...

else:
if PYDANTIC_V2:
if PYDANTIC_V1:
import pydantic.generics

class GenericModel(pydantic.generics.GenericModel, pydantic.BaseModel): ...
else:
# there no longer needs to be a distinction in v2 but
# we still have to create our own subclass to avoid
# inconsistent MRO ordering errors
class GenericModel(pydantic.BaseModel): ...

else:
import pydantic.generics

class GenericModel(pydantic.generics.GenericModel, pydantic.BaseModel): ...


# cached properties
if TYPE_CHECKING:
Expand Down
Loading