Skip to content

Commit 1c69163

Browse files
nahuel-polyapisudiptatjeupharisaarongoineneumann
authored
R22 (#40)
* # Feature (2970): Update python client to support setup command (#22) * # Feature (2970): Update python client to support setup command - Function add command now support --execution-api-key - Extra Old Function call removed * improve polyapi-python setup (#24) * improve polyapi-python setup * # Feature (3019): improve polyapi-python setup (#25) * # Feature (3019): improve polyapi-python setup * # Feature (3019): improve polyapi-python setup - UUID Validation check added --------- Co-authored-by: Sudipta at TechJays <sudipta.kumar@techjays.com> * # Feature (3007): Update python -m polyapi function add --logs options (#23) * # Feature (3007): Update python -m polyapi function add --logs options - if --logs added, then value must enabled or disabled - If Nothing passed the value is default disabled - pyproject.toml version updated * Project Glide + Refactor main command line args parsing (#26) * Refactor main command line args parsing, adding prepare and sync commands to enable project glide workflows for python * improved tests * updating version * fix for poly cache directory path construction * one more adjustment to the deployables cache directory so there can't be any conflict with any custom namespace * this better? * verbose logging on upload code to see what's failing in CI/CD * bumpity * whoops * so close * better? * okay this should be the fix * is it this? * maybe * oh for the love of pete * whatever. might be a pypi issue * removing verbose logging * fixing bugs in sync command to use correct api urls * update logging * lint * improved auth * last fix for function sync * fix bug when comment arguments don't align with the function * try forcing the poly directory to exist * test logging * remove debug logging * fixing project glide deployable types and bumping the version * fixing missing arguments in python client function upload * fixing return type for trained functions * fix bug preventing use of poly sync command locally * next version of client! * EN #3183 allow null logs flag for python client (#28) * let the typing_extensions versions increase to support latest openai pypi package version * update dependency in one more place * Some bug fixes for python client (#29) * fixed bug with parsing python functions without any types, and bug where functions with multiple deployment receipts were getting mangled * whoops. uncommenting tests * last test fix * 0.3.2 * add poly schemas support (#31) * onward * adding schemas for Pythonland! * onward * next * next * next * next * test * next * next * next * little tweak for A-Aron * fix * next * update to v4 * v4 everywhere * bump version * add new version * remove warning, just go with any type for now * better generate printed messages, fix generate bug after function add * Update python version (#32) * Update python image (#33) * Update python version * Updated version * Rollback version * onward (#34) * woot! we have some better return types * toward working tests - except parser/deployables * more * getting there * next * onawrd * next * next * next * next * next (#35) * improve intellisense detection of schemas * release 0.3.3.dev8, fix misleading generate after setup * 0.3.3.dev9 - add support for optional arguments (#36) * next * release 0.3.3.dev10 * EN #3943 update to support SFX serverSideAsync True by setting correct return type (#39) * deploying version 0.3.3 for R22 --------- Co-authored-by: Sudipta at TechJays <sudipta.kumar@techjays.com> Co-authored-by: Dan Fellin <dan@polyapi.io> Co-authored-by: Aaron Goin <aarongoin@users.noreply.github.com> Co-authored-by: Dan Fellin <dan@highwaterlabs.com> Co-authored-by: Eric Neumann <eneumann@users.noreply.github.com> Co-authored-by: Don Chiniquy <drchiniquy@gmail.com>
1 parent b961c32 commit 1c69163

27 files changed

+674
-101
lines changed

.flake8

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[flake8]
2-
extend-ignore = E203,E303,E402,E501,E722,W391,F401,W292
2+
ignore = E203,E303,E402,E501,E722,W391,F401,W292,F811
33
max-line-length = 150
4-
max-complexity = 20
4+
max-complexity = 22

.github/workflows/polyapi-update-python-package.yml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Update python pip package
1+
name: Update python pip package
22
on:
33
push:
44
paths:
@@ -13,7 +13,7 @@ jobs:
1313
runs-on: ubuntu-latest
1414
if: ${{ github.ref == 'refs/heads/develop' }}
1515
environment: dev
16-
16+
1717
steps:
1818
- uses: actions/checkout@v4
1919
- name: Set up Python
@@ -31,7 +31,7 @@ jobs:
3131
- name: Build a binary wheel and a source tarball
3232
run: python3 -m build
3333
- name: Store the distribution packages
34-
uses: actions/upload-artifact@v3
34+
uses: actions/upload-artifact@v4
3535
with:
3636
name: python-package-distributions
3737
path: dist/
@@ -44,27 +44,27 @@ jobs:
4444
needs: develop-build
4545
environment:
4646
name: dev
47-
url: https://pypi.org/p/polyapi-python
47+
url: https://pypi.org/p/polyapi-python
4848

4949
permissions:
50-
id-token: write
50+
id-token: write
5151
steps:
5252

5353
- name: Download all the dists
54-
uses: actions/download-artifact@v3
54+
uses: actions/download-artifact@v4
5555
with:
5656
name: python-package-distributions
5757
path: dist/
5858
- name: Publish distribution 📦 to PyPI
5959
uses: pypa/gh-action-pypi-publish@release/v1
6060

61-
61+
6262
main-build:
6363
name: Build distribution 📦
6464
runs-on: ubuntu-latest
6565
if: ${{ github.ref == 'refs/heads/main' }}
6666
environment: main
67-
67+
6868
steps:
6969
- uses: actions/checkout@v4
7070
- name: Set up Python
@@ -81,7 +81,7 @@ jobs:
8181
- name: Build a binary wheel and a source tarball
8282
run: python3 -m build
8383
- name: Store the distribution packages
84-
uses: actions/upload-artifact@v3
84+
uses: actions/upload-artifact@v4
8585
with:
8686
name: python-package-distributions
8787
path: dist/
@@ -90,20 +90,20 @@ jobs:
9090
main-publish-to-pypi:
9191
name: >-
9292
Publish Python 🐍 distribution 📦 to PyPI
93-
if: ${{ github.ref == 'refs/heads/main' }}
93+
if: ${{ github.ref == 'refs/heads/main' }}
9494
needs:
9595
- main-build
9696
runs-on: ubuntu-latest
9797
environment:
9898
name: main
99-
url: https://pypi.org/p/polyapi-python
99+
url: https://pypi.org/p/polyapi-python
100100
permissions:
101-
id-token: write
101+
id-token: write
102102

103103

104104
steps:
105105
- name: Download all the dists
106-
uses: actions/download-artifact@v3
106+
uses: actions/download-artifact@v4
107107
with:
108108
name: python-package-distributions
109109
path: dist/

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,6 @@ __pycache__
3434
.polyapi-python
3535
function_add_test.py
3636
lib_test*.py
37-
polyapi/poly/
38-
polyapi/vari/
37+
polyapi/poly
38+
polyapi/vari
39+
polyapi/schemas

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2023 PolyAPI Inc.
3+
Copyright (c) 2025 PolyAPI Inc.
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,26 @@ To run this library's unit tests, please clone the repo then run:
143143
python -m unittest discover
144144
```
145145

146+
## Linting
147+
148+
The flake8 config is at the root of this repo at `.flake8`.
149+
150+
When hacking on this library, please enable flake8 and add this line to your flake8 args (e.g., in your VSCode Workspace Settings):
151+
152+
```
153+
--config=.flake8
154+
```
155+
156+
## Mypy Type Improvements
157+
158+
This script is handy for checking for any mypy types:
159+
160+
```bash
161+
./check_mypy.sh
162+
```
163+
164+
Please ignore \[name-defined\] errors for now. This is a known bug we are working to fix!
165+
146166
## Support
147167

148168
If you run into any issues or want help getting started with this project, please contact support@polyapi.io

check_mypy.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
mypy polyapi/poly
4+
mypy polyapi/vari
5+
mypy polyapi/schemas

polyapi/api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from typing import List, Dict, Any, TypedDict
99
{args_def}
1010
{return_type_def}
11+
1112
class {api_response_type}(TypedDict):
1213
status: int
1314
headers: Dict
@@ -41,6 +42,7 @@ def render_api_function(
4142
arg_names = [a["name"] for a in arguments]
4243
args, args_def = parse_arguments(function_name, arguments)
4344
return_type_name, return_type_def = get_type_and_def(return_type) # type: ignore
45+
4446
data = "{" + ", ".join([f"'{arg}': {rewrite_arg_name(arg)}" for arg in arg_names]) + "}"
4547

4648
api_response_type = f"{function_name}Response"

polyapi/cli.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
CLI_COMMANDS = ["setup", "generate", "function", "clear", "help", "update_rendered_spec"]
1515

16+
1617
def execute_from_cli():
1718
# First we setup all our argument parsing logic
1819
# Then we parse the arguments (waaay at the bottom)
@@ -46,9 +47,7 @@ def setup(args):
4647

4748
def generate_command(args):
4849
initialize_config()
49-
print("Generating Poly functions...", end="")
5050
generate()
51-
print_green("DONE")
5251

5352
generate_parser.set_defaults(command=generate_command)
5453

polyapi/config.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ def set_api_key_and_url(key: str, url: str):
5555
config.set("polyapi", "poly_api_base_url", url)
5656
with open(get_config_file_path(), "w") as f:
5757
config.write(f)
58+
global API_KEY
59+
global API_URL
60+
API_KEY = key
61+
API_URL = url
5862

5963

6064
def initialize_config(force=False):
@@ -81,7 +85,7 @@ def initialize_config(force=False):
8185
sys.exit(1)
8286

8387
set_api_key_and_url(key, url)
84-
print_green(f"Poly setup complete.")
88+
print_green("Poly setup complete.")
8589

8690
if not key or not url:
8791
print_yellow("Poly API Key and Poly API Base URL are required.")

polyapi/execute.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from typing import Dict
12
import requests
23
from requests import Response
34
from polyapi.config import get_api_key_and_url
@@ -7,10 +8,14 @@
78
def execute(function_type, function_id, data) -> Response:
89
""" execute a specific function id/type
910
"""
11+
data_without_None = data
12+
if isinstance(data, Dict):
13+
data_without_None = {k: v for k, v in data.items() if v is not None}
14+
1015
api_key, api_url = get_api_key_and_url()
1116
headers = {"Authorization": f"Bearer {api_key}"}
1217
url = f"{api_url}/functions/{function_type}/{function_id}/execute"
13-
resp = requests.post(url, json=data, headers=headers)
18+
resp = requests.post(url, json=data_without_None, headers=headers)
1419
# print(resp.status_code)
1520
# print(resp.headers["content-type"])
1621
if resp.status_code < 200 or resp.status_code >= 300:

0 commit comments

Comments
 (0)