pydantic-rpc 0.2.0__tar.gz → 0.2.1__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.2.0 → pydantic_rpc-0.2.1}/PKG-INFO +37 -3
- {pydantic_rpc-0.2.0 → pydantic_rpc-0.2.1}/README.md +36 -2
- {pydantic_rpc-0.2.0 → pydantic_rpc-0.2.1}/pyproject.toml +1 -1
- {pydantic_rpc-0.2.0 → pydantic_rpc-0.2.1}/src/pydantic_rpc/core.py +10 -2
- {pydantic_rpc-0.2.0 → pydantic_rpc-0.2.1}/.gitignore +0 -0
- {pydantic_rpc-0.2.0 → pydantic_rpc-0.2.1}/.python-version +0 -0
- {pydantic_rpc-0.2.0 → pydantic_rpc-0.2.1}/LICENSE +0 -0
- {pydantic_rpc-0.2.0 → pydantic_rpc-0.2.1}/examples/README.md +0 -0
- {pydantic_rpc-0.2.0 → pydantic_rpc-0.2.1}/examples/agent_aio_grpc.py +0 -0
- {pydantic_rpc-0.2.0 → pydantic_rpc-0.2.1}/examples/agent_connecpy.py +0 -0
- {pydantic_rpc-0.2.0 → pydantic_rpc-0.2.1}/examples/asyncio_greeting.py +0 -0
- {pydantic_rpc-0.2.0 → pydantic_rpc-0.2.1}/examples/barservice.proto +0 -0
- {pydantic_rpc-0.2.0 → pydantic_rpc-0.2.1}/examples/barservice_pb2.py +0 -0
- {pydantic_rpc-0.2.0 → pydantic_rpc-0.2.1}/examples/barservice_pb2.pyi +0 -0
- {pydantic_rpc-0.2.0 → pydantic_rpc-0.2.1}/examples/barservice_pb2_grpc.py +0 -0
- {pydantic_rpc-0.2.0 → pydantic_rpc-0.2.1}/examples/foobar.py +0 -0
- {pydantic_rpc-0.2.0 → pydantic_rpc-0.2.1}/examples/foobar_client.py +0 -0
- {pydantic_rpc-0.2.0 → pydantic_rpc-0.2.1}/examples/fooservice.proto +0 -0
- {pydantic_rpc-0.2.0 → pydantic_rpc-0.2.1}/examples/fooservice_pb2.py +0 -0
- {pydantic_rpc-0.2.0 → pydantic_rpc-0.2.1}/examples/fooservice_pb2.pyi +0 -0
- {pydantic_rpc-0.2.0 → pydantic_rpc-0.2.1}/examples/fooservice_pb2_grpc.py +0 -0
- {pydantic_rpc-0.2.0 → pydantic_rpc-0.2.1}/examples/google/protobuf/duration.proto +0 -0
- {pydantic_rpc-0.2.0 → pydantic_rpc-0.2.1}/examples/google/protobuf/timestamp.proto +0 -0
- {pydantic_rpc-0.2.0 → pydantic_rpc-0.2.1}/examples/greeter.proto +0 -0
- {pydantic_rpc-0.2.0 → pydantic_rpc-0.2.1}/examples/greeter_client.py +0 -0
- {pydantic_rpc-0.2.0 → pydantic_rpc-0.2.1}/examples/greeter_connecpy.py +0 -0
- {pydantic_rpc-0.2.0 → pydantic_rpc-0.2.1}/examples/greeter_connecpy_client.py +0 -0
- {pydantic_rpc-0.2.0 → pydantic_rpc-0.2.1}/examples/greeter_pb2.py +0 -0
- {pydantic_rpc-0.2.0 → pydantic_rpc-0.2.1}/examples/greeter_pb2.pyi +0 -0
- {pydantic_rpc-0.2.0 → pydantic_rpc-0.2.1}/examples/greeter_pb2_grpc.py +0 -0
- {pydantic_rpc-0.2.0 → pydantic_rpc-0.2.1}/examples/greeter_sonora_client.py +0 -0
- {pydantic_rpc-0.2.0 → pydantic_rpc-0.2.1}/examples/greeting.py +0 -0
- {pydantic_rpc-0.2.0 → pydantic_rpc-0.2.1}/examples/greeting_asgi.py +0 -0
- {pydantic_rpc-0.2.0 → pydantic_rpc-0.2.1}/examples/greeting_connecpy.py +0 -0
- {pydantic_rpc-0.2.0 → pydantic_rpc-0.2.1}/examples/greeting_using_exsiting_pb2_modules.py +0 -0
- {pydantic_rpc-0.2.0 → pydantic_rpc-0.2.1}/examples/greeting_wsgi.py +0 -0
- {pydantic_rpc-0.2.0 → pydantic_rpc-0.2.1}/examples/olympicslocationagent.proto +0 -0
- {pydantic_rpc-0.2.0 → pydantic_rpc-0.2.1}/examples/olympicslocationagent_connecpy.py +0 -0
- {pydantic_rpc-0.2.0 → pydantic_rpc-0.2.1}/examples/olympicslocationagent_pb2.py +0 -0
- {pydantic_rpc-0.2.0 → pydantic_rpc-0.2.1}/examples/olympicslocationagent_pb2.pyi +0 -0
- {pydantic_rpc-0.2.0 → pydantic_rpc-0.2.1}/examples/olympicslocationagent_pb2_grpc.py +0 -0
- {pydantic_rpc-0.2.0 → pydantic_rpc-0.2.1}/requirements-dev.lock +0 -0
- {pydantic_rpc-0.2.0 → pydantic_rpc-0.2.1}/requirements.lock +0 -0
- {pydantic_rpc-0.2.0 → pydantic_rpc-0.2.1}/src/pydantic_rpc/__init__.py +0 -0
- {pydantic_rpc-0.2.0 → pydantic_rpc-0.2.1}/src/pydantic_rpc/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: pydantic-rpc
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: A Python library for building gRPC/ConnectRPC services with Pydantic models.
|
|
5
5
|
Author: Yasushi Itoh
|
|
6
6
|
Requires-Python: >=3.11
|
|
@@ -14,10 +14,10 @@ Description-Content-Type: text/markdown
|
|
|
14
14
|
|
|
15
15
|
# 🚀 PydanticRPC
|
|
16
16
|
|
|
17
|
-
**PydanticRPC** is a Python library that enables you to rapidly expose Pydantic models via gRPC/ConnectRPC services without writing any protobuf files. Instead, it automatically generates protobuf files on the fly from the method signatures of your Python objects and the type signatures of your Pydantic models.
|
|
17
|
+
**PydanticRPC** is a Python library that enables you to rapidly expose [Pydantic](https://docs.pydantic.dev/) models via [gRPC](https://grpc.io/)/[ConnectRPC](https://connectrpc.com/docs/protocol/) services without writing any protobuf files. Instead, it automatically generates protobuf files on the fly from the method signatures of your Python objects and the type signatures of your Pydantic models.
|
|
18
18
|
|
|
19
19
|
|
|
20
|
-
Below is an example of a simple gRPC service that exposes a PydanticAI agent:
|
|
20
|
+
Below is an example of a simple gRPC service that exposes a [PydanticAI](https://ai.pydantic.dev/) agent:
|
|
21
21
|
|
|
22
22
|
```python
|
|
23
23
|
import asyncio
|
|
@@ -54,6 +54,40 @@ if __name__ == "__main__":
|
|
|
54
54
|
loop.run_until_complete(s.run(OlympicsLocationAgent()))
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
+
And here is an example of a simple ConnectRPC service that exposes the same agent as an ASGI application:
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
import asyncio
|
|
61
|
+
|
|
62
|
+
from pydantic_ai import Agent
|
|
63
|
+
from pydantic_rpc import ConnecpyASGIApp, Message
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class CityLocation(Message):
|
|
67
|
+
city: str
|
|
68
|
+
country: str
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class Olympics(Message):
|
|
72
|
+
year: int
|
|
73
|
+
|
|
74
|
+
def prompt(self):
|
|
75
|
+
return f"Where were the Olympics held in {self.year}?"
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
class OlympicsLocationAgent:
|
|
79
|
+
def __init__(self):
|
|
80
|
+
self._agent = Agent("ollama:llama3.2", result_type=CityLocation)
|
|
81
|
+
|
|
82
|
+
async def ask(self, req: Olympics) -> CityLocation:
|
|
83
|
+
result = await self._agent.run(req.prompt())
|
|
84
|
+
return result.data
|
|
85
|
+
|
|
86
|
+
app = ConnecpyASGIApp()
|
|
87
|
+
app.mount(OlympicsLocationAgent())
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
|
|
57
91
|
|
|
58
92
|
## 💡 Key Features
|
|
59
93
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# 🚀 PydanticRPC
|
|
2
2
|
|
|
3
|
-
**PydanticRPC** is a Python library that enables you to rapidly expose Pydantic models via gRPC/ConnectRPC services without writing any protobuf files. Instead, it automatically generates protobuf files on the fly from the method signatures of your Python objects and the type signatures of your Pydantic models.
|
|
3
|
+
**PydanticRPC** is a Python library that enables you to rapidly expose [Pydantic](https://docs.pydantic.dev/) models via [gRPC](https://grpc.io/)/[ConnectRPC](https://connectrpc.com/docs/protocol/) services without writing any protobuf files. Instead, it automatically generates protobuf files on the fly from the method signatures of your Python objects and the type signatures of your Pydantic models.
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
Below is an example of a simple gRPC service that exposes a PydanticAI agent:
|
|
6
|
+
Below is an example of a simple gRPC service that exposes a [PydanticAI](https://ai.pydantic.dev/) agent:
|
|
7
7
|
|
|
8
8
|
```python
|
|
9
9
|
import asyncio
|
|
@@ -40,6 +40,40 @@ if __name__ == "__main__":
|
|
|
40
40
|
loop.run_until_complete(s.run(OlympicsLocationAgent()))
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
+
And here is an example of a simple ConnectRPC service that exposes the same agent as an ASGI application:
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
import asyncio
|
|
47
|
+
|
|
48
|
+
from pydantic_ai import Agent
|
|
49
|
+
from pydantic_rpc import ConnecpyASGIApp, Message
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class CityLocation(Message):
|
|
53
|
+
city: str
|
|
54
|
+
country: str
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class Olympics(Message):
|
|
58
|
+
year: int
|
|
59
|
+
|
|
60
|
+
def prompt(self):
|
|
61
|
+
return f"Where were the Olympics held in {self.year}?"
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class OlympicsLocationAgent:
|
|
65
|
+
def __init__(self):
|
|
66
|
+
self._agent = Agent("ollama:llama3.2", result_type=CityLocation)
|
|
67
|
+
|
|
68
|
+
async def ask(self, req: Olympics) -> CityLocation:
|
|
69
|
+
result = await self._agent.run(req.prompt())
|
|
70
|
+
return result.data
|
|
71
|
+
|
|
72
|
+
app = ConnecpyASGIApp()
|
|
73
|
+
app.mount(OlympicsLocationAgent())
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
|
|
43
77
|
|
|
44
78
|
## 💡 Key Features
|
|
45
79
|
|
|
@@ -865,7 +865,11 @@ def generate_and_compile_proto(obj: object, package_name: str = ""):
|
|
|
865
865
|
pb2_grpc_module = importlib.import_module(
|
|
866
866
|
f"{obj.__class__.__name__.lower()}_pb2_grpc"
|
|
867
867
|
)
|
|
868
|
-
|
|
868
|
+
|
|
869
|
+
if pb2_grpc_module is not None and pb2_module is not None:
|
|
870
|
+
return pb2_grpc_module, pb2_module
|
|
871
|
+
|
|
872
|
+
# If the modules are not found, generate and compile the proto files.
|
|
869
873
|
|
|
870
874
|
klass = obj.__class__
|
|
871
875
|
proto_file = generate_proto(obj, package_name)
|
|
@@ -892,7 +896,11 @@ def generate_and_compile_proto_using_connecpy(obj: object, package_name: str = "
|
|
|
892
896
|
connecpy_module = importlib.import_module(
|
|
893
897
|
f"{obj.__class__.__name__.lower()}_connecpy"
|
|
894
898
|
)
|
|
895
|
-
|
|
899
|
+
|
|
900
|
+
if connecpy_module is not None and pb2_module is not None:
|
|
901
|
+
return connecpy_module, pb2_module
|
|
902
|
+
|
|
903
|
+
# If the modules are not found, generate and compile the proto files.
|
|
896
904
|
|
|
897
905
|
klass = obj.__class__
|
|
898
906
|
proto_file = generate_proto(obj, package_name)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|