mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-19 00:02:03 +00:00
feat(python): Refactor Windmill Python client (remove windmill-api) (#2665)
* "feat(python): Refactor Windmill Python client for better encapsulation and maintainability"
This PR obviates the need for the `windmill-api` library. I believe this makes the client package is easier to understand, debug, build, (and test) without it.
Additional updates were made to improve logging and add more robust error handling.
Here's what Jetbrains' AI assistant came up with to describe the changes based on the diff--I think it did a decent job:
> Simplified the Windmill Python client by refactoring out repeated code into more compact, reusable methods. Transitioned the client functions into a Windmill client class, enabling a better encapsulation of the client's state. Updated the README example to reflect this change. This improves code maintainability by making the code easier to understand and update, and improves user experience by providing a more intuitive client interface.
* "Refactor post method in Windmill Python client"
Removed the hard-coded param 'refresh_client' from the post method in wmill/client.py. since it's no longer used.
* "Update build script for Python client"
Updated the build script for the Python client for the backend to now include scaffolding code for generating the OpenAPI client, making changes to the generated client, and building the client. .
* "Add raise_for_status option in http methods"
Enhanced 'get' and 'post' methods in the client class to include a new optional parameter 'raise_for_status'. This allows for better error handling by raising exceptions for 4XX and 5XX responses, if requested. This way, non critical API calls can continue execution even if they receive a client or server error.
* "Removed refresh_client condition in post method"
* Replace `create_job` with `start_execution` in wmill client
This commit changes the method `create_job` to `start_execution` in the wmill client. The change was made to better reflect the function's purpose and make the code even more self-explanatory. Additionally, references to this changed method in README.md and various portions of client.py are also updated. The change will enhance readability and make it easier for newcomers to understand the code.
* Fix type hints and default arguments in wmill client
This commit adjusts typing hints for several methods from Dict[str, Any] to Any in wmill client since the result of a script isn't always a dictionary. Null arguments are also adjusted from {} to None, ensuring better Python standard practices and less unpredicted behaviors. These changes are aimed to enhance maintainability and make the functions more resilient.
* Update client.py
* Update pyproject.toml
* Update client.py
---------
Co-authored-by: Ruben Fiszel <ruben@rubenfiszel.com>
This commit is contained in:
committed by
GitHub
parent
9ee4ffef39
commit
56a3783aa5
@@ -2,9 +2,6 @@
|
||||
|
||||
The core client for the [Windmill](https://windmill.dev) platform.
|
||||
|
||||
It is a convenient wrapper around the exhaustive, automatically generated from
|
||||
OpenApi but less user-friendly
|
||||
[windmill-api](https://pypi.org/project/windmill-api/).
|
||||
|
||||
## Quickstart
|
||||
|
||||
@@ -13,15 +10,15 @@ import wmill
|
||||
|
||||
|
||||
def main():
|
||||
#os.environ.set("WM_TOKEN", "<mytoken>") OPTIONAL to set token used by the wmill client
|
||||
version = wmill.get_version()
|
||||
resource = wmill.get_resource("u/user/resource_path")
|
||||
client = wmill.Windmill(
|
||||
# token=... <- this is optional. otherwise the client will look for the WM_TOKEN env var
|
||||
)
|
||||
|
||||
# run synchronously, will return the result
|
||||
res = wmill.run_script_sync(hash="000000000000002a", args={})
|
||||
print(res)
|
||||
print(client.version)
|
||||
print(client.get("u/user/resource_path"))
|
||||
|
||||
for _ in range(3):
|
||||
# run asynchrnously, will return immediately. Can be scheduled
|
||||
wmill.run_script_async(hash="000000000000002a", args={}, scheduled_in_secs=10)
|
||||
job_id = client.start_execution(path="path/to/script")
|
||||
print(job_id)
|
||||
|
||||
return client.run_script(path="path/to/script", args={"arg1": "value1"})
|
||||
```
|
||||
|
||||
@@ -16,7 +16,7 @@ include = ["wmill/py.typed"]
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.7"
|
||||
windmill-api = "^1.213.0"
|
||||
httpx = "^0.25"
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry>=1.0.2", "poetry-dynamic-versioning"]
|
||||
|
||||
+521
-425
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user