polyapi-python 0.1.0.dev8__tar.gz → 0.1.0.dev10__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 (29) hide show
  1. {polyapi-python-0.1.0.dev8/polyapi_python.egg-info → polyapi-python-0.1.0.dev10}/PKG-INFO +10 -1
  2. {polyapi-python-0.1.0.dev8 → polyapi-python-0.1.0.dev10}/README.md +8 -0
  3. {polyapi-python-0.1.0.dev8 → polyapi-python-0.1.0.dev10}/polyapi/api.py +1 -2
  4. {polyapi-python-0.1.0.dev8 → polyapi-python-0.1.0.dev10}/polyapi/cli.py +16 -7
  5. {polyapi-python-0.1.0.dev8 → polyapi-python-0.1.0.dev10}/polyapi/config.py +4 -0
  6. {polyapi-python-0.1.0.dev8 → polyapi-python-0.1.0.dev10}/polyapi/function_cli.py +23 -8
  7. {polyapi-python-0.1.0.dev8 → polyapi-python-0.1.0.dev10}/polyapi/utils.py +14 -1
  8. {polyapi-python-0.1.0.dev8 → polyapi-python-0.1.0.dev10}/polyapi/variables.py +0 -1
  9. {polyapi-python-0.1.0.dev8 → polyapi-python-0.1.0.dev10/polyapi_python.egg-info}/PKG-INFO +10 -1
  10. {polyapi-python-0.1.0.dev8 → polyapi-python-0.1.0.dev10}/polyapi_python.egg-info/requires.txt +1 -0
  11. {polyapi-python-0.1.0.dev8 → polyapi-python-0.1.0.dev10}/pyproject.toml +2 -2
  12. {polyapi-python-0.1.0.dev8 → polyapi-python-0.1.0.dev10}/LICENSE +0 -0
  13. {polyapi-python-0.1.0.dev8 → polyapi-python-0.1.0.dev10}/polyapi/__init__.py +0 -0
  14. {polyapi-python-0.1.0.dev8 → polyapi-python-0.1.0.dev10}/polyapi/__main__.py +0 -0
  15. {polyapi-python-0.1.0.dev8 → polyapi-python-0.1.0.dev10}/polyapi/constants.py +0 -0
  16. {polyapi-python-0.1.0.dev8 → polyapi-python-0.1.0.dev10}/polyapi/exceptions.py +0 -0
  17. {polyapi-python-0.1.0.dev8 → polyapi-python-0.1.0.dev10}/polyapi/execute.py +0 -0
  18. {polyapi-python-0.1.0.dev8 → polyapi-python-0.1.0.dev10}/polyapi/generate.py +0 -0
  19. {polyapi-python-0.1.0.dev8 → polyapi-python-0.1.0.dev10}/polyapi/py.typed +0 -0
  20. {polyapi-python-0.1.0.dev8 → polyapi-python-0.1.0.dev10}/polyapi/schema.py +0 -0
  21. {polyapi-python-0.1.0.dev8 → polyapi-python-0.1.0.dev10}/polyapi/typedefs.py +0 -0
  22. {polyapi-python-0.1.0.dev8 → polyapi-python-0.1.0.dev10}/polyapi_python.egg-info/SOURCES.txt +0 -0
  23. {polyapi-python-0.1.0.dev8 → polyapi-python-0.1.0.dev10}/polyapi_python.egg-info/dependency_links.txt +0 -0
  24. {polyapi-python-0.1.0.dev8 → polyapi-python-0.1.0.dev10}/polyapi_python.egg-info/top_level.txt +0 -0
  25. {polyapi-python-0.1.0.dev8 → polyapi-python-0.1.0.dev10}/setup.cfg +0 -0
  26. {polyapi-python-0.1.0.dev8 → polyapi-python-0.1.0.dev10}/tests/test_api.py +0 -0
  27. {polyapi-python-0.1.0.dev8 → polyapi-python-0.1.0.dev10}/tests/test_function_cli.py +0 -0
  28. {polyapi-python-0.1.0.dev8 → polyapi-python-0.1.0.dev10}/tests/test_utils.py +0 -0
  29. {polyapi-python-0.1.0.dev8 → polyapi-python-0.1.0.dev10}/tests/test_variables.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: polyapi-python
3
- Version: 0.1.0.dev8
3
+ Version: 0.1.0.dev10
4
4
  Summary: The PolyAPI Python Client
5
5
  Author-email: Dan Fellin <dan@polyapi.io>
6
6
  License: MIT License
@@ -33,6 +33,7 @@ Requires-Dist: typing_extensions
33
33
  Requires-Dist: jsonschema-gentypes
34
34
  Requires-Dist: pydantic>=2.5.3
35
35
  Requires-Dist: stdlib_list
36
+ Requires-Dist: colorama
36
37
 
37
38
  # PolyAPI Python Library
38
39
 
@@ -145,6 +146,14 @@ To upgrade your library to the latest dev version, pass the `--pre` flag.
145
146
  pip install polyapi-python --pre --upgrade
146
147
  ```
147
148
 
149
+ ## Change Your API Key
150
+
151
+ If you need to change your API key or what server you are pointing to, you can run:
152
+
153
+ ```bash
154
+ python -m polyapi setup
155
+ ```
156
+
148
157
  ## Unit Tests
149
158
 
150
159
  To run this library's unit tests, please clone the repo then run:
@@ -109,6 +109,14 @@ To upgrade your library to the latest dev version, pass the `--pre` flag.
109
109
  pip install polyapi-python --pre --upgrade
110
110
  ```
111
111
 
112
+ ## Change Your API Key
113
+
114
+ If you need to change your API key or what server you are pointing to, you can run:
115
+
116
+ ```bash
117
+ python -m polyapi setup
118
+ ```
119
+
112
120
  ## Unit Tests
113
121
 
114
122
  To run this library's unit tests, please clone the repo then run:
@@ -275,5 +275,4 @@ def create_function(
275
275
 
276
276
  def generate_api(api_functions: List) -> None:
277
277
  for func in api_functions:
278
- create_function(*func)
279
- print("API functions generated!")
278
+ create_function(*func)
@@ -1,21 +1,30 @@
1
1
  import argparse
2
2
 
3
+ from polyapi.utils import print_green
4
+
3
5
  from .config import clear_config
4
6
  from .generate import generate, clear
5
7
  from .function_cli import function_add_or_update
6
8
 
7
9
 
8
- CLI_COMMANDS = ["generate", "config", "clear", "function", "help"]
10
+ CLI_COMMANDS = ["setup", "generate", "function", "clear", "help"]
11
+
12
+ CLIENT_DESC = """Commands
13
+ python -m polyapi setup Setup your Poly connection
14
+ python -m polyapi generate Generates Poly library
15
+ python -m polyapi function <command> Manages functions
16
+ python -m polyapi clear Clear current generated Poly library
17
+ """
9
18
 
10
19
 
11
20
  def execute_from_cli():
12
21
  parser = argparse.ArgumentParser(
13
- prog="python -m polyapi", description="PolyAPI Client"
22
+ prog="python -m polyapi", description=CLIENT_DESC, formatter_class=argparse.RawTextHelpFormatter
14
23
  )
15
24
  parser.add_argument("--context", required=False, default="")
16
25
  parser.add_argument("--description", required=False, default="")
17
- parser.add_argument("--server", action="store_true", help="Pass --server if you want this to be a server function. By default, it will be a client function.")
18
- parser.add_argument("--logs", action="store_true", help="Pass --logs if you want to store and see the logs from this function executing")
26
+ parser.add_argument("--server", action="store_true", help="Pass --server when adding function to add a server function. By default, new functions are client.")
27
+ parser.add_argument("--logs", action="store_true", help="Pass --logs when adding function if you want to store and see the function logs.")
19
28
  parser.add_argument("command", choices=CLI_COMMANDS)
20
29
  parser.add_argument("subcommands", nargs="*")
21
30
  args = parser.parse_args()
@@ -24,10 +33,10 @@ def execute_from_cli():
24
33
  if command == "help":
25
34
  parser.print_help()
26
35
  elif command == "generate":
27
- print("Generating...")
36
+ print("Generating Poly functions...", end="")
28
37
  generate()
29
- elif command == "config":
30
- print("Clearing old config...")
38
+ print_green("DONE")
39
+ elif command == "setup":
31
40
  clear_config()
32
41
  generate()
33
42
  elif command == "clear":
@@ -69,6 +69,10 @@ def initialize_config():
69
69
 
70
70
 
71
71
  def clear_config():
72
+ if os.environ.get("POLY_API_KEY"):
73
+ print("Using POLY_API_KEY from environment. Please unset environment variable to manually set api key.")
74
+ return
75
+
72
76
  global API_KEY
73
77
  global API_URL
74
78
  API_KEY = None
@@ -11,12 +11,13 @@ from pydantic import TypeAdapter
11
11
  from polyapi.generate import get_functions_and_parse, generate_api
12
12
  from polyapi.config import get_api_key_and_url
13
13
  from polyapi.constants import PYTHON_TO_JSONSCHEMA_TYPE_MAP
14
- from polyapi.utils import get_auth_headers
14
+ from polyapi.utils import get_auth_headers, print_green, print_red, print_yellow
15
+ import importlib
15
16
 
16
17
 
17
18
  # these libraries are already installed in the base docker image
18
19
  # and shouldnt be included in additional requirements
19
- BASE_REQUIREMENTS = {"requests", "typing_extensions", "jsonschema-gentypes", "pydantic"}
20
+ BASE_REQUIREMENTS = {"polyapi", "requests", "typing_extensions", "jsonschema-gentypes", "pydantic"}
20
21
  all_stdlib_symbols = stdlib_list('.'.join([str(v) for v in sys.version_info[0:2]]))
21
22
  BASE_REQUIREMENTS.update(all_stdlib_symbols) # dont need to pip install stuff in the python standard library
22
23
 
@@ -141,6 +142,14 @@ def _parse_code(code: str, function_name: str):
141
142
  return parsed_args, return_type, return_type_schema, requirements
142
143
 
143
144
 
145
+ def _func_already_exists(context: str, function_name: str) -> bool:
146
+ try:
147
+ module = importlib.import_module(f"polyapi.poly.{context}")
148
+ return bool(getattr(module, function_name, False))
149
+ except ModuleNotFoundError:
150
+ return False
151
+
152
+
144
153
  def function_add_or_update(
145
154
  context: str, description: str, server: bool, logs_enabled: bool, subcommands: List
146
155
  ):
@@ -150,6 +159,9 @@ def function_add_or_update(
150
159
  parser.add_argument("filename")
151
160
  args = parser.parse_args(subcommands)
152
161
 
162
+ verb = "Updating" if _func_already_exists(context, args.function_name) else "Adding"
163
+ print(f"{verb} custom server side function...", end="")
164
+
153
165
  with open(args.filename, "r") as f:
154
166
  code = f.read()
155
167
 
@@ -162,11 +174,13 @@ def function_add_or_update(
162
174
  ) = _parse_code(code, args.function_name)
163
175
 
164
176
  if not return_type:
165
- print(
166
- f"Error: function named {args.function_name} not found as top-level function in file. Exiting."
167
- )
177
+ print_red("ERROR")
178
+ print(f"Function {args.function_name} not found as top-level function in {args.filename}")
168
179
  sys.exit(1)
169
180
 
181
+ if requirements:
182
+ print_yellow('\nPlease note that deploying your functions will take a few minutes because it makes use of libraries other than polyapi.')
183
+
170
184
  data = {
171
185
  "context": context,
172
186
  "name": args.function_name,
@@ -189,14 +203,15 @@ def function_add_or_update(
189
203
  # url = f"{base_url}/functions/client"
190
204
 
191
205
  headers = get_auth_headers(api_key)
192
- print("Adding function...")
193
206
  resp = requests.post(url, headers=headers, json=data)
194
207
  if resp.status_code == 201:
208
+ print_green("DEPLOYED")
195
209
  function_id = resp.json()["id"]
196
- print(f"Function added successfully. Function id is {function_id}")
197
- print("Adding new function to environment...")
210
+ print(f"Function ID: {function_id}")
211
+ print("Generating new custom function...", end="")
198
212
  functions = get_functions_and_parse(limit_ids=[function_id])
199
213
  generate_api(functions)
214
+ print_green("DONE")
200
215
  else:
201
216
  print("Error adding function.")
202
217
  print(resp.status_code)
@@ -1,5 +1,6 @@
1
1
  import re
2
2
  import os
3
+ from colorama import Fore, Style
3
4
 
4
5
 
5
6
  # this string should be in every __init__ file.
@@ -37,4 +38,16 @@ def camelCase(s):
37
38
  return ''.join([s[0].lower(), s[1:]])
38
39
  else:
39
40
  # s is already in camelcase as best as we can tell, just move on!
40
- return s
41
+ return s
42
+
43
+
44
+ def print_green(s: str):
45
+ print(Fore.GREEN + s + Style.RESET_ALL)
46
+
47
+
48
+ def print_yellow(s: str):
49
+ print(Fore.YELLOW + s + Style.RESET_ALL)
50
+
51
+
52
+ def print_red(s: str):
53
+ print(Fore.RED + s + Style.RESET_ALL)
@@ -34,7 +34,6 @@ class {variable_name}:{get_method}
34
34
  def generate_variables(variables: List[VariableSpecDto]):
35
35
  for variable in variables:
36
36
  create_variable(variable)
37
- print("Variables generated!")
38
37
 
39
38
 
40
39
  def render_variable(variable: VariableSpecDto):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: polyapi-python
3
- Version: 0.1.0.dev8
3
+ Version: 0.1.0.dev10
4
4
  Summary: The PolyAPI Python Client
5
5
  Author-email: Dan Fellin <dan@polyapi.io>
6
6
  License: MIT License
@@ -33,6 +33,7 @@ Requires-Dist: typing_extensions
33
33
  Requires-Dist: jsonschema-gentypes
34
34
  Requires-Dist: pydantic>=2.5.3
35
35
  Requires-Dist: stdlib_list
36
+ Requires-Dist: colorama
36
37
 
37
38
  # PolyAPI Python Library
38
39
 
@@ -145,6 +146,14 @@ To upgrade your library to the latest dev version, pass the `--pre` flag.
145
146
  pip install polyapi-python --pre --upgrade
146
147
  ```
147
148
 
149
+ ## Change Your API Key
150
+
151
+ If you need to change your API key or what server you are pointing to, you can run:
152
+
153
+ ```bash
154
+ python -m polyapi setup
155
+ ```
156
+
148
157
  ## Unit Tests
149
158
 
150
159
  To run this library's unit tests, please clone the repo then run:
@@ -3,3 +3,4 @@ typing_extensions
3
3
  jsonschema-gentypes
4
4
  pydantic>=2.5.3
5
5
  stdlib_list
6
+ colorama
@@ -3,10 +3,10 @@ requires = ["setuptools>=61.2", "wheel"]
3
3
 
4
4
  [project]
5
5
  name = "polyapi-python"
6
- version = "0.1.0.dev8"
6
+ version = "0.1.0.dev10"
7
7
  description = "The PolyAPI Python Client"
8
8
  authors = [{ name = "Dan Fellin", email = "dan@polyapi.io" }]
9
- dependencies = ["requests", "typing_extensions", "jsonschema-gentypes", "pydantic>=2.5.3", "stdlib_list"]
9
+ dependencies = ["requests", "typing_extensions", "jsonschema-gentypes", "pydantic>=2.5.3", "stdlib_list", "colorama"]
10
10
  readme = "README.md"
11
11
  license = { file = "LICENSE" }
12
12
  requires-python = ">=3.10"