polyapi-python 0.3.9.dev12__py3-none-any.whl → 0.3.9.dev14__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.
polyapi/__init__.py CHANGED
@@ -2,8 +2,6 @@ import os
2
2
  import sys
3
3
  import copy
4
4
  import truststore
5
- import logging
6
- import builtins
7
5
  from typing import Any, Dict, Optional, overload, Literal
8
6
  from typing_extensions import TypedDict
9
7
  truststore.inject_into_ssl()
@@ -100,19 +98,4 @@ class _PolyCustom:
100
98
  return new
101
99
 
102
100
 
103
- polyCustom: PolyCustomDict = _PolyCustom()
104
-
105
- original_print = print
106
-
107
- logging.basicConfig(level=logging.INFO, format='%(levelname)s - %(message)s')
108
-
109
- def log_prints(*objects, sep=' ', end='\n', file=sys.stdout, flush=False):
110
- message = sep.join(map(str, objects)) + end
111
- if file is sys.stdout:
112
- logging.info(message)
113
- elif file is sys.stderr:
114
- logging.error(message)
115
- else:
116
- original_print(*objects, sep=sep, end=end, file=file, flush=flush)
117
-
118
- builtins.print = log_prints
101
+ polyCustom: PolyCustomDict = _PolyCustom()
polyapi/deployables.py CHANGED
@@ -1,4 +1,6 @@
1
1
  import os
2
+ import string
3
+ import random
2
4
  import subprocess
3
5
  import json
4
6
  import hashlib
@@ -76,9 +78,10 @@ class SyncDeployment(TypedDict, total=False):
76
78
  id: Optional[str]
77
79
  deployed: Optional[str]
78
80
 
81
+
79
82
  DeployableTypeEntries: List[Tuple[DeployableTypeNames, DeployableTypes]] = [
80
- ("PolyServerFunction", "server-function"), # type: ignore
81
- ("PolyClientFunction", "client-function"), # type: ignore
83
+ ("PolyServerFunction", "server-function"), # type: ignore
84
+ ("PolyClientFunction", "client-function"), # type: ignore
82
85
  ]
83
86
 
84
87
  DeployableTypeToName: Dict[DeployableTypeNames, DeployableTypes] = {name: type for name, type in DeployableTypeEntries}
@@ -175,7 +178,7 @@ def get_git_revision(branch_or_tag: str = "HEAD") -> str:
175
178
  return check_output(["git", "rev-parse", "--short", branch_or_tag], text=True).strip()
176
179
  except CalledProcessError:
177
180
  # Return a random 7-character hash as a fallback
178
- return "".join(format(ord(str(c)), 'x') for c in os.urandom(4))[:7]
181
+ return "".join([random.choice(string.ascii_letters + string.digits) for _ in range(7)])
179
182
 
180
183
  def get_cache_deployments_revision() -> str:
181
184
  """Retrieve the cache deployments revision from a file."""
polyapi/execute.py CHANGED
@@ -1,11 +1,12 @@
1
1
  from typing import Dict, Optional
2
2
  import requests
3
3
  import os
4
- import sys
4
+ import logging
5
5
  from requests import Response
6
6
  from polyapi.config import get_api_key_and_url, get_mtls_config
7
7
  from polyapi.exceptions import PolyApiException
8
8
 
9
+ logger = logging.getLogger("poly")
9
10
 
10
11
  def direct_execute(function_type, function_id, data) -> Response:
11
12
  """ execute a specific function id/type
@@ -48,7 +49,7 @@ def direct_execute(function_type, function_id, data) -> Response:
48
49
  if (resp.status_code < 200 or resp.status_code >= 300):
49
50
  error_content = resp.content.decode("utf-8", errors="ignore")
50
51
  if function_type == 'api' and os.getenv("LOGS_ENABLED"):
51
- print(f"Error executing api function with id: {function_id}. Status code: {resp.status_code}. Request data: {data}, Response: {error_content}", file=sys.stderr)
52
+ logger.error(f"Error executing api function with id: {function_id}. Status code: {resp.status_code}. Request data: {data}, Response: {error_content}")
52
53
  elif function_type != 'api':
53
54
  raise PolyApiException(f"{resp.status_code}: {error_content}")
54
55
 
@@ -72,7 +73,7 @@ def execute(function_type, function_id, data) -> Response:
72
73
  if (resp.status_code < 200 or resp.status_code >= 300) and os.getenv("LOGS_ENABLED"):
73
74
  error_content = resp.content.decode("utf-8", errors="ignore")
74
75
  if function_type == 'api' and os.getenv("LOGS_ENABLED"):
75
- print(f"Error executing api function with id: {function_id}. Status code: {resp.status_code}. Request data: {data}, Response: {error_content}", file=sys.stderr)
76
+ logger.error(f"Error executing api function with id: {function_id}. Status code: {resp.status_code}. Request data: {data}, Response: {error_content}")
76
77
  elif function_type != 'api':
77
78
  raise PolyApiException(f"{resp.status_code}: {error_content}")
78
79
 
polyapi/schema.py CHANGED
@@ -3,8 +3,6 @@
3
3
  import logging
4
4
  import contextlib
5
5
  import re
6
- import polyapi
7
- import builtins
8
6
  from typing import Dict
9
7
  from jsonschema_gentypes.cli import process_config
10
8
  from jsonschema_gentypes import configuration
@@ -91,12 +89,9 @@ def generate_schema_types(input_data: Dict, root=None):
91
89
  }
92
90
 
93
91
  # jsonschema_gentypes prints source to stdout
94
- # no option to suppress so we do this
95
- # Not reverting the print monkeypatch causes print to bypass redirect
96
- builtins.print = polyapi.original_print
92
+ # no option to surpress so we do this
97
93
  with contextlib.redirect_stdout(None):
98
94
  process_config(config, [tmp_input])
99
- builtins.print = polyapi.log_prints
100
95
 
101
96
  with open(tmp_output, encoding='utf-8') as f:
102
97
  output = f.read()
polyapi/sync.py CHANGED
@@ -24,7 +24,7 @@ def read_file(file_path: str) -> str:
24
24
  return file.read()
25
25
 
26
26
  def group_by(items: List[Dict], key: str) -> Dict[str, List[Dict]]:
27
- grouped = {}
27
+ grouped = {} # type: ignore
28
28
  for item in items:
29
29
  grouped.setdefault(item[key], []).append(item)
30
30
  return grouped
@@ -32,7 +32,7 @@ def group_by(items: List[Dict], key: str) -> Dict[str, List[Dict]]:
32
32
  def remove_deployable_function(deployable: SyncDeployment) -> bool:
33
33
  api_key, _ = get_api_key_and_url()
34
34
  if not api_key:
35
- raise Error("Missing api key!")
35
+ raise Exception("Missing api key!")
36
36
  headers = get_auth_headers(api_key)
37
37
  url = f'{deployable["instance"]}/functions/{deployable["type"].replace("-function", "")}/{deployable["id"]}'
38
38
  response = requests.get(url, headers=headers)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: polyapi-python
3
- Version: 0.3.9.dev12
3
+ Version: 0.3.9.dev14
4
4
  Summary: The Python Client for PolyAPI, the IPaaS by Developers for Developers
5
5
  Author-email: Dan Fellin <dan@polyapi.io>
6
6
  License: MIT License
@@ -110,24 +110,6 @@ def bar():
110
110
  return "Hello World"
111
111
  ```
112
112
 
113
- ## See Server Function Logs
114
-
115
- In order to see function logs, please first set `logsEnabled` to `true` in Canopy for the function.
116
-
117
- https://na1.polyapi.io/canopy/polyui/collections/server-functions
118
-
119
- Then in your code, get the poly logger and log with it like so:
120
-
121
- ```python
122
- logger = logging.getLogger("poly")
123
- def bar():
124
- logger.warning("I AM THE LOG")
125
- return "Hello World"
126
- ```
127
-
128
- Finally, click the "Show Logs" button to see your server function logs in Canopy!
129
-
130
-
131
113
  ## Complex Types In Server Functions
132
114
 
133
115
  You can define arbitrarily complex argument and return types using TypedDicts.
@@ -1,4 +1,4 @@
1
- polyapi/__init__.py,sha256=y-NBe7eopIdiqvJOD9KRjz90AgTR-zziBovF9h-CNzo,3725
1
+ polyapi/__init__.py,sha256=hw7x4j9JNJfPdkIOZqV0X9pbYcw3_5AH1iQFdSogH-c,3235
2
2
  polyapi/__main__.py,sha256=V4zhAh_YGxno5f_KSrlkELxcuDh9bR3WSd0n-2r-qQQ,93
3
3
  polyapi/api.py,sha256=2nds6ZdNe9OHvCba4IjOPga0CAYIsib2SbhEyDDCmd8,2188
4
4
  polyapi/auth.py,sha256=EGstBjTSdAydI5hGAHeRRc1GcmHshogudb3sxCgO6zA,5341
@@ -6,10 +6,10 @@ polyapi/cli.py,sha256=unKqAoZ1hTGAeyYRfNQ6jO15Um7N4F95k__1qFue5bI,10659
6
6
  polyapi/client.py,sha256=DW6ljG_xCwAo2yz23A9QfLooE6ZUDvSpdA4e_dCQjiQ,1418
7
7
  polyapi/config.py,sha256=cAMv2n9tGN_BTvqt7V32o5F86qRhxAKyey_PoId2D8s,7638
8
8
  polyapi/constants.py,sha256=sc-FnS0SngBLvSu1ZWMs0UCf9EYD1u1Yhfr-sZXGLns,607
9
- polyapi/deployables.py,sha256=W8K6D8dypqntwjC9jAHxoR7hTfnG3Oj49nVULtq1OTQ,12133
9
+ polyapi/deployables.py,sha256=6R7XSgpTohZBcqoGd7GioQdXXKuvbBsdq_cAJ1p8jfQ,12184
10
10
  polyapi/error_handler.py,sha256=I_e0iz6VM23FLVQWJljxs2NGcl_OODbi43OcbnqBlp8,2398
11
11
  polyapi/exceptions.py,sha256=Zh7i7eCUhDuXEdUYjatkLFTeZkrx1BJ1P5ePgbJ9eIY,89
12
- polyapi/execute.py,sha256=WQH5bLG3zLpb5_21y9dUvhCLJy9kiryWcTvr9glCji0,4404
12
+ polyapi/execute.py,sha256=q4xtV6rYO8f-8hULlFTlVgoTVQSahvlMu3FHkFzYpMs,4423
13
13
  polyapi/function_cli.py,sha256=H0sVrbvRBXw_xeApe2MvQw8p_xE7jVTTOU-07Dg041A,4220
14
14
  polyapi/generate.py,sha256=thOrjq4suOkR97x00rthor96aslzzOaAAo4yxLtiuh0,21081
15
15
  polyapi/parser.py,sha256=20ZE7kSXx3UL7QVSIYYxzsnJlygVbsaDAg9q7c41WxQ,20695
@@ -18,15 +18,15 @@ polyapi/poly_tables.py,sha256=gRLGnNnLdFYuSfy-7gg4hjzzeVak8LJkfLX6n0u4RJg,15559
18
18
  polyapi/prepare.py,sha256=NQzpMIoakNovStvOGOmqSYIpTwiWXaweNSE9se10A2E,7420
19
19
  polyapi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
20
20
  polyapi/rendered_spec.py,sha256=nJEj2vRgG3N20fU4s-ThRtOIwAuTzXwXuOBIkXljDVc,2240
21
- polyapi/schema.py,sha256=NyS9OgQJM0YAuZ8CLIM_9QitfpZf4lU5MFHlyFZKHCM,5498
21
+ polyapi/schema.py,sha256=-mtRV5iL3CV0X3phXhGYFV8sLz0KouTACOKWyGO9Pwc,5309
22
22
  polyapi/server.py,sha256=YXWxhYBx-hluwDQ8Jvfpy2s8ogz0GsNTMcZVNcP5ca8,2147
23
- polyapi/sync.py,sha256=5iiQHu76my2AuGVoPRjD2t9Y0VvGJCZ8W2uG0F1sWPY,6722
23
+ polyapi/sync.py,sha256=52ODc82jBJpbNYTB9zXlrVZLR39iwDPW3cuIC3P8dbM,6742
24
24
  polyapi/typedefs.py,sha256=VEaYODLm-3a26_cK1uSRoYwenmprLOQQdoKFz4gqK_0,5587
25
25
  polyapi/utils.py,sha256=RpkXWi6jiwjozrX9iovPBK708w0W117ueN41uhQgnZU,12567
26
26
  polyapi/variables.py,sha256=SJv106ePpQP5mx7Iiafl_shtFlE8FoaO9Q8lvw-3IRg,7270
27
27
  polyapi/webhook.py,sha256=I3_uOl4f4L2-2WehzRLMVMRrB-76EiXCPA9Vzoaj30I,5326
28
- polyapi_python-0.3.9.dev12.dist-info/licenses/LICENSE,sha256=6b_I7aPVp8JXhqQwdw7_B84Ca0S4JGjHj0sr_1VOdB4,1068
29
- polyapi_python-0.3.9.dev12.dist-info/METADATA,sha256=WO8t5B5Lsb6GSNLjajkTvd63F8zTeFjMoacRx3eRfVs,5785
30
- polyapi_python-0.3.9.dev12.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
31
- polyapi_python-0.3.9.dev12.dist-info/top_level.txt,sha256=CEFllOnzowci_50RYJac-M54KD2IdAptFsayVVF_f04,8
32
- polyapi_python-0.3.9.dev12.dist-info/RECORD,,
28
+ polyapi_python-0.3.9.dev14.dist-info/licenses/LICENSE,sha256=6b_I7aPVp8JXhqQwdw7_B84Ca0S4JGjHj0sr_1VOdB4,1068
29
+ polyapi_python-0.3.9.dev14.dist-info/METADATA,sha256=ejIs8-9z8g08GXXyMrAEsAPIAvuDv3nus-bcd8i-PW4,5318
30
+ polyapi_python-0.3.9.dev14.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
31
+ polyapi_python-0.3.9.dev14.dist-info/top_level.txt,sha256=CEFllOnzowci_50RYJac-M54KD2IdAptFsayVVF_f04,8
32
+ polyapi_python-0.3.9.dev14.dist-info/RECORD,,