pydantic-rpc 0.3.1__py3-none-any.whl → 0.4.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.
@@ -1,10 +1,11 @@
1
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.4
2
2
  Name: pydantic-rpc
3
- Version: 0.3.1
3
+ Version: 0.4.1
4
4
  Summary: A Python library for building gRPC/ConnectRPC services with Pydantic models.
5
5
  Author: Yasushi Itoh
6
+ License-File: LICENSE
6
7
  Requires-Python: >=3.11
7
- Requires-Dist: connecpy>=1.2.0
8
+ Requires-Dist: connecpy>=1.2.1
8
9
  Requires-Dist: grpcio-health-checking>=1.56.2
9
10
  Requires-Dist: grpcio-reflection>=1.56.2
10
11
  Requires-Dist: grpcio-tools>=1.56.2
@@ -94,6 +95,7 @@ app.mount(OlympicsLocationAgent())
94
95
  - 🔄 **Automatic Protobuf Generation:** Automatically creates protobuf files matching the method signatures of your Python objects.
95
96
  - ⚙️ **Dynamic Code Generation:** Generates server and client stubs using `grpcio-tools`.
96
97
  - ✅ **Pydantic Integration:** Uses `pydantic` for robust type validation and serialization.
98
+ - 📄 **Pprotobuf File Export:** Exports the generated protobuf files for use in other languages.
97
99
  - **For gRPC:**
98
100
  - 💚 **Health Checking:** Built-in support for gRPC health checks using `grpc_health.v1`.
99
101
  - 🔎 **Server Reflection:** Built-in support for gRPC server reflection.
@@ -228,7 +230,7 @@ app.mount(Greeter())
228
230
  PydanticRPC also partially supports Connect-RPC via connecpy. Check out “greeting_connecpy.py” for an example:
229
231
 
230
232
  ```bash
231
- rye run python greeting_connecpy.py
233
+ uv run greeting_connecpy.py
232
234
  ```
233
235
 
234
236
  This will launch a Connecpy-based ASGI application that uses the same Pydantic models to serve Connect-RPC requests.
@@ -261,57 +263,38 @@ Please see the sample code below:
261
263
 
262
264
  ```python
263
265
  import asyncio
264
- from typing import AsyncIterator
266
+ from typing import Annotated, AsyncIterator
265
267
 
266
- from pydantic import field_validator
268
+ from pydantic import Field
267
269
  from pydantic_ai import Agent
268
270
  from pydantic_rpc import AsyncIOServer, Message
269
271
 
270
272
 
271
273
  # `Message` is just a pydantic BaseModel alias
272
274
  class CityLocation(Message):
273
- city: str
274
- country: str
275
+ city: Annotated[str, Field(description="The city where the Olympics were held")]
276
+ country: Annotated[
277
+ str, Field(description="The country where the Olympics were held")
278
+ ]
275
279
 
276
280
 
277
281
  class OlympicsQuery(Message):
278
- year: int
282
+ year: Annotated[int, Field(description="The year of the Olympics", ge=1896)]
279
283
 
280
284
  def prompt(self):
281
285
  return f"Where were the Olympics held in {self.year}?"
282
286
 
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
287
 
291
288
  class OlympicsDurationQuery(Message):
292
- start: int
293
- end: int
289
+ start: Annotated[int, Field(description="The start year of the Olympics", ge=1896)]
290
+ end: Annotated[int, Field(description="The end year of the Olympics", ge=1896)]
294
291
 
295
292
  def prompt(self):
296
293
  return f"From {self.start} to {self.end}, how many Olympics were held? Please provide the list of countries and cities."
297
294
 
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
295
 
313
296
  class StreamingResult(Message):
314
- answer: str
297
+ answer: Annotated[str, Field(description="The answer to the query")]
315
298
 
316
299
 
317
300
  class OlympicsAgent:
@@ -433,18 +416,27 @@ Using this generated proto file and tools as `protoc`, `buf` and `BSR`, you coul
433
416
 
434
417
  ## 📖 Data Type Mapping
435
418
 
436
- | Python Type | Protobuf Type |
437
- |--------------------|-----------------|
438
- | str | string |
439
- | bool | bool |
440
- | int | int32, int64 |
441
- | float | float, double |
442
- | list[T], tuple[T] | repeated T |
443
- | dict[K, V] | map<K, V> |
419
+ | Python Type | Protobuf Type |
420
+ |--------------------------------|---------------------------|
421
+ | str | string |
422
+ | bytes | bytes |
423
+ | bool | bool |
424
+ | int | int32 |
425
+ | float | float, double |
426
+ | list[T], tuple[T] | repeated T |
427
+ | dict[K, V] | map<K, V> |
428
+ | datetime.datetime | google.protobuf.Timestamp |
429
+ | datetime.timedelta | google.protobuf.Duration |
430
+ | typing.Union[A, B] | oneof A, B |
431
+ | subclass of enum.Enum | enum |
432
+ | subclass of pydantic.BaseModel | message |
444
433
 
445
434
 
446
435
  ## TODO
447
436
  - [ ] Streaming Support
437
+ - [x] unary-stream
438
+ - [ ] stream-unary
439
+ - [ ] stream-stream
448
440
  - [ ] Betterproto Support
449
441
  - [ ] Sonora-connect Support
450
442
  - [ ] Custom Health Check Support
@@ -0,0 +1,7 @@
1
+ pydantic_rpc/__init__.py,sha256=oomSVGmh_zddQQaphQt1L2xSVh9dD1LVyaAq1cN1FW4,231
2
+ pydantic_rpc/core.py,sha256=e6zO5qx9vJvOZR8yiBVx41jnIGEg2d_uDHzp6WgkN70,47938
3
+ pydantic_rpc/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ pydantic_rpc-0.4.1.dist-info/METADATA,sha256=4EwQ-24LOPI8h0eNivTcN9aI9n0db80HWEzLi9QZBqI,12007
5
+ pydantic_rpc-0.4.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
6
+ pydantic_rpc-0.4.1.dist-info/licenses/LICENSE,sha256=Y6jkAm2VqPqoGIGQ-mEQCecNfteQ2LwdpYhC5XiH_cA,1069
7
+ pydantic_rpc-0.4.1.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.26.3
2
+ Generator: hatchling 1.27.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -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,,