pydantic-rpc 0.12.0__tar.gz → 0.14.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pydantic_rpc-0.12.0 → pydantic_rpc-0.14.0}/PKG-INFO +10 -17
- {pydantic_rpc-0.12.0 → pydantic_rpc-0.14.0}/README.md +9 -16
- {pydantic_rpc-0.12.0 → pydantic_rpc-0.14.0}/pyproject.toml +2 -1
- {pydantic_rpc-0.12.0 → pydantic_rpc-0.14.0}/src/pydantic_rpc/core.py +41 -19
- {pydantic_rpc-0.12.0 → pydantic_rpc-0.14.0}/src/pydantic_rpc/__init__.py +0 -0
- {pydantic_rpc-0.12.0 → pydantic_rpc-0.14.0}/src/pydantic_rpc/decorators.py +0 -0
- {pydantic_rpc-0.12.0 → pydantic_rpc-0.14.0}/src/pydantic_rpc/mcp/__init__.py +0 -0
- {pydantic_rpc-0.12.0 → pydantic_rpc-0.14.0}/src/pydantic_rpc/mcp/converter.py +0 -0
- {pydantic_rpc-0.12.0 → pydantic_rpc-0.14.0}/src/pydantic_rpc/mcp/exporter.py +0 -0
- {pydantic_rpc-0.12.0 → pydantic_rpc-0.14.0}/src/pydantic_rpc/options.py +0 -0
- {pydantic_rpc-0.12.0 → pydantic_rpc-0.14.0}/src/pydantic_rpc/py.typed +0 -0
- {pydantic_rpc-0.12.0 → pydantic_rpc-0.14.0}/src/pydantic_rpc/tls.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: pydantic-rpc
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.14.0
|
|
4
4
|
Summary: A Python library for building gRPC/ConnectRPC services with Pydantic models.
|
|
5
5
|
Author: Yasushi Itoh
|
|
6
6
|
Requires-Dist: annotated-types==0.7.0
|
|
@@ -125,7 +125,7 @@ app = ASGIApp(service=OlympicsLocationAgent())
|
|
|
125
125
|
- 🔎 **Server Reflection:** Built-in support for gRPC server reflection.
|
|
126
126
|
- ⚡ **Asynchronous Support:** Easily create asynchronous gRPC services with `AsyncIOServer`.
|
|
127
127
|
- **For Connect-RPC:**
|
|
128
|
-
- 🌐 **Full Protocol Support:** Native Connect-RPC support via `
|
|
128
|
+
- 🌐 **Full Protocol Support:** Native Connect-RPC support via `connect-python`
|
|
129
129
|
- 🔄 **All Streaming Patterns:** Unary, server streaming, client streaming, and bidirectional streaming
|
|
130
130
|
- 🌐 **WSGI/ASGI Applications:** Run as standard WSGI or ASGI applications for easy deployment
|
|
131
131
|
- 🛠️ **Pre-generated Protobuf Files and Code:** Pre-generate proto files and corresponding code via the CLI. By setting the environment variable (PYDANTIC_RPC_SKIP_GENERATION), you can skip runtime generation.
|
|
@@ -304,21 +304,21 @@ app.mount(Greeter())
|
|
|
304
304
|
|
|
305
305
|
### 🏆 Connect-RPC with Streaming Example
|
|
306
306
|
|
|
307
|
-
PydanticRPC provides native Connect-RPC support via
|
|
307
|
+
PydanticRPC provides native Connect-RPC support via connect-python, including full streaming capabilities and PEP 8 naming conventions. Check out our ASGI examples:
|
|
308
308
|
|
|
309
309
|
```bash
|
|
310
310
|
# Run with uvicorn
|
|
311
311
|
uv run uvicorn greeting_asgi:app --port 3000
|
|
312
312
|
|
|
313
313
|
# Or run streaming example
|
|
314
|
-
uv run python examples/
|
|
314
|
+
uv run python examples/streaming_connect_python.py
|
|
315
315
|
```
|
|
316
316
|
|
|
317
|
-
This will launch a
|
|
317
|
+
This will launch a connect-python-based ASGI application that uses the same Pydantic models to serve Connect-RPC requests.
|
|
318
318
|
|
|
319
|
-
#### Streaming Support with
|
|
319
|
+
#### Streaming Support with connect-python
|
|
320
320
|
|
|
321
|
-
|
|
321
|
+
connect-python provides full support for streaming RPCs with automatic PEP 8 naming (snake_case):
|
|
322
322
|
|
|
323
323
|
```python
|
|
324
324
|
from typing import AsyncIterator
|
|
@@ -359,14 +359,7 @@ app.mount(StreamingService())
|
|
|
359
359
|
```
|
|
360
360
|
|
|
361
361
|
> [!NOTE]
|
|
362
|
-
> Please install `protoc-gen-
|
|
363
|
-
>
|
|
364
|
-
> 1. Install Go.
|
|
365
|
-
> - Please follow the instruction described in https://go.dev/doc/install.
|
|
366
|
-
> 2. Install `protoc-gen-connecpy`:
|
|
367
|
-
> ```bash
|
|
368
|
-
> go install github.com/i2y/connecpy/v2/protoc-gen-connecpy@latest
|
|
369
|
-
> ```
|
|
362
|
+
> Please install `protoc-gen-connect-python` to run the connect-python example.
|
|
370
363
|
|
|
371
364
|
## ♻️ Skipping Protobuf Generation
|
|
372
365
|
By default, PydanticRPC generates .proto files and code at runtime. If you wish to skip the code-generation step (for example, in production environment), set the environment variable below:
|
|
@@ -375,9 +368,9 @@ By default, PydanticRPC generates .proto files and code at runtime. If you wish
|
|
|
375
368
|
export PYDANTIC_RPC_SKIP_GENERATION=true
|
|
376
369
|
```
|
|
377
370
|
|
|
378
|
-
When this variable is set to "true", PydanticRPC will load existing pre-generated modules rather than generating
|
|
371
|
+
When this variable is set to "true", PydanticRPC will load existing pre-generated modules rather than generating theƒm on the fly.
|
|
379
372
|
|
|
380
|
-
## 🪧 Setting Protobuf and
|
|
373
|
+
## 🪧 Setting Protobuf and Connect RPC/gRPC generation directory
|
|
381
374
|
By default your files will be generated in the current working directory where you ran the code from, but you can set a custom specific directory by setting the environment variable below:
|
|
382
375
|
|
|
383
376
|
```bash
|
|
@@ -107,7 +107,7 @@ app = ASGIApp(service=OlympicsLocationAgent())
|
|
|
107
107
|
- 🔎 **Server Reflection:** Built-in support for gRPC server reflection.
|
|
108
108
|
- ⚡ **Asynchronous Support:** Easily create asynchronous gRPC services with `AsyncIOServer`.
|
|
109
109
|
- **For Connect-RPC:**
|
|
110
|
-
- 🌐 **Full Protocol Support:** Native Connect-RPC support via `
|
|
110
|
+
- 🌐 **Full Protocol Support:** Native Connect-RPC support via `connect-python`
|
|
111
111
|
- 🔄 **All Streaming Patterns:** Unary, server streaming, client streaming, and bidirectional streaming
|
|
112
112
|
- 🌐 **WSGI/ASGI Applications:** Run as standard WSGI or ASGI applications for easy deployment
|
|
113
113
|
- 🛠️ **Pre-generated Protobuf Files and Code:** Pre-generate proto files and corresponding code via the CLI. By setting the environment variable (PYDANTIC_RPC_SKIP_GENERATION), you can skip runtime generation.
|
|
@@ -286,21 +286,21 @@ app.mount(Greeter())
|
|
|
286
286
|
|
|
287
287
|
### 🏆 Connect-RPC with Streaming Example
|
|
288
288
|
|
|
289
|
-
PydanticRPC provides native Connect-RPC support via
|
|
289
|
+
PydanticRPC provides native Connect-RPC support via connect-python, including full streaming capabilities and PEP 8 naming conventions. Check out our ASGI examples:
|
|
290
290
|
|
|
291
291
|
```bash
|
|
292
292
|
# Run with uvicorn
|
|
293
293
|
uv run uvicorn greeting_asgi:app --port 3000
|
|
294
294
|
|
|
295
295
|
# Or run streaming example
|
|
296
|
-
uv run python examples/
|
|
296
|
+
uv run python examples/streaming_connect_python.py
|
|
297
297
|
```
|
|
298
298
|
|
|
299
|
-
This will launch a
|
|
299
|
+
This will launch a connect-python-based ASGI application that uses the same Pydantic models to serve Connect-RPC requests.
|
|
300
300
|
|
|
301
|
-
#### Streaming Support with
|
|
301
|
+
#### Streaming Support with connect-python
|
|
302
302
|
|
|
303
|
-
|
|
303
|
+
connect-python provides full support for streaming RPCs with automatic PEP 8 naming (snake_case):
|
|
304
304
|
|
|
305
305
|
```python
|
|
306
306
|
from typing import AsyncIterator
|
|
@@ -341,14 +341,7 @@ app.mount(StreamingService())
|
|
|
341
341
|
```
|
|
342
342
|
|
|
343
343
|
> [!NOTE]
|
|
344
|
-
> Please install `protoc-gen-
|
|
345
|
-
>
|
|
346
|
-
> 1. Install Go.
|
|
347
|
-
> - Please follow the instruction described in https://go.dev/doc/install.
|
|
348
|
-
> 2. Install `protoc-gen-connecpy`:
|
|
349
|
-
> ```bash
|
|
350
|
-
> go install github.com/i2y/connecpy/v2/protoc-gen-connecpy@latest
|
|
351
|
-
> ```
|
|
344
|
+
> Please install `protoc-gen-connect-python` to run the connect-python example.
|
|
352
345
|
|
|
353
346
|
## ♻️ Skipping Protobuf Generation
|
|
354
347
|
By default, PydanticRPC generates .proto files and code at runtime. If you wish to skip the code-generation step (for example, in production environment), set the environment variable below:
|
|
@@ -357,9 +350,9 @@ By default, PydanticRPC generates .proto files and code at runtime. If you wish
|
|
|
357
350
|
export PYDANTIC_RPC_SKIP_GENERATION=true
|
|
358
351
|
```
|
|
359
352
|
|
|
360
|
-
When this variable is set to "true", PydanticRPC will load existing pre-generated modules rather than generating
|
|
353
|
+
When this variable is set to "true", PydanticRPC will load existing pre-generated modules rather than generating theƒm on the fly.
|
|
361
354
|
|
|
362
|
-
## 🪧 Setting Protobuf and
|
|
355
|
+
## 🪧 Setting Protobuf and Connect RPC/gRPC generation directory
|
|
363
356
|
By default your files will be generated in the current working directory where you ran the code from, but you can set a custom specific directory by setting the environment variable below:
|
|
364
357
|
|
|
365
358
|
```bash
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "pydantic-rpc"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.14.0"
|
|
4
4
|
description = "A Python library for building gRPC/ConnectRPC services with Pydantic models."
|
|
5
5
|
authors = [
|
|
6
6
|
{ name = "Yasushi Itoh" }
|
|
@@ -33,6 +33,7 @@ dev-dependencies = [
|
|
|
33
33
|
"pytest>=8.3.4",
|
|
34
34
|
"pytest-asyncio>=0.20.3",
|
|
35
35
|
"ruff>=0.9.4",
|
|
36
|
+
"uvicorn>=0.34.0",
|
|
36
37
|
]
|
|
37
38
|
|
|
38
39
|
[tool.pytest.ini_options]
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import annotated_types
|
|
1
2
|
import asyncio
|
|
2
3
|
import datetime
|
|
3
4
|
import enum
|
|
5
|
+
import grpc
|
|
6
|
+
import grpc_tools
|
|
4
7
|
import importlib.util
|
|
5
8
|
import inspect
|
|
6
9
|
import os
|
|
@@ -8,11 +11,19 @@ import signal
|
|
|
8
11
|
import sys
|
|
9
12
|
import time
|
|
10
13
|
import types
|
|
11
|
-
from
|
|
12
|
-
from collections.abc import AsyncIterator, Awaitable, Callable, Iterable
|
|
14
|
+
from collections.abc import AsyncIterator, Awaitable, Callable, Iterable, Sequence
|
|
13
15
|
from concurrent import futures
|
|
16
|
+
from connectrpc.code import Code as Errors
|
|
17
|
+
# Protobuf Python modules for Timestamp, Duration (requires protobuf / grpcio)
|
|
18
|
+
from google.protobuf import duration_pb2, timestamp_pb2, empty_pb2
|
|
19
|
+
from grpc import ServicerContext
|
|
20
|
+
from grpc_health.v1 import health_pb2, health_pb2_grpc
|
|
21
|
+
from grpc_health.v1.health import HealthServicer
|
|
22
|
+
from grpc_reflection.v1alpha import reflection
|
|
23
|
+
from grpc_tools import protoc
|
|
14
24
|
from pathlib import Path
|
|
15
25
|
from posixpath import basename
|
|
26
|
+
from pydantic import BaseModel, ValidationError
|
|
16
27
|
from typing import (
|
|
17
28
|
Any,
|
|
18
29
|
Optional,
|
|
@@ -22,20 +33,10 @@ from typing import (
|
|
|
22
33
|
cast,
|
|
23
34
|
TypeGuard,
|
|
24
35
|
)
|
|
36
|
+
from typing import Union
|
|
37
|
+
from typing import Union, Sequence, Tuple
|
|
38
|
+
from concurrent.futures import Executor
|
|
25
39
|
|
|
26
|
-
import annotated_types
|
|
27
|
-
import grpc
|
|
28
|
-
from grpc import ServicerContext
|
|
29
|
-
import grpc_tools
|
|
30
|
-
from connectrpc.code import Code as Errors
|
|
31
|
-
|
|
32
|
-
# Protobuf Python modules for Timestamp, Duration (requires protobuf / grpcio)
|
|
33
|
-
from google.protobuf import duration_pb2, timestamp_pb2, empty_pb2
|
|
34
|
-
from grpc_health.v1 import health_pb2, health_pb2_grpc
|
|
35
|
-
from grpc_health.v1.health import HealthServicer
|
|
36
|
-
from grpc_reflection.v1alpha import reflection
|
|
37
|
-
from grpc_tools import protoc
|
|
38
|
-
from pydantic import BaseModel, ValidationError
|
|
39
40
|
from .decorators import get_method_options, has_http_option
|
|
40
41
|
from .tls import GrpcTLSConfig
|
|
41
42
|
|
|
@@ -2610,11 +2611,20 @@ class Server:
|
|
|
2610
2611
|
port: int = 50051,
|
|
2611
2612
|
package_name: str = "",
|
|
2612
2613
|
max_workers: int = 8,
|
|
2613
|
-
*interceptors: Any,
|
|
2614
2614
|
tls: Optional["GrpcTLSConfig"] = None,
|
|
2615
|
+
interceptors: Optional[Sequence[grpc.ServerInterceptor]] = None,
|
|
2616
|
+
handlers: Optional[Sequence[grpc.GenericRpcHandler]] = None,
|
|
2617
|
+
options: Optional[Sequence[Tuple[str, Any]]] = None,
|
|
2618
|
+
maximum_concurrent_rpcs: Optional[int] = None,
|
|
2619
|
+
compression: Optional[grpc.Compression] = None,
|
|
2615
2620
|
) -> None:
|
|
2616
2621
|
self._server: grpc.Server = grpc.server(
|
|
2617
|
-
futures.ThreadPoolExecutor(max_workers),
|
|
2622
|
+
futures.ThreadPoolExecutor(max_workers),
|
|
2623
|
+
handlers=handlers,
|
|
2624
|
+
interceptors=interceptors,
|
|
2625
|
+
options=options,
|
|
2626
|
+
maximum_concurrent_rpcs=maximum_concurrent_rpcs,
|
|
2627
|
+
compression=compression,
|
|
2618
2628
|
)
|
|
2619
2629
|
self._service_names: list[str] = []
|
|
2620
2630
|
self._package_name: str = package_name
|
|
@@ -2711,10 +2721,22 @@ class AsyncIOServer:
|
|
|
2711
2721
|
service: Optional[object] = None,
|
|
2712
2722
|
port: int = 50051,
|
|
2713
2723
|
package_name: str = "",
|
|
2714
|
-
*interceptors: grpc.ServerInterceptor,
|
|
2715
2724
|
tls: Optional["GrpcTLSConfig"] = None,
|
|
2725
|
+
interceptors: Optional[Sequence[grpc.ServerInterceptor]] = None,
|
|
2726
|
+
migration_thread_pool: Optional[Executor] = None,
|
|
2727
|
+
handlers: Optional[Sequence[grpc.GenericRpcHandler]] = None,
|
|
2728
|
+
options: Optional[Sequence[Tuple[str, Any]]] = None,
|
|
2729
|
+
maximum_concurrent_rpcs: Optional[int] = None,
|
|
2730
|
+
compression: Optional[grpc.Compression] = None,
|
|
2716
2731
|
) -> None:
|
|
2717
|
-
self._server: grpc.aio.Server = grpc.aio.server(
|
|
2732
|
+
self._server: grpc.aio.Server = grpc.aio.server(
|
|
2733
|
+
migration_thread_pool=migration_thread_pool,
|
|
2734
|
+
handlers=handlers,
|
|
2735
|
+
interceptors=interceptors,
|
|
2736
|
+
options=options,
|
|
2737
|
+
maximum_concurrent_rpcs=maximum_concurrent_rpcs,
|
|
2738
|
+
compression=compression,
|
|
2739
|
+
)
|
|
2718
2740
|
self._service_names: list[str] = []
|
|
2719
2741
|
self._package_name: str = package_name
|
|
2720
2742
|
self._port: int = port
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|