polyapi-python 0.3.4.dev2__py3-none-any.whl → 0.3.5.dev1__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/cli.py CHANGED
@@ -45,10 +45,12 @@ def execute_from_cli():
45
45
  # Generate command
46
46
  generate_parser = subparsers.add_parser("generate", help="Generates Poly library")
47
47
  generate_parser.add_argument("--no-types", action="store_true", help="Generate SDK without type definitions")
48
+ generate_parser.add_argument("--contexts", type=str, required=False, help="Contexts to generate")
48
49
 
49
50
  def generate_command(args):
50
51
  initialize_config()
51
- generate(no_types=args.no_types)
52
+ contexts = args.contexts.split(",") if args.contexts else None
53
+ generate(contexts=contexts, no_types=args.no_types)
52
54
 
53
55
  generate_parser.set_defaults(command=generate_command)
54
56
 
@@ -69,6 +71,7 @@ def execute_from_cli():
69
71
  fn_add_parser.add_argument("--logs", choices=["enabled", "disabled"], default=None, help="Enable or disable logs for the function.")
70
72
  fn_add_parser.add_argument("--execution-api-key", required=False, default="", help="API key for execution (for server functions only).")
71
73
  fn_add_parser.add_argument("--disable-ai", "--skip-generate", action="store_true", help="Pass --disable-ai skip AI generation of missing descriptions")
74
+ fn_add_parser.add_argument("--generate-contexts", type=str, help="Server function only – only include certain contexts to speed up function execution")
72
75
 
73
76
  def add_function(args):
74
77
  initialize_config()
@@ -80,6 +83,8 @@ def execute_from_cli():
80
83
  err = "You must specify `--server` or `--client`."
81
84
  elif logs_enabled and not args.server:
82
85
  err = "Option `logs` is only for server functions (--server)."
86
+ elif args.generate_contexts and not args.server:
87
+ err = "Option `generate-contexts` is only for server functions (--server)."
83
88
 
84
89
  if err:
85
90
  print_red("ERROR")
@@ -95,7 +100,8 @@ def execute_from_cli():
95
100
  server=args.server,
96
101
  logs_enabled=logs_enabled,
97
102
  generate=not args.disable_ai,
98
- execution_api_key=args.execution_api_key
103
+ execution_api_key=args.execution_api_key,
104
+ generate_contexts=args.generate_contexts
99
105
  )
100
106
 
101
107
  fn_add_parser.set_defaults(command=add_function)
polyapi/config.py CHANGED
@@ -3,7 +3,7 @@ import os
3
3
  import configparser
4
4
  from typing import Tuple
5
5
 
6
- from polyapi.utils import is_valid_polyapi_url, is_valid_uuid, print_green, print_yellow
6
+ from polyapi.utils import is_valid_polyapi_url, print_green, print_yellow
7
7
 
8
8
  # cached values
9
9
  API_KEY = None
@@ -78,8 +78,6 @@ def initialize_config(force=False):
78
78
  errors = []
79
79
  if not is_valid_polyapi_url(url):
80
80
  errors.append(f"{url} is not a valid Poly API Base URL")
81
- if not is_valid_uuid(key):
82
- errors.append(f"{key} is not a valid Poly App Key or User Key")
83
81
  if errors:
84
82
  print_yellow("\n".join(errors))
85
83
  sys.exit(1)
polyapi/function_cli.py CHANGED
@@ -24,6 +24,7 @@ def function_add_or_update(
24
24
  client: bool,
25
25
  server: bool,
26
26
  logs_enabled: Optional[bool],
27
+ generate_contexts: Optional[str],
27
28
  generate: bool = True,
28
29
  execution_api_key: str = ""
29
30
  ):
@@ -59,6 +60,9 @@ def function_add_or_update(
59
60
  "logsEnabled": logs_enabled,
60
61
  }
61
62
 
63
+ if generate_contexts:
64
+ data["generateContexts"] = generate_contexts.split(",")
65
+
62
66
  if server and parsed["dependencies"]:
63
67
  print_yellow(
64
68
  "\nPlease note that deploying your functions will take a few minutes because it makes use of libraries other than polyapi."
@@ -87,7 +91,8 @@ def function_add_or_update(
87
91
  function_id = resp.json()["id"]
88
92
  print(f"Function ID: {function_id}")
89
93
  if generate:
90
- generate_library()
94
+ contexts=generate_contexts.split(",") if generate_contexts else None
95
+ generate_library(contexts=contexts)
91
96
  else:
92
97
  print("Error adding function.")
93
98
  print(resp.status_code)
polyapi/generate.py CHANGED
@@ -2,7 +2,7 @@ import json
2
2
  import requests
3
3
  import os
4
4
  import shutil
5
- from typing import List, Tuple, cast
5
+ from typing import List, Optional, Tuple, cast
6
6
 
7
7
  from .auth import render_auth_function
8
8
  from .client import render_client_function
@@ -36,12 +36,16 @@ Unresolved schema, please add the following schema to complete it:
36
36
  path:'''
37
37
 
38
38
 
39
- def get_specs(no_types: bool = False) -> List:
39
+ def get_specs(contexts=Optional[List[str]], no_types: bool = False) -> List:
40
40
  api_key, api_url = get_api_key_and_url()
41
41
  assert api_key
42
42
  headers = get_auth_headers(api_key)
43
43
  url = f"{api_url}/specs"
44
44
  params = {"noTypes": str(no_types).lower()}
45
+
46
+ if contexts:
47
+ params["contexts"] = contexts
48
+
45
49
  resp = requests.get(url, headers=headers, params=params)
46
50
  if resp.status_code == 200:
47
51
  return resp.json()
@@ -197,11 +201,12 @@ def remove_old_library():
197
201
  shutil.rmtree(path)
198
202
 
199
203
 
200
- def generate(no_types: bool = False) -> None:
201
- print("Generating Poly Python SDK...", end="", flush=True)
204
+ def generate(contexts: Optional[List[str]] = None, no_types: bool = False) -> None:
205
+ generate_msg = f"Generating Poly Python SDK for contexts ${contexts}..." if contexts else "Generating Poly Python SDK..."
206
+ print(generate_msg, end="", flush=True)
202
207
  remove_old_library()
203
208
 
204
- specs = get_specs(no_types=no_types)
209
+ specs = get_specs(no_types=no_types, contexts=contexts)
205
210
  cache_specs(specs)
206
211
 
207
212
  limit_ids: List[str] = [] # useful for narrowing down generation to a single function to debug
polyapi/utils.py CHANGED
@@ -2,6 +2,7 @@ import keyword
2
2
  import re
3
3
  import os
4
4
  import uuid
5
+ from urllib.parse import urlparse
5
6
  from typing import Tuple, List
6
7
  from colorama import Fore, Style
7
8
  from polyapi.constants import BASIC_PYTHON_TYPES
@@ -261,21 +262,16 @@ valid_subdomains = ["na[1-2]", "eu[1-2]", "dev"]
261
262
 
262
263
 
263
264
  def is_valid_polyapi_url(_url: str):
265
+ # in dev allow localhost (and 127.0.0.1) over http *or* https
266
+ parsed = urlparse(_url)
267
+ if parsed.scheme in ("http", "https") and parsed.hostname in ("localhost", "127.0.0.1"):
268
+ return True
269
+
264
270
  # Join the subdomains into a pattern
265
271
  subdomain_pattern = "|".join(valid_subdomains)
266
272
  pattern = rf"^https://({subdomain_pattern})\.polyapi\.io$"
267
273
  return re.match(pattern, _url) is not None
268
274
 
269
-
270
- def is_valid_uuid(uuid_string, version=4):
271
- try:
272
- uuid_obj = uuid.UUID(uuid_string, version=version)
273
- except ValueError:
274
- return False
275
-
276
- return str(uuid_obj) == uuid_string
277
-
278
-
279
275
  def return_type_already_defined_in_args(return_type_name: str, args_def: str) -> bool:
280
276
  """
281
277
  Checks if the return_type_name preceded optionally by 'class ' and followed by ' =' exists in args_def.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: polyapi-python
3
- Version: 0.3.4.dev2
3
+ Version: 0.3.5.dev1
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
@@ -2,16 +2,16 @@ polyapi/__init__.py,sha256=a1Poy1kaTncYnUg6nWRcTjVm-R1CUQk12UX7VYQ9d5k,616
2
2
  polyapi/__main__.py,sha256=V4zhAh_YGxno5f_KSrlkELxcuDh9bR3WSd0n-2r-qQQ,93
3
3
  polyapi/api.py,sha256=f1037HFJF7DtQSSypM4PE5AmmxWxjd0JiW6ARZqrgac,1879
4
4
  polyapi/auth.py,sha256=zrIGatjba5GwUTNjKj1GHQWTEDP9B-HrSzCKbLFoqvc,5336
5
- polyapi/cli.py,sha256=EVT_mgmaXP4NSk4v3Nr9d5AmeMFEcwVYSk2LNwv7bUs,8375
5
+ polyapi/cli.py,sha256=jtKXARbT9AOgYTR6nf3OiwiPvsyUlLVbyynEA84PDzw,8924
6
6
  polyapi/client.py,sha256=CoFDYvyKsqL4wPQbUDIr0Qb8Q5eD92xN4OEEcJEVuGQ,1296
7
- polyapi/config.py,sha256=Vgc_q9FYXWGCOTr13EbpD0AwHks0Nflimy1NtZxgynA,3088
7
+ polyapi/config.py,sha256=IGPIA3-1iSejLLly3xW7ctLzTSM_TdGoqeqlQiU5C9Q,2954
8
8
  polyapi/constants.py,sha256=sc-FnS0SngBLvSu1ZWMs0UCf9EYD1u1Yhfr-sZXGLns,607
9
9
  polyapi/deployables.py,sha256=WVcNNB6W5ZW_-ukf_kK3moRcnwIkC-O4te6vLepjcco,11936
10
10
  polyapi/error_handler.py,sha256=I_e0iz6VM23FLVQWJljxs2NGcl_OODbi43OcbnqBlp8,2398
11
11
  polyapi/exceptions.py,sha256=Zh7i7eCUhDuXEdUYjatkLFTeZkrx1BJ1P5ePgbJ9eIY,89
12
12
  polyapi/execute.py,sha256=akfiJMIlRCPNtDfRvGd11baGC7F8gjwD3Uv8w9RVND4,1967
13
- polyapi/function_cli.py,sha256=htgmcx_dPmw4_5NKRgIivcwS7D8bkOsxCTOrJhzV3pU,3989
14
- polyapi/generate.py,sha256=SIWyl7sZjRL33xViQvIo5adVsE5R9epuOF9rSB-audU,11638
13
+ polyapi/function_cli.py,sha256=iGTjbFJQvfVOAtbcM5xbKbXcG-m22TrBRyZY-NYGDPo,4216
14
+ polyapi/generate.py,sha256=KdkhvkefHbSWr-XqStLrDNtE61-beIbdIClq9_y5XcI,11899
15
15
  polyapi/parser.py,sha256=mdoh4pNq8pyiHE0-i6Coqj8frEXfBLRk6itpAXMrrgI,20373
16
16
  polyapi/poly_schemas.py,sha256=T4kfZyfgVLiqLD28GmYNiHnrNx77J_HO4uzk8LUAhlo,3137
17
17
  polyapi/prepare.py,sha256=Q8CWV4kmZ2dbXYVsud34AgJkj5ymcQ_IcYhLuikc9yk,6659
@@ -21,11 +21,11 @@ polyapi/schema.py,sha256=ZSzeUjpqigLvE4tFKB7y4AaZG-W5N5Z9wMH-F-vjMBU,4616
21
21
  polyapi/server.py,sha256=YXWxhYBx-hluwDQ8Jvfpy2s8ogz0GsNTMcZVNcP5ca8,2147
22
22
  polyapi/sync.py,sha256=PGdC0feBBjEVrF3d9EluW_OAxbWuzSrfh84czma8kWg,6476
23
23
  polyapi/typedefs.py,sha256=KniVl7vwcDOhgAJmHSgTJKkP0rKWvSLIPOGsWuf9jRU,2239
24
- polyapi/utils.py,sha256=K6QMKEf2fgmh3AswyNBADfv53sIOSAbXmGx2MaW5vy8,10261
24
+ polyapi/utils.py,sha256=vq2seXLhbp9pOvemhS71DDwi1h4YofI8TXiRDjt5Eoo,10308
25
25
  polyapi/variables.py,sha256=d36-trnfTL_8m2NkorMiImb4O3UrJbiFV38CHxV5i0A,4200
26
26
  polyapi/webhook.py,sha256=LWv28c2MLz_OKBI_Nn7WR4C-gs1SWgbdXsoxIIf-9UI,4886
27
- polyapi_python-0.3.4.dev2.dist-info/licenses/LICENSE,sha256=6b_I7aPVp8JXhqQwdw7_B84Ca0S4JGjHj0sr_1VOdB4,1068
28
- polyapi_python-0.3.4.dev2.dist-info/METADATA,sha256=RjB5UQgq8Ig7RkiRW5lC5e_UOh5kDeHe5fTjaZpGooU,5782
29
- polyapi_python-0.3.4.dev2.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
30
- polyapi_python-0.3.4.dev2.dist-info/top_level.txt,sha256=CEFllOnzowci_50RYJac-M54KD2IdAptFsayVVF_f04,8
31
- polyapi_python-0.3.4.dev2.dist-info/RECORD,,
27
+ polyapi_python-0.3.5.dev1.dist-info/licenses/LICENSE,sha256=6b_I7aPVp8JXhqQwdw7_B84Ca0S4JGjHj0sr_1VOdB4,1068
28
+ polyapi_python-0.3.5.dev1.dist-info/METADATA,sha256=YptreUILVlcZGNQomNmBqYS1UVozCFhSWRVzR4lmBrE,5782
29
+ polyapi_python-0.3.5.dev1.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
30
+ polyapi_python-0.3.5.dev1.dist-info/top_level.txt,sha256=CEFllOnzowci_50RYJac-M54KD2IdAptFsayVVF_f04,8
31
+ polyapi_python-0.3.5.dev1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.3.1)
2
+ Generator: setuptools (80.4.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5