polyapi-python 0.2.5.dev12__tar.gz → 0.2.6__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 (39) hide show
  1. {polyapi_python-0.2.5.dev12/polyapi_python.egg-info → polyapi_python-0.2.6}/PKG-INFO +2 -2
  2. {polyapi_python-0.2.5.dev12 → polyapi_python-0.2.6}/polyapi/cli.py +4 -3
  3. {polyapi_python-0.2.5.dev12 → polyapi_python-0.2.6}/polyapi/function_cli.py +6 -4
  4. {polyapi_python-0.2.5.dev12 → polyapi_python-0.2.6}/polyapi/generate.py +3 -3
  5. {polyapi_python-0.2.5.dev12 → polyapi_python-0.2.6}/polyapi/rendered_spec.py +8 -13
  6. {polyapi_python-0.2.5.dev12 → polyapi_python-0.2.6}/polyapi/schema.py +2 -1
  7. {polyapi_python-0.2.5.dev12 → polyapi_python-0.2.6}/polyapi/utils.py +18 -4
  8. {polyapi_python-0.2.5.dev12 → polyapi_python-0.2.6}/polyapi/webhook.py +2 -2
  9. {polyapi_python-0.2.5.dev12 → polyapi_python-0.2.6/polyapi_python.egg-info}/PKG-INFO +2 -2
  10. {polyapi_python-0.2.5.dev12 → polyapi_python-0.2.6}/polyapi_python.egg-info/requires.txt +1 -1
  11. {polyapi_python-0.2.5.dev12 → polyapi_python-0.2.6}/pyproject.toml +2 -2
  12. {polyapi_python-0.2.5.dev12 → polyapi_python-0.2.6}/tests/test_api.py +5 -4
  13. {polyapi_python-0.2.5.dev12 → polyapi_python-0.2.6}/tests/test_auth.py +0 -1
  14. {polyapi_python-0.2.5.dev12 → polyapi_python-0.2.6}/tests/test_server.py +3 -1
  15. {polyapi_python-0.2.5.dev12 → polyapi_python-0.2.6}/LICENSE +0 -0
  16. {polyapi_python-0.2.5.dev12 → polyapi_python-0.2.6}/README.md +0 -0
  17. {polyapi_python-0.2.5.dev12 → polyapi_python-0.2.6}/polyapi/__init__.py +0 -0
  18. {polyapi_python-0.2.5.dev12 → polyapi_python-0.2.6}/polyapi/__main__.py +0 -0
  19. {polyapi_python-0.2.5.dev12 → polyapi_python-0.2.6}/polyapi/api.py +0 -0
  20. {polyapi_python-0.2.5.dev12 → polyapi_python-0.2.6}/polyapi/auth.py +0 -0
  21. {polyapi_python-0.2.5.dev12 → polyapi_python-0.2.6}/polyapi/client.py +0 -0
  22. {polyapi_python-0.2.5.dev12 → polyapi_python-0.2.6}/polyapi/config.py +0 -0
  23. {polyapi_python-0.2.5.dev12 → polyapi_python-0.2.6}/polyapi/constants.py +0 -0
  24. {polyapi_python-0.2.5.dev12 → polyapi_python-0.2.6}/polyapi/error_handler.py +0 -0
  25. {polyapi_python-0.2.5.dev12 → polyapi_python-0.2.6}/polyapi/exceptions.py +0 -0
  26. {polyapi_python-0.2.5.dev12 → polyapi_python-0.2.6}/polyapi/execute.py +0 -0
  27. {polyapi_python-0.2.5.dev12 → polyapi_python-0.2.6}/polyapi/py.typed +0 -0
  28. {polyapi_python-0.2.5.dev12 → polyapi_python-0.2.6}/polyapi/server.py +0 -0
  29. {polyapi_python-0.2.5.dev12 → polyapi_python-0.2.6}/polyapi/typedefs.py +0 -0
  30. {polyapi_python-0.2.5.dev12 → polyapi_python-0.2.6}/polyapi/variables.py +0 -0
  31. {polyapi_python-0.2.5.dev12 → polyapi_python-0.2.6}/polyapi_python.egg-info/SOURCES.txt +0 -0
  32. {polyapi_python-0.2.5.dev12 → polyapi_python-0.2.6}/polyapi_python.egg-info/dependency_links.txt +0 -0
  33. {polyapi_python-0.2.5.dev12 → polyapi_python-0.2.6}/polyapi_python.egg-info/top_level.txt +0 -0
  34. {polyapi_python-0.2.5.dev12 → polyapi_python-0.2.6}/setup.cfg +0 -0
  35. {polyapi_python-0.2.5.dev12 → polyapi_python-0.2.6}/tests/test_function_cli.py +0 -0
  36. {polyapi_python-0.2.5.dev12 → polyapi_python-0.2.6}/tests/test_rendered_spec.py +0 -0
  37. {polyapi_python-0.2.5.dev12 → polyapi_python-0.2.6}/tests/test_schema.py +0 -0
  38. {polyapi_python-0.2.5.dev12 → polyapi_python-0.2.6}/tests/test_utils.py +0 -0
  39. {polyapi_python-0.2.5.dev12 → polyapi_python-0.2.6}/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.5.dev12
3
+ Version: 0.2.6
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
@@ -30,7 +30,7 @@ Description-Content-Type: text/markdown
30
30
  License-File: LICENSE
31
31
  Requires-Dist: requests==2.31.0
32
32
  Requires-Dist: typing_extensions==4.10.0
33
- Requires-Dist: jsonschema-gentypes==2.4.0
33
+ Requires-Dist: jsonschema-gentypes==2.6.0
34
34
  Requires-Dist: pydantic==2.6.4
35
35
  Requires-Dist: stdlib_list==0.10.0
36
36
  Requires-Dist: colorama==0.4.4
@@ -27,6 +27,7 @@ def execute_from_cli() -> None:
27
27
  parser.add_argument("--client", action="store_true", help="Pass --client when adding function to add a client function.")
28
28
  parser.add_argument("--server", action="store_true", help="Pass --server when adding function to add a server function.")
29
29
  parser.add_argument("--logs", action="store_true", help="Pass --logs when adding function if you want to store and see the function logs.")
30
+ parser.add_argument("--skip-generate", action="store_true", help="Pass --skip-generate to skip generating the library after adding a function.")
30
31
  parser.add_argument("command", choices=CLI_COMMANDS)
31
32
  parser.add_argument("subcommands", nargs="*")
32
33
  args = parser.parse_args()
@@ -44,8 +45,8 @@ def execute_from_cli() -> None:
44
45
  clear_config()
45
46
  generate()
46
47
  elif command == "update_rendered_spec":
47
- assert len(args.subcommands) == 2
48
- updated = get_and_update_rendered_spec(args.subcommands[0], args.subcommands[1])
48
+ assert len(args.subcommands) == 1
49
+ updated = get_and_update_rendered_spec(args.subcommands[0])
49
50
  if updated:
50
51
  print("Updated rendered spec!")
51
52
  else:
@@ -55,4 +56,4 @@ def execute_from_cli() -> None:
55
56
  print("Clearing the generated library...")
56
57
  clear()
57
58
  elif command == "function":
58
- function_add_or_update(args.context, args.description, args.client, args.server, args.logs, args.subcommands)
59
+ function_add_or_update(args.context, args.description, args.client, args.server, args.logs, args.subcommands, not args.skip_generate)
@@ -207,6 +207,7 @@ def function_add_or_update(
207
207
  server: bool,
208
208
  logs_enabled: bool,
209
209
  subcommands: List,
210
+ generate: bool = True,
210
211
  ):
211
212
  parser = argparse.ArgumentParser()
212
213
  parser.add_argument("subcommand", choices=["add"])
@@ -268,10 +269,11 @@ def function_add_or_update(
268
269
  print_green("DEPLOYED")
269
270
  function_id = resp.json()["id"]
270
271
  print(f"Function ID: {function_id}")
271
- print("Generating new custom function...", end="")
272
- functions = get_functions_and_parse(limit_ids=[function_id])
273
- generate_functions(functions)
274
- print_green("DONE")
272
+ if generate:
273
+ print("Generating new custom function...", end="")
274
+ functions = get_functions_and_parse(limit_ids=[function_id])
275
+ generate_functions(functions)
276
+ print_green("DONE")
275
277
  else:
276
278
  print("Error adding function.")
277
279
  print(resp.status_code)
@@ -11,7 +11,7 @@ from polyapi.webhook import render_webhook_handle
11
11
  from .typedefs import PropertySpecification, SpecificationDto, VariableSpecDto
12
12
  from .api import render_api_function
13
13
  from .server import render_server_function
14
- from .utils import add_import_to_init, get_auth_headers, init_the_init
14
+ from .utils import add_import_to_init, get_auth_headers, init_the_init, to_func_namespace
15
15
  from .variables import generate_variables
16
16
  from .config import get_api_key_and_url, initialize_config
17
17
 
@@ -232,10 +232,10 @@ def add_function_file(
232
232
  # add function to init
233
233
  init_path = os.path.join(full_path, "__init__.py")
234
234
  with open(init_path, "a") as f:
235
- f.write(f"\n\nfrom . import _{function_name}\n\n{func_str}")
235
+ f.write(f"\n\nfrom . import {to_func_namespace(function_name)}\n\n{func_str}")
236
236
 
237
237
  # add type_defs to underscore file
238
- file_path = os.path.join(full_path, f"_{function_name}.py")
238
+ file_path = os.path.join(full_path, f"{to_func_namespace(function_name)}.py")
239
239
  with open(file_path, "w") as f:
240
240
  f.write(func_type_defs)
241
241
 
@@ -7,7 +7,7 @@ from polyapi.generate import read_cached_specs, render_spec
7
7
  from polyapi.typedefs import SpecificationDto
8
8
 
9
9
 
10
- def update_rendered_spec(api_key: str, spec: SpecificationDto):
10
+ def update_rendered_spec(spec: SpecificationDto):
11
11
  print("Updating rendered spec...")
12
12
  func_str, type_defs = render_spec(spec)
13
13
  data = {
@@ -27,9 +27,7 @@ def update_rendered_spec(api_key: str, spec: SpecificationDto):
27
27
  raise NotImplementedError("todo")
28
28
 
29
29
  # use super key on develop-k8s here!
30
- _, base_url = get_api_key_and_url()
31
- if not base_url:
32
- base_url = os.environ.get("HOST_URL")
30
+ api_key, base_url = get_api_key_and_url()
33
31
 
34
32
  url = f"{base_url}/functions/rendered-specs"
35
33
  headers = {"Authorization": f"Bearer {api_key}"}
@@ -37,11 +35,8 @@ def update_rendered_spec(api_key: str, spec: SpecificationDto):
37
35
  assert resp.status_code == 201, (resp.text, resp.status_code)
38
36
 
39
37
 
40
- def _get_spec(api_key: str, spec_id: str) -> Optional[SpecificationDto]:
41
- _, base_url = get_api_key_and_url()
42
- if not base_url:
43
- base_url = os.environ.get("HOST_URL")
44
-
38
+ def _get_spec(spec_id: str) -> Optional[SpecificationDto]:
39
+ api_key, base_url = get_api_key_and_url()
45
40
  url = f"{base_url}/specs"
46
41
  headers = {"Authorization": f"Bearer {api_key}"}
47
42
  resp = requests.get(url, headers=headers)
@@ -55,10 +50,10 @@ def _get_spec(api_key: str, spec_id: str) -> Optional[SpecificationDto]:
55
50
  raise NotImplementedError(resp.content)
56
51
 
57
52
 
58
- def get_and_update_rendered_spec(api_key: str, spec_id: str) -> bool:
59
- spec = _get_spec(api_key, spec_id)
53
+ def get_and_update_rendered_spec(spec_id: str) -> bool:
54
+ spec = _get_spec(spec_id)
60
55
  if spec:
61
- update_rendered_spec(api_key, spec)
56
+ update_rendered_spec(spec)
62
57
  return True
63
58
  return False
64
59
 
@@ -70,4 +65,4 @@ def save_rendered_specs() -> None:
70
65
  for spec in api_specs:
71
66
  assert spec["function"]
72
67
  print("adding", spec["context"], spec["name"])
73
- update_rendered_spec("FIXME", spec)
68
+ update_rendered_spec(spec)
@@ -64,6 +64,7 @@ def generate_schema_types(input_data: Dict, root=None):
64
64
  "source": tmp_input,
65
65
  "destination": tmp_output,
66
66
  "root_name": root,
67
+ "api_arguments": {"get_name_properties": "UpperFirst"},
67
68
  }
68
69
  ],
69
70
  }
@@ -71,7 +72,7 @@ def generate_schema_types(input_data: Dict, root=None):
71
72
  # jsonschema_gentypes prints source to stdout
72
73
  # no option to surpress so we do this
73
74
  with contextlib.redirect_stdout(None):
74
- process_config(config)
75
+ process_config(config, [tmp_input])
75
76
 
76
77
  with open(tmp_output) as f:
77
78
  output = f.read()
@@ -75,11 +75,11 @@ def add_type_import_path(function_name: str, arg: str) -> str:
75
75
  else:
76
76
  if '"' in sub:
77
77
  sub = sub.replace('"', "")
78
- return f'List["_{function_name}.{camelCase(sub)}"]'
78
+ return f'List["{to_func_namespace(function_name)}.{camelCase(sub)}"]'
79
79
  else:
80
- return f'List[_{function_name}.{camelCase(sub)}]'
80
+ return f'List[{to_func_namespace(function_name)}.{camelCase(sub)}]'
81
81
 
82
- return f'_{function_name}.{camelCase(arg)}'
82
+ return f'{to_func_namespace(function_name)}.{camelCase(arg)}'
83
83
 
84
84
 
85
85
  def get_type_and_def(type_spec: PropertyType) -> Tuple[str, str]:
@@ -183,4 +183,18 @@ def poly_full_path(context, name) -> str:
183
183
  path = context + "." + name
184
184
  else:
185
185
  path = name
186
- return f"poly.{path}"
186
+ return f"poly.{path}"
187
+
188
+
189
+ RESERVED_TYPES = {"List", "Dict", "Any", "Optional", "Callable"}
190
+
191
+
192
+ def to_func_namespace(s: str) -> str:
193
+ """ convert a function name to some function namespace
194
+ by default it is
195
+ """
196
+ rv = s[0].upper() + s[1:]
197
+ if rv in RESERVED_TYPES:
198
+ return "_" + rv
199
+ else:
200
+ return rv
@@ -6,7 +6,7 @@ from typing import Any, Dict, List, Tuple
6
6
 
7
7
  from polyapi.config import get_api_key_and_url
8
8
  from polyapi.typedefs import PropertySpecification
9
- from polyapi.utils import parse_arguments, poly_full_path
9
+ from polyapi.utils import parse_arguments, poly_full_path, to_func_namespace
10
10
 
11
11
  # all active webhook handlers, used by unregister_all to cleanup
12
12
  active_handlers: List[Dict[str, Any]] = []
@@ -124,7 +124,7 @@ def render_webhook_handle(
124
124
 
125
125
  if "WebhookEventType" in function_args:
126
126
  # let's add the function name import!
127
- function_args = function_args.replace("WebhookEventType", f"_{function_name}.WebhookEventType")
127
+ function_args = function_args.replace("WebhookEventType", f"{to_func_namespace(function_name)}.WebhookEventType")
128
128
 
129
129
  func_str = WEBHOOK_TEMPLATE.format(
130
130
  description=function_description,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: polyapi-python
3
- Version: 0.2.5.dev12
3
+ Version: 0.2.6
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
@@ -30,7 +30,7 @@ Description-Content-Type: text/markdown
30
30
  License-File: LICENSE
31
31
  Requires-Dist: requests==2.31.0
32
32
  Requires-Dist: typing_extensions==4.10.0
33
- Requires-Dist: jsonschema-gentypes==2.4.0
33
+ Requires-Dist: jsonschema-gentypes==2.6.0
34
34
  Requires-Dist: pydantic==2.6.4
35
35
  Requires-Dist: stdlib_list==0.10.0
36
36
  Requires-Dist: colorama==0.4.4
@@ -1,6 +1,6 @@
1
1
  requests==2.31.0
2
2
  typing_extensions==4.10.0
3
- jsonschema-gentypes==2.4.0
3
+ jsonschema-gentypes==2.6.0
4
4
  pydantic==2.6.4
5
5
  stdlib_list==0.10.0
6
6
  colorama==0.4.4
@@ -3,13 +3,13 @@ requires = ["setuptools>=61.2", "wheel"]
3
3
 
4
4
  [project]
5
5
  name = "polyapi-python"
6
- version = "0.2.5.dev12"
6
+ version = "0.2.6"
7
7
  description = "The Python Client for PolyAPI, the IPaaS by Developers for Developers"
8
8
  authors = [{ name = "Dan Fellin", email = "dan@polyapi.io" }]
9
9
  dependencies = [
10
10
  "requests==2.31.0",
11
11
  "typing_extensions==4.10.0",
12
- "jsonschema-gentypes==2.4.0",
12
+ "jsonschema-gentypes==2.6.0",
13
13
  "pydantic==2.6.4",
14
14
  "stdlib_list==0.10.0",
15
15
  "colorama==0.4.4",
@@ -1,6 +1,7 @@
1
1
  import unittest
2
2
 
3
3
  from polyapi.api import render_api_function
4
+ from polyapi.utils import to_func_namespace
4
5
 
5
6
  ACCUWEATHER = {
6
7
  "id": "f7588018-2364-4586-b60d",
@@ -235,7 +236,7 @@ class T(unittest.TestCase):
235
236
  )
236
237
  self.assertIn(ACCUWEATHER["id"], func_str)
237
238
  self.assertIn("locationId: int,", func_str)
238
- self.assertIn(f"-> _{name}.{name}Response", func_str)
239
+ self.assertIn(f"-> {to_func_namespace(name)}.{name}Response", func_str)
239
240
 
240
241
  def test_render_function_zillow(self):
241
242
  name = ZILLOW["name"]
@@ -249,7 +250,7 @@ class T(unittest.TestCase):
249
250
  )
250
251
  self.assertIn(ZILLOW["id"], func_str)
251
252
  self.assertIn("locationId: int,", func_str)
252
- self.assertIn(f"-> _{name}.{name}Response", func_str)
253
+ self.assertIn(f"-> {to_func_namespace(name)}.{name}Response", func_str)
253
254
 
254
255
  def test_render_function_twilio_api(self):
255
256
  name = TWILIO["name"]
@@ -264,7 +265,7 @@ class T(unittest.TestCase):
264
265
  self.assertIn(TWILIO["id"], func_str)
265
266
  self.assertIn("conversationSID: str", func_str)
266
267
  self.assertIn("authToken: str", func_str)
267
- self.assertIn(f"-> _{name}.{name}Response", func_str)
268
+ self.assertIn(f"-> {to_func_namespace(name)}.{name}Response", func_str)
268
269
 
269
270
  def test_render_function_twilio_get_details(self):
270
271
  # same test but try it as a serverFunction rather than an apiFunction
@@ -278,6 +279,6 @@ class T(unittest.TestCase):
278
279
  TWILIO_GET_DETAILS["function"]["returnType"],
279
280
  )
280
281
  self.assertIn(TWILIO_GET_DETAILS["id"], func_str)
281
- self.assertIn(f"-> _{name}.{name}Response", func_str)
282
+ self.assertIn(f"-> {to_func_namespace(name)}.{name}Response", func_str)
282
283
  self.assertIn("class SubresourceUris", func_type_defs)
283
284
  # self.assertIn('Required["SubresourceUris"]', func_type_defs)
@@ -136,4 +136,3 @@ class T(unittest.TestCase):
136
136
  self.assertIn(GET_TOKEN["id"], func_str)
137
137
  # self.assertIn("conversationSID: str", func_str)
138
138
  # self.assertIn("authToken: str", func_str)
139
- # self.assertIn(f"-> _{name}.ResponseType", func_str)
@@ -1,5 +1,7 @@
1
1
  import unittest
2
2
 
3
+ from polyapi.utils import to_func_namespace
4
+
3
5
  from .test_api import TWILIO
4
6
  from polyapi.server import render_server_function
5
7
 
@@ -45,7 +47,7 @@ class T(unittest.TestCase):
45
47
  self.assertIn(TWILIO["id"], func_str)
46
48
  self.assertIn("conversationSID: str", func_str)
47
49
  self.assertIn("authToken: str", func_str)
48
- self.assertIn(f"-> _{name}.ResponseType", func_str)
50
+ self.assertIn(f"-> {to_func_namespace(name)}.ResponseType", func_str)
49
51
 
50
52
  def test_render_function_get_products_count(self):
51
53
  return_type = GET_PRODUCTS_COUNT["function"]["returnType"]