pydantic-rpc 0.3.1__py3-none-any.whl → 0.4.0__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 +1343 -1308
- {pydantic_rpc-0.3.1.dist-info → pydantic_rpc-0.4.0.dist-info}/METADATA +29 -38
- pydantic_rpc-0.4.0.dist-info/RECORD +7 -0
- pydantic_rpc-0.3.1.dist-info/RECORD +0 -7
- {pydantic_rpc-0.3.1.dist-info → pydantic_rpc-0.4.0.dist-info}/WHEEL +0 -0
- {pydantic_rpc-0.3.1.dist-info → pydantic_rpc-0.4.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: pydantic-rpc
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
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
|
|
@@ -94,6 +94,7 @@ app.mount(OlympicsLocationAgent())
|
|
|
94
94
|
- 🔄 **Automatic Protobuf Generation:** Automatically creates protobuf files matching the method signatures of your Python objects.
|
|
95
95
|
- ⚙️ **Dynamic Code Generation:** Generates server and client stubs using `grpcio-tools`.
|
|
96
96
|
- ✅ **Pydantic Integration:** Uses `pydantic` for robust type validation and serialization.
|
|
97
|
+
- 📄 **Pprotobuf File Export:** Exports the generated protobuf files for use in other languages.
|
|
97
98
|
- **For gRPC:**
|
|
98
99
|
- 💚 **Health Checking:** Built-in support for gRPC health checks using `grpc_health.v1`.
|
|
99
100
|
- 🔎 **Server Reflection:** Built-in support for gRPC server reflection.
|
|
@@ -261,57 +262,38 @@ Please see the sample code below:
|
|
|
261
262
|
|
|
262
263
|
```python
|
|
263
264
|
import asyncio
|
|
264
|
-
from typing import AsyncIterator
|
|
265
|
+
from typing import Annotated, AsyncIterator
|
|
265
266
|
|
|
266
|
-
from pydantic import
|
|
267
|
+
from pydantic import Field
|
|
267
268
|
from pydantic_ai import Agent
|
|
268
269
|
from pydantic_rpc import AsyncIOServer, Message
|
|
269
270
|
|
|
270
271
|
|
|
271
272
|
# `Message` is just a pydantic BaseModel alias
|
|
272
273
|
class CityLocation(Message):
|
|
273
|
-
city: str
|
|
274
|
-
country:
|
|
274
|
+
city: Annotated[str, Field(description="The city where the Olympics were held")]
|
|
275
|
+
country: Annotated[
|
|
276
|
+
str, Field(description="The country where the Olympics were held")
|
|
277
|
+
]
|
|
275
278
|
|
|
276
279
|
|
|
277
280
|
class OlympicsQuery(Message):
|
|
278
|
-
year: int
|
|
281
|
+
year: Annotated[int, Field(description="The year of the Olympics", ge=1896)]
|
|
279
282
|
|
|
280
283
|
def prompt(self):
|
|
281
284
|
return f"Where were the Olympics held in {self.year}?"
|
|
282
285
|
|
|
283
|
-
@field_validator("year")
|
|
284
|
-
def validate_year(cls, value):
|
|
285
|
-
if value < 1896:
|
|
286
|
-
raise ValueError("The first modern Olympics was held in 1896.")
|
|
287
|
-
|
|
288
|
-
return value
|
|
289
|
-
|
|
290
286
|
|
|
291
287
|
class OlympicsDurationQuery(Message):
|
|
292
|
-
start: int
|
|
293
|
-
end: int
|
|
288
|
+
start: Annotated[int, Field(description="The start year of the Olympics", ge=1896)]
|
|
289
|
+
end: Annotated[int, Field(description="The end year of the Olympics", ge=1896)]
|
|
294
290
|
|
|
295
291
|
def prompt(self):
|
|
296
292
|
return f"From {self.start} to {self.end}, how many Olympics were held? Please provide the list of countries and cities."
|
|
297
293
|
|
|
298
|
-
@field_validator("start")
|
|
299
|
-
def validate_start(cls, value):
|
|
300
|
-
if value < 1896:
|
|
301
|
-
raise ValueError("The first modern Olympics was held in 1896.")
|
|
302
|
-
|
|
303
|
-
return value
|
|
304
|
-
|
|
305
|
-
@field_validator("end")
|
|
306
|
-
def validate_end(cls, value):
|
|
307
|
-
if value < 1896:
|
|
308
|
-
raise ValueError("The first modern Olympics was held in 1896.")
|
|
309
|
-
|
|
310
|
-
return value
|
|
311
|
-
|
|
312
294
|
|
|
313
295
|
class StreamingResult(Message):
|
|
314
|
-
answer: str
|
|
296
|
+
answer: Annotated[str, Field(description="The answer to the query")]
|
|
315
297
|
|
|
316
298
|
|
|
317
299
|
class OlympicsAgent:
|
|
@@ -433,18 +415,27 @@ Using this generated proto file and tools as `protoc`, `buf` and `BSR`, you coul
|
|
|
433
415
|
|
|
434
416
|
## 📖 Data Type Mapping
|
|
435
417
|
|
|
436
|
-
| Python Type
|
|
437
|
-
|
|
438
|
-
| str
|
|
439
|
-
|
|
|
440
|
-
|
|
|
441
|
-
|
|
|
442
|
-
|
|
|
443
|
-
|
|
|
418
|
+
| Python Type | Protobuf Type |
|
|
419
|
+
|--------------------------------|---------------------------|
|
|
420
|
+
| str | string |
|
|
421
|
+
| bytes | bytes |
|
|
422
|
+
| bool | bool |
|
|
423
|
+
| int | int32 |
|
|
424
|
+
| float | float, double |
|
|
425
|
+
| list[T], tuple[T] | repeated T |
|
|
426
|
+
| dict[K, V] | map<K, V> |
|
|
427
|
+
| datetime.datetime | google.protobuf.Timestamp |
|
|
428
|
+
| datetime.timedelta | google.protobuf.Duration |
|
|
429
|
+
| typing.Union[A, B] | oneof A, B |
|
|
430
|
+
| subclass of enum.Enum | enum |
|
|
431
|
+
| subclass of pydantic.BaseModel | message |
|
|
444
432
|
|
|
445
433
|
|
|
446
434
|
## TODO
|
|
447
435
|
- [ ] Streaming Support
|
|
436
|
+
- [x] unary-stream
|
|
437
|
+
- [ ] stream-unary
|
|
438
|
+
- [ ] stream-stream
|
|
448
439
|
- [ ] Betterproto Support
|
|
449
440
|
- [ ] Sonora-connect Support
|
|
450
441
|
- [ ] Custom Health Check Support
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
pydantic_rpc/__init__.py,sha256=AWYjSmYQcMqsqGmGK4k-pQQhX6RBBgkTvNcQtCtsctU,113
|
|
2
|
+
pydantic_rpc/core.py,sha256=6NMTtS8cKNjPN5cBvd_XLU6h1oMZ6EqAHz-HGLnJpD0,47939
|
|
3
|
+
pydantic_rpc/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
pydantic_rpc-0.4.0.dist-info/METADATA,sha256=FOVo-T-PCD0Sxh__B9cVaZpXb6XfUBOPmFIW0hP1v58,11993
|
|
5
|
+
pydantic_rpc-0.4.0.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
|
|
6
|
+
pydantic_rpc-0.4.0.dist-info/licenses/LICENSE,sha256=Y6jkAm2VqPqoGIGQ-mEQCecNfteQ2LwdpYhC5XiH_cA,1069
|
|
7
|
+
pydantic_rpc-0.4.0.dist-info/RECORD,,
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
pydantic_rpc/__init__.py,sha256=AWYjSmYQcMqsqGmGK4k-pQQhX6RBBgkTvNcQtCtsctU,113
|
|
2
|
-
pydantic_rpc/core.py,sha256=FbSEiSnm9oOh0vFr4jcv7_5ZWyMvRDnMwzlFN5M9g4U,47417
|
|
3
|
-
pydantic_rpc/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
-
pydantic_rpc-0.3.1.dist-info/METADATA,sha256=xfYTVEKisOvkxozu9nbdJ_nPR3rcaufARQfqZubWFDs,11412
|
|
5
|
-
pydantic_rpc-0.3.1.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
|
|
6
|
-
pydantic_rpc-0.3.1.dist-info/licenses/LICENSE,sha256=Y6jkAm2VqPqoGIGQ-mEQCecNfteQ2LwdpYhC5XiH_cA,1069
|
|
7
|
-
pydantic_rpc-0.3.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|