pydantic-rpc 0.2.0__py3-none-any.whl → 0.2.1__py3-none-any.whl

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/core.py CHANGED
@@ -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
- return pb2_grpc_module, pb2_module
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
- return connecpy_module, pb2_module
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)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: pydantic-rpc
3
- Version: 0.2.0
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
 
@@ -0,0 +1,7 @@
1
+ pydantic_rpc/__init__.py,sha256=AWYjSmYQcMqsqGmGK4k-pQQhX6RBBgkTvNcQtCtsctU,113
2
+ pydantic_rpc/core.py,sha256=CUoiQpARAAejnxNv_6foerWvc_vUvXpZOU1LxoR-EiQ,42596
3
+ pydantic_rpc/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ pydantic_rpc-0.2.1.dist-info/METADATA,sha256=Td5HvDvxy521IB9rClJcsmtxPHAdPRfxcJHgQ3WSEmU,8933
5
+ pydantic_rpc-0.2.1.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
6
+ pydantic_rpc-0.2.1.dist-info/licenses/LICENSE,sha256=Y6jkAm2VqPqoGIGQ-mEQCecNfteQ2LwdpYhC5XiH_cA,1069
7
+ pydantic_rpc-0.2.1.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- pydantic_rpc/__init__.py,sha256=AWYjSmYQcMqsqGmGK4k-pQQhX6RBBgkTvNcQtCtsctU,113
2
- pydantic_rpc/core.py,sha256=IynEU8bReuJM--MvOnw3zlDpneJFROoJNk35pM4fgvI,42286
3
- pydantic_rpc/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- pydantic_rpc-0.2.0.dist-info/METADATA,sha256=RBvdwlbQS1Q020U8Tpp0T-CPswc1xYAlsurXM414Awo,8081
5
- pydantic_rpc-0.2.0.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
6
- pydantic_rpc-0.2.0.dist-info/licenses/LICENSE,sha256=Y6jkAm2VqPqoGIGQ-mEQCecNfteQ2LwdpYhC5XiH_cA,1069
7
- pydantic_rpc-0.2.0.dist-info/RECORD,,