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
13 changes: 0 additions & 13 deletions examples/Dockerfile

This file was deleted.

34 changes: 34 additions & 0 deletions examples/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#
# Copyright (c) 2023-2024 - Restate Software, Inc., Restate GmbH
#
# This file is part of the Restate SDK for Python,
# which is released under the MIT license.
#
# You can find a copy of the license in file LICENSE in the root
# directory of this repository or package, or at
# https://github.com/restatedev/sdk-typescript/blob/main/LICENSE
#
import restate

from virtual_object import increment, count

#
# uv run examples/client.py
#


async def main():
async with restate.create_client("http://localhost:8080") as client:
await client.object_call(increment, key="a", arg=5)

await client.object_send(increment, key="a", arg=5)

current_count = await client.object_call(count, key="a", arg=None)

print(f"Current count for 'a': {current_count}")


if __name__ == "__main__":
import asyncio

asyncio.run(main())
5 changes: 5 additions & 0 deletions examples/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
# pylint: disable=C0116
# pylint: disable=W0613


#
# uv run examples/example.py
#

import logging
import restate

Expand Down
38 changes: 38 additions & 0 deletions examples/harness.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#
# Copyright (c) 2023-2024 - Restate Software, Inc., Restate GmbH
#
# This file is part of the Restate SDK for Python,
# which is released under the MIT license.
#
# You can find a copy of the license in file LICENSE in the root
# directory of this repository or package, or at
# https://github.com/restatedev/sdk-typescript/blob/main/LICENSE
#
import restate

from virtual_object import increment, count, counter

#
# uv run examples/harness.py
#


async def main():
app = restate.app([counter])
async with restate.create_test_harness(app) as harness:
await harness.client.object_call(increment, key="a", arg=5)
await harness.client.object_call(increment, key="a", arg=5)

current_count = await harness.client.object_call(count, key="a", arg=None)

print(f"Current count for 'a': {current_count}")

send = await harness.client.object_send(increment, key="b", arg=-10, idempotency_key="op1")

print(f"Sent increment to 'b', invocation ID: {send.invocation_id}")


if __name__ == "__main__":
import asyncio

asyncio.run(main())
4 changes: 0 additions & 4 deletions examples/requirements.txt

This file was deleted.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ test = ["pytest", "hypercorn"]
lint = ["mypy>=1.11.2", "pyright>=1.1.390", "ruff>=0.6.9"]
harness = ["testcontainers", "hypercorn", "httpx"]
serde = ["dacite", "pydantic"]
client = ["httpx[http2]"]

[build-system]
requires = ["maturin>=1.6,<2.0"]
Expand Down
28 changes: 23 additions & 5 deletions python/restate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Restate SDK for Python
"""

from contextlib import contextmanager
from contextlib import asynccontextmanager
import typing

from restate.server_types import RestateAppT
Expand All @@ -26,6 +26,7 @@
from .context import Context, ObjectContext, ObjectSharedContext
from .context import WorkflowContext, WorkflowSharedContext
from .retry_policy import InvocationRetryPolicy
from .client_types import RestateClient, RestateClientSendHandle

# pylint: disable=line-too-long
from .context import (
Expand All @@ -50,15 +51,15 @@
# we don't have the appropriate dependencies installed

# pylint: disable=unused-argument, redefined-outer-name
@contextmanager
@asynccontextmanager
def create_test_harness(
app: RestateAppT,
follow_logs: bool = False,
restate_image: str = "restatedev/restate:latest",
always_replay: bool = False,
disable_retries: bool = False,
) -> typing.Generator[TestHarnessEnvironment, None, None]:
"""a dummy harness constructor to raise ImportError"""
) -> typing.AsyncGenerator[TestHarnessEnvironment, None]:
"""a dummy harness constructor to raise ImportError. Install restate-sdk[harness] to use this feature"""
raise ImportError("Install restate-sdk[harness] to use this feature")

def test_harness(
Expand All @@ -68,10 +69,24 @@ def test_harness(
always_replay: bool = False,
disable_retries: bool = False,
):
"""a dummy harness constructor to raise ImportError"""
"""a dummy harness constructor to raise ImportError. Install restate-sdk[harness] to use this feature"""
raise ImportError("Install restate-sdk[harness] to use this feature")


try:
from .client import create_client
except ImportError:
# we don't have the appropriate dependencies installed

@asynccontextmanager
async def create_client(
ingress: str, headers: typing.Optional[dict] = None
) -> typing.AsyncGenerator[RestateClient, None]:
"""a dummy client constructor to raise ImportError. Install restate-sdk[client] to use this feature"""
raise ImportError("Install restate-sdk[client] to use this feature")
yield # type: ignore


__all__ = [
"Service",
"VirtualObject",
Expand Down Expand Up @@ -101,4 +116,7 @@ def test_harness(
"SdkInternalBaseException",
"is_internal_exception",
"getLogger",
"RestateClient",
"RestateClientSendHandle",
"create_client",
]
Loading