ephaptic 0.2.0__tar.gz → 0.2.2__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.
- {ephaptic-0.2.0 → ephaptic-0.2.2}/PKG-INFO +3 -1
- {ephaptic-0.2.0 → ephaptic-0.2.2}/README.md +3 -1
- {ephaptic-0.2.0 → ephaptic-0.2.2}/ephaptic/__init__.py +3 -1
- {ephaptic-0.2.0 → ephaptic-0.2.2}/ephaptic/ephaptic.py +42 -7
- {ephaptic-0.2.0 → ephaptic-0.2.2}/ephaptic.egg-info/PKG-INFO +3 -1
- {ephaptic-0.2.0 → ephaptic-0.2.2}/pyproject.toml +1 -1
- {ephaptic-0.2.0 → ephaptic-0.2.2}/LICENSE +0 -0
- {ephaptic-0.2.0 → ephaptic-0.2.2}/ephaptic/adapters/__init__.py +0 -0
- {ephaptic-0.2.0 → ephaptic-0.2.2}/ephaptic/adapters/fastapi_.py +0 -0
- {ephaptic-0.2.0 → ephaptic-0.2.2}/ephaptic/adapters/quart_.py +0 -0
- {ephaptic-0.2.0 → ephaptic-0.2.2}/ephaptic/cli/__init__.py +0 -0
- {ephaptic-0.2.0 → ephaptic-0.2.2}/ephaptic/cli/__main__.py +0 -0
- {ephaptic-0.2.0 → ephaptic-0.2.2}/ephaptic/client/__init__.py +0 -0
- {ephaptic-0.2.0 → ephaptic-0.2.2}/ephaptic/client/client.py +0 -0
- {ephaptic-0.2.0 → ephaptic-0.2.2}/ephaptic/localproxy.py +0 -0
- {ephaptic-0.2.0 → ephaptic-0.2.2}/ephaptic/transports/__init__.py +0 -0
- {ephaptic-0.2.0 → ephaptic-0.2.2}/ephaptic/transports/fastapi_ws.py +0 -0
- {ephaptic-0.2.0 → ephaptic-0.2.2}/ephaptic/transports/websocket.py +0 -0
- {ephaptic-0.2.0 → ephaptic-0.2.2}/ephaptic.egg-info/SOURCES.txt +0 -0
- {ephaptic-0.2.0 → ephaptic-0.2.2}/ephaptic.egg-info/dependency_links.txt +0 -0
- {ephaptic-0.2.0 → ephaptic-0.2.2}/ephaptic.egg-info/entry_points.txt +0 -0
- {ephaptic-0.2.0 → ephaptic-0.2.2}/ephaptic.egg-info/requires.txt +0 -0
- {ephaptic-0.2.0 → ephaptic-0.2.2}/ephaptic.egg-info/top_level.txt +0 -0
- {ephaptic-0.2.0 → ephaptic-0.2.2}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ephaptic
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: The Python client/server package for ephaptic.
|
|
5
5
|
Author-email: uukelele <robustrobot11@gmail.com>
|
|
6
6
|
License: MIT License
|
|
@@ -132,6 +132,8 @@ async def add(num1: int, num2: int) -> int:
|
|
|
132
132
|
return num1 + num2
|
|
133
133
|
```
|
|
134
134
|
|
|
135
|
+
###### If you're trying to expose functions statelessly, e.g. in a different file, feel free to instead import and use the `expose` function from the library instead of the instance. Please note that if you do this, you must define all exposed functions *before* creating the ephaptic instance - easily done by simply placing your import line above the ephaptic constructor. The same thing can be done with the global `identity_loader` decorator.
|
|
136
|
+
|
|
135
137
|
Yep, it's really that simple.
|
|
136
138
|
|
|
137
139
|
But what if your code throws an error? No sweat, it just throws up on the frontend, with the error name.
|
|
@@ -90,6 +90,8 @@ async def add(num1: int, num2: int) -> int:
|
|
|
90
90
|
return num1 + num2
|
|
91
91
|
```
|
|
92
92
|
|
|
93
|
+
###### If you're trying to expose functions statelessly, e.g. in a different file, feel free to instead import and use the `expose` function from the library instead of the instance. Please note that if you do this, you must define all exposed functions *before* creating the ephaptic instance - easily done by simply placing your import line above the ephaptic constructor. The same thing can be done with the global `identity_loader` decorator.
|
|
94
|
+
|
|
93
95
|
Yep, it's really that simple.
|
|
94
96
|
|
|
95
97
|
But what if your code throws an error? No sweat, it just throws up on the frontend, with the error name.
|
|
@@ -178,4 +180,4 @@ const client = connect(...);
|
|
|
178
180
|
|
|
179
181
|
<p align="center">
|
|
180
182
|
© ephaptic 2025
|
|
181
|
-
</p>
|
|
183
|
+
</p>
|
|
@@ -51,9 +51,12 @@ class ConnectionManager:
|
|
|
51
51
|
for user_id in user_ids:
|
|
52
52
|
if user_id in self.active:
|
|
53
53
|
for transport in list(self.active[user_id]):
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
asyncio.create_task(self._safe_send(transport, payload))
|
|
55
|
+
|
|
56
|
+
async def _safe_send(self, transport: Transport, payload: bytes):
|
|
57
|
+
try:
|
|
58
|
+
await transport.send(payload)
|
|
59
|
+
except: ...
|
|
57
60
|
|
|
58
61
|
async def start_redis(self):
|
|
59
62
|
if not self.redis: return
|
|
@@ -67,6 +70,9 @@ class ConnectionManager:
|
|
|
67
70
|
|
|
68
71
|
manager = ConnectionManager()
|
|
69
72
|
|
|
73
|
+
_EXPOSED_FUNCTIONS = {}
|
|
74
|
+
_IDENTITY_LOADER: Optional[Callable] = None
|
|
75
|
+
|
|
70
76
|
class EphapticTarget:
|
|
71
77
|
def __init__(self, user_ids: list[str]):
|
|
72
78
|
self.user_ids = user_ids
|
|
@@ -76,6 +82,14 @@ class EphapticTarget:
|
|
|
76
82
|
await manager.broadcast(self.user_ids, name, list(args), dict(kwargs))
|
|
77
83
|
return emitter
|
|
78
84
|
|
|
85
|
+
def expose(func: Callable):
|
|
86
|
+
_EXPOSED_FUNCTIONS[func.__name__] = func
|
|
87
|
+
return func
|
|
88
|
+
|
|
89
|
+
def identity_loader(func: Callable):
|
|
90
|
+
_IDENTITY_LOADER = func
|
|
91
|
+
return func
|
|
92
|
+
|
|
79
93
|
class Ephaptic:
|
|
80
94
|
_exposed_functions: Dict[str, Callable] = {}
|
|
81
95
|
_identity_loader: Optional[Callable] = None
|
|
@@ -111,6 +125,9 @@ class Ephaptic:
|
|
|
111
125
|
case _:
|
|
112
126
|
raise TypeError(f"Unsupported app type: {module}")
|
|
113
127
|
|
|
128
|
+
cls._exposed_functions = _EXPOSED_FUNCTIONS.copy()
|
|
129
|
+
cls._identity_loader = _IDENTITY_LOADER
|
|
130
|
+
|
|
114
131
|
return instance
|
|
115
132
|
|
|
116
133
|
|
|
@@ -178,7 +195,7 @@ class Ephaptic:
|
|
|
178
195
|
|
|
179
196
|
if func_name in self._exposed_functions:
|
|
180
197
|
target_func = self._exposed_functions[func_name]
|
|
181
|
-
sig = inspect.signature(target_func)
|
|
198
|
+
sig = inspect.signature(target_func)
|
|
182
199
|
try:
|
|
183
200
|
bound = sig.bind(*args, **kwargs)
|
|
184
201
|
bound.apply_defaults()
|
|
@@ -188,6 +205,8 @@ class Ephaptic:
|
|
|
188
205
|
|
|
189
206
|
hints = typing.get_type_hints(target_func)
|
|
190
207
|
|
|
208
|
+
return_type = hints.get("return", typing.Any)
|
|
209
|
+
|
|
191
210
|
errors = []
|
|
192
211
|
|
|
193
212
|
for name, val in bound.arguments.items():
|
|
@@ -202,7 +221,11 @@ class Ephaptic:
|
|
|
202
221
|
if errors:
|
|
203
222
|
await transport.send(msgpack.dumps({
|
|
204
223
|
"id": call_id,
|
|
205
|
-
"error":
|
|
224
|
+
"error": {
|
|
225
|
+
"code": "VALIDATION_ERROR",
|
|
226
|
+
"message": "Validation failed.",
|
|
227
|
+
"data": errors,
|
|
228
|
+
},
|
|
206
229
|
}))
|
|
207
230
|
continue
|
|
208
231
|
|
|
@@ -211,9 +234,21 @@ class Ephaptic:
|
|
|
211
234
|
|
|
212
235
|
try:
|
|
213
236
|
result = await self._async(target_func)(**bound.arguments)
|
|
214
|
-
|
|
215
|
-
|
|
237
|
+
|
|
238
|
+
if return_type is not inspect.Signature.empty:
|
|
239
|
+
try:
|
|
240
|
+
adapter = pydantic.TypeAdapter(return_type)
|
|
241
|
+
validated = adapter.validate_python(result, from_attributes=True)
|
|
242
|
+
result = adapter.dump_python(validated, mode='json')
|
|
243
|
+
except: ...
|
|
244
|
+
elif isinstance(result, pydantic.BaseModel):
|
|
245
|
+
result = result.model_dump(mode='json')
|
|
246
|
+
|
|
216
247
|
await transport.send(msgpack.dumps({"id": call_id, "result": result}))
|
|
248
|
+
# except pydantic.ValidationError as e:
|
|
249
|
+
# Should we really treat this separately?
|
|
250
|
+
# For input it's understandable, but for server responses it feels like a server issue.
|
|
251
|
+
# Ok, let's treat this like any other server error.
|
|
217
252
|
except Exception as e:
|
|
218
253
|
await transport.send(msgpack.dumps({"id": call_id, "error": str(e)}))
|
|
219
254
|
finally:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ephaptic
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: The Python client/server package for ephaptic.
|
|
5
5
|
Author-email: uukelele <robustrobot11@gmail.com>
|
|
6
6
|
License: MIT License
|
|
@@ -132,6 +132,8 @@ async def add(num1: int, num2: int) -> int:
|
|
|
132
132
|
return num1 + num2
|
|
133
133
|
```
|
|
134
134
|
|
|
135
|
+
###### If you're trying to expose functions statelessly, e.g. in a different file, feel free to instead import and use the `expose` function from the library instead of the instance. Please note that if you do this, you must define all exposed functions *before* creating the ephaptic instance - easily done by simply placing your import line above the ephaptic constructor. The same thing can be done with the global `identity_loader` decorator.
|
|
136
|
+
|
|
135
137
|
Yep, it's really that simple.
|
|
136
138
|
|
|
137
139
|
But what if your code throws an error? No sweat, it just throws up on the frontend, with the error 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
|