polyapi-python 0.2.4.dev0__tar.gz → 0.2.4.dev2__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.
Files changed (37) hide show
  1. {polyapi_python-0.2.4.dev0/polyapi_python.egg-info → polyapi_python-0.2.4.dev2}/PKG-INFO +1 -2
  2. polyapi_python-0.2.4.dev2/polyapi/error_handler.py +78 -0
  3. {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev2}/polyapi/server.py +4 -9
  4. {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev2/polyapi_python.egg-info}/PKG-INFO +1 -2
  5. {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev2}/polyapi_python.egg-info/requires.txt +0 -1
  6. {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev2}/pyproject.toml +1 -2
  7. polyapi_python-0.2.4.dev0/polyapi/error_handler.py +0 -52
  8. {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev2}/LICENSE +0 -0
  9. {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev2}/README.md +0 -0
  10. {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev2}/polyapi/__init__.py +0 -0
  11. {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev2}/polyapi/__main__.py +0 -0
  12. {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev2}/polyapi/api.py +0 -0
  13. {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev2}/polyapi/auth.py +0 -0
  14. {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev2}/polyapi/cli.py +0 -0
  15. {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev2}/polyapi/client.py +0 -0
  16. {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev2}/polyapi/config.py +0 -0
  17. {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev2}/polyapi/constants.py +0 -0
  18. {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev2}/polyapi/exceptions.py +0 -0
  19. {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev2}/polyapi/execute.py +0 -0
  20. {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev2}/polyapi/function_cli.py +0 -0
  21. {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev2}/polyapi/generate.py +0 -0
  22. {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev2}/polyapi/py.typed +0 -0
  23. {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev2}/polyapi/schema.py +0 -0
  24. {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev2}/polyapi/typedefs.py +0 -0
  25. {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev2}/polyapi/utils.py +0 -0
  26. {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev2}/polyapi/variables.py +0 -0
  27. {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev2}/polyapi/webhook.py +0 -0
  28. {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev2}/polyapi_python.egg-info/SOURCES.txt +0 -0
  29. {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev2}/polyapi_python.egg-info/dependency_links.txt +0 -0
  30. {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev2}/polyapi_python.egg-info/top_level.txt +0 -0
  31. {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev2}/setup.cfg +0 -0
  32. {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev2}/tests/test_api.py +0 -0
  33. {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev2}/tests/test_auth.py +0 -0
  34. {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev2}/tests/test_function_cli.py +0 -0
  35. {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev2}/tests/test_server.py +0 -0
  36. {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev2}/tests/test_utils.py +0 -0
  37. {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev2}/tests/test_variables.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: polyapi-python
3
- Version: 0.2.4.dev0
3
+ Version: 0.2.4.dev2
4
4
  Summary: The PolyAPI Python Client
5
5
  Author-email: Dan Fellin <dan@polyapi.io>
6
6
  License: MIT License
@@ -36,7 +36,6 @@ Requires-Dist: stdlib_list==0.10.0
36
36
  Requires-Dist: colorama==0.4.4
37
37
  Requires-Dist: python-socketio[asyncio_client]==5.11.1
38
38
  Requires-Dist: truststore==0.8.0
39
- Requires-Dist: pyjwt==2.3.0
40
39
 
41
40
  # PolyAPI Python Library
42
41
 
@@ -0,0 +1,78 @@
1
+ import asyncio
2
+ import copy
3
+ import socketio # type: ignore
4
+ from typing import Any, Callable, Dict, List, Optional
5
+
6
+ from polyapi.config import get_api_key_and_url
7
+
8
+
9
+ active_handlers: List[Dict[str, Any]] = []
10
+ client = None
11
+
12
+
13
+ def prepare():
14
+ loop = asyncio.get_event_loop()
15
+ loop.run_until_complete(get_client_and_connect())
16
+ print("Client initialized!")
17
+
18
+
19
+
20
+ async def get_client_and_connect():
21
+ _, base_url = get_api_key_and_url()
22
+ global client
23
+ client = socketio.AsyncClient()
24
+ await client.connect(base_url, transports=["websocket"], namespaces=["/events"])
25
+
26
+
27
+ async def unregister(data: Dict[str, Any]):
28
+ print(f"stopping error handler for '{data['path']}'...")
29
+ assert client
30
+ await client.emit(
31
+ "unregisterErrorHandler",
32
+ data,
33
+ "/events",
34
+ )
35
+
36
+
37
+ async def unregister_all():
38
+ _, base_url = get_api_key_and_url()
39
+ # need to reconnect because maybe socketio client disconnected after Ctrl+C?
40
+ await client.connect(base_url, transports=["websocket"], namespaces=["/events"])
41
+ await asyncio.gather(*[unregister(handler) for handler in active_handlers])
42
+
43
+
44
+ async def on(
45
+ path: str, callback: Callable, options: Optional[Dict[str, Any]] = None
46
+ ) -> None:
47
+ print(f"starting error handler for {path}...")
48
+
49
+ if not client:
50
+ raise Exception("Client not initialized. Please call error_handler.prepare() first.")
51
+
52
+ api_key, _ = get_api_key_and_url()
53
+ handler_id = None
54
+ data = copy.deepcopy(options or {})
55
+ data["path"] = path
56
+ data["apiKey"] = api_key
57
+
58
+ def registerCallback(id: int):
59
+ nonlocal handler_id
60
+ handler_id = id
61
+ client.on(f"handleError:{handler_id}", callback, namespace="/events")
62
+ active_handlers.append({"path": path, "id": handler_id, "apiKey": api_key})
63
+
64
+ await client.emit("registerErrorHandler", data, "/events", registerCallback)
65
+
66
+
67
+ def start(*args):
68
+ loop = asyncio.get_event_loop()
69
+ loop.run_until_complete(get_client_and_connect())
70
+ asyncio.gather(*args)
71
+
72
+ try:
73
+ loop.run_forever()
74
+ except KeyboardInterrupt:
75
+ pass
76
+ finally:
77
+ loop.run_until_complete(unregister_all())
78
+ loop.stop()
@@ -18,7 +18,10 @@ def {function_name}(
18
18
  Function ID: {function_id}
19
19
  \"""
20
20
  resp = execute("{function_type}", "{function_id}", {data})
21
- return {return_action}
21
+ try:
22
+ return {return_action}
23
+ except:
24
+ return resp.text
22
25
  """
23
26
 
24
27
 
@@ -54,14 +57,6 @@ def render_server_function(
54
57
  def _get_server_return_action(return_type_name: str) -> str:
55
58
  if return_type_name == "str":
56
59
  return_action = "resp.text"
57
- elif return_type_name == "Any":
58
- return_action = "resp.text"
59
- elif return_type_name == "int":
60
- return_action = "int(resp.text.replace('(int) ', ''))"
61
- elif return_type_name == "float":
62
- return_action = "float(resp.text.replace('(float) ', ''))"
63
- elif return_type_name == "bool":
64
- return_action = "False if resp.text == 'False' else True"
65
60
  else:
66
61
  return_action = "resp.json()"
67
62
  return return_action
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: polyapi-python
3
- Version: 0.2.4.dev0
3
+ Version: 0.2.4.dev2
4
4
  Summary: The PolyAPI Python Client
5
5
  Author-email: Dan Fellin <dan@polyapi.io>
6
6
  License: MIT License
@@ -36,7 +36,6 @@ Requires-Dist: stdlib_list==0.10.0
36
36
  Requires-Dist: colorama==0.4.4
37
37
  Requires-Dist: python-socketio[asyncio_client]==5.11.1
38
38
  Requires-Dist: truststore==0.8.0
39
- Requires-Dist: pyjwt==2.3.0
40
39
 
41
40
  # PolyAPI Python Library
42
41
 
@@ -6,4 +6,3 @@ stdlib_list==0.10.0
6
6
  colorama==0.4.4
7
7
  python-socketio[asyncio_client]==5.11.1
8
8
  truststore==0.8.0
9
- pyjwt==2.3.0
@@ -3,7 +3,7 @@ requires = ["setuptools>=61.2", "wheel"]
3
3
 
4
4
  [project]
5
5
  name = "polyapi-python"
6
- version = "0.2.4.dev0"
6
+ version = "0.2.4.dev2"
7
7
  description = "The PolyAPI Python Client"
8
8
  authors = [{ name = "Dan Fellin", email = "dan@polyapi.io" }]
9
9
  dependencies = [
@@ -15,7 +15,6 @@ dependencies = [
15
15
  "colorama==0.4.4",
16
16
  "python-socketio[asyncio_client]==5.11.1",
17
17
  "truststore==0.8.0",
18
- "pyjwt==2.3.0",
19
18
  ]
20
19
  readme = "README.md"
21
20
  license = { file = "LICENSE" }
@@ -1,52 +0,0 @@
1
- import asyncio
2
- import copy
3
- import socketio # type: ignore
4
- from typing import Any, Callable, Dict, Optional
5
-
6
- from polyapi.config import get_api_key_and_url
7
-
8
-
9
- local_error_handlers: Dict[str, Any] = {}
10
-
11
-
12
- def on(path: str, callback: Callable, options: Optional[Dict[str, Any]] = None) -> Callable:
13
- assert not local_error_handlers
14
- socket = socketio.AsyncClient()
15
- api_key, base_url = get_api_key_and_url()
16
-
17
- async def _inner():
18
- await socket.connect(base_url, transports=["websocket"], namespaces=["/events"])
19
-
20
- handler_id = None
21
- data = copy.deepcopy(options or {})
22
- data["path"] = path
23
- data["apiKey"] = api_key
24
-
25
- def registerCallback(id: int):
26
- nonlocal handler_id, socket
27
- handler_id = id
28
- socket.on(f"handleError:{handler_id}", callback, namespace="/events")
29
-
30
- await socket.emit("registerErrorHandler", data, "/events", registerCallback)
31
- if local_error_handlers.get(path):
32
- local_error_handlers[path].append(callback)
33
- else:
34
- local_error_handlers[path] = [callback]
35
-
36
- async def unregister():
37
- nonlocal handler_id, socket
38
- if handler_id and socket:
39
- await socket.emit(
40
- "unregisterErrorHandler",
41
- {"id": handler_id, "path": path, "apiKey": api_key},
42
- namespace="/events",
43
- )
44
-
45
- if local_error_handlers.get(path):
46
- local_error_handlers[path].remove(callback)
47
-
48
- await socket.wait()
49
-
50
- return unregister
51
-
52
- return asyncio.run(_inner())