danielgtaylor / danielgtaylor/python-betterproto

Documentation errors

Open
#208 1 comment 3 reactions 0 assignees View on GitHub
documentation
Dominant language
Python
Stars
1.8k
Forks
234
PR merge metrics
No merged PRs in 30d

Description

There're a few issues with the example server, even after using the prerelease version. Probably not worth a PR, so here's an update example with notes below:

```python
import asyncio

from echo import EchoBase, EchoResponse, EchoStreamResponse
from grpclib.server import Server
from typing import AsyncIterator

class EchoService(EchoBase):
async def echo(self, value: str, extra_times: int) -> EchoResponse:
return EchoResponse(values=[value] * extra_times)

async def echo_stream(
self, value: str, extra_times: int
) -> AsyncIterator[EchoStreamResponse]:
for _ in range(extra_times):
yield EchoStreamResponse(value=value)

async def start_server():
HOST = "127.0.0.1"
PORT = 50051
server = Server([EchoService()])
await server.start(HOST, PORT)
await server.wait_closed()

if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(start_server())
loop.close()

```

### Changes

- Added imports of `EchoReponse` and `EchoStreamResponse`
- Updated `echo` and `echo_stream` to return the correct types
- Updated `PORT` to match that in the client example
- Replaced `await server.run_forever()` (raises a `NotImplementedError`) with `await server.wait_closed()`
- Added an asyncio loop at the bottom to actually run the server

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.