pyrpc-fastapi 0.1.0a1__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.
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
from pyrpc_core import handle_request, Router, rpc, model
|
|
2
|
+
from typing import Any, Optional, Dict
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def mount_fastapi(app: Any, router: Optional[Router] = None) -> None:
|
|
6
|
+
"""
|
|
7
|
+
Mount the pyRPC RPC endpoint onto a FastAPI application.
|
|
8
|
+
|
|
9
|
+
Args:
|
|
10
|
+
app: A FastAPI application instance.
|
|
11
|
+
router: An optional pyRPC Router. If None, the global default router is used.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
@app.post("/rpc")
|
|
15
|
+
async def rpc_endpoint(payload: Dict[str, Any]):
|
|
16
|
+
return await handle_request(payload, router=router)
|
|
17
|
+
|
|
18
|
+
@app.get("/rpc")
|
|
19
|
+
async def introspection_endpoint():
|
|
20
|
+
from pyrpc_core import get_registry_schema
|
|
21
|
+
schemas = get_registry_schema(router)
|
|
22
|
+
return {
|
|
23
|
+
name: schema.model_dump() if hasattr(schema, "model_dump") else schema
|
|
24
|
+
for name, schema in schemas.items()
|
|
25
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
pyrpc_fastapi/__init__.py,sha256=9TFczDBcDmdH1mEI0uFdzgMLwyxiEM-mV0oGly2FrZ4,866
|
|
2
|
+
pyrpc_fastapi-0.1.0a1.dist-info/METADATA,sha256=DflwRliKqjESbD3eCS1angbQUwkMyU3JkORd4CGvXfk,176
|
|
3
|
+
pyrpc_fastapi-0.1.0a1.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
|
|
4
|
+
pyrpc_fastapi-0.1.0a1.dist-info/RECORD,,
|