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
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pyo3 = { version = "0.30.1", features = ["extension-module"] }
pyo3-async-runtimes = { version = "0.30", features = ["tokio-runtime"] }
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["fmt", "env-filter"] }
restate-sdk-shared-core = { version = "8.2.0", features = ["request_identity", "sha2_random_seed", "rust_crypto", "tunnel"] }
restate-sdk-shared-core = { version = "8.3.0", features = ["request_identity", "sha2_random_seed", "rust_crypto", "tunnel"] }

# ASGI bridge for the tunnel
bytes = "1.10"
Expand All @@ -28,7 +28,3 @@ percent-encoding = "2.3"
tokio = { version = "1.49", default-features = false, features = ["sync", "rt-multi-thread"] }
tokio-stream = { version = "0.1", default-features = false }
tokio-util = { version = "0.7", default-features = false }

# Until restate-sdk-shared-core with the `cloud` and `tunnel` features is released.
[patch.crates-io]
restate-sdk-shared-core = { git = "https://github.com/restatedev/sdk-shared-core", branch = "cloud-exp-revamp" }
63 changes: 54 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,78 @@ To use this SDK, add the dependency to your project:
pip install restate_sdk
```

## Serving using an ASGI server

Given an `app.py`:

```python
import restate

greeter = restate.Service("greeter")

@greeter.handler()
async def greet(ctx: restate.Context, name: str) -> str:
return f"Hello {name}!"

app = restate.app(services=[greeter])
```

`restate.app(...)` returns an ASGI application, so it can be served by any ASGI server.

With [Hypercorn](https://github.com/pgjones/hypercorn):

```shell
pip install hypercorn
python -m hypercorn app:app --bind "0.0.0.0:9080"
```

Or start it from code:

```python
if __name__ == "__main__":
import asyncio
import hypercorn
import hypercorn.asyncio

conf = hypercorn.Config()
conf.bind = ["0.0.0.0:9080"]
asyncio.run(hypercorn.asyncio.serve(app, conf))
```

Once served, register the deployment with `restate deployments register http://localhost:9080`.

## Connecting to Restate Cloud

An application can connect outbound to Restate Cloud instead of exposing a port. Copy a connect key
from the Cloud UI (Development → Configure SDK), pick a name for the deployment, and run:
from the [Cloud UI -> Development → Configure SDK](https://cloud.restate.dev/to/developers/integration#configure-sdk), pick a name for the deployment, and run:

```shell
RESTATE_CONNECT_KEY=rstcloudv1_... python -m restate connect app:app --name greeter
RESTATE_CONNECT_KEY=rstcloudv1_... python -m restate connect app:app --name greeter-v1
Comment thread
slinkydeveloper marked this conversation as resolved.
Resolved
```

where `app:app` is the module and attribute holding the application returned by `restate.app(...)`.
Then register the deployment as `connect://greeter`. The same from code, running until stopped:
Then register the deployment as `connect://greeter-v1`.

The same from code:

```python
if __name__ == "__main__":
asyncio.run(restate.connect(app, name="greeter"))
import asyncio

Comment thread
slinkydeveloper marked this conversation as resolved.
Resolved
asyncio.run(restate.connect(app, name="greeter-v1"))
```

To do something while connected, use the context manager:
Or using the context manager, for finer control:

```python
async with restate.with_connection(app, name="greeter") as connection:
async with restate.with_connection(app, name="greeter-v1") as connection:
print(connection.info.deployment_url)
await connection.wait()
```

Clients can read an ingress key the same way: `restate.create_client()` without an URL uses
`RESTATE_INGRESS_KEY` (Development → Configure Client).
### Clients

`restate.create_client()` without a URL connects to Restate Cloud using the ingress key in `RESTATE_INGRESS_KEY`, copied from the
[Cloud UI -> Development → Configure SDK](https://cloud.restate.dev/to/developers/integration#configure-sdk).

## Versions

Expand Down
Loading