Windmill Python Client
The `wmill` library is the official Python client for interacting with the Windmill platform. It provides a comprehensive set of functions and utilities to manage Windmill resources, variables, and execute scripts or flows. Designed for both module-level convenience functions and advanced class-based usage, it simplifies automation and workflow orchestration within the Windmill ecosystem. The library is actively maintained with frequent updates, usually on a weekly or bi-weekly cadence.
Warnings
- gotcha The `wmill` client is not inherently thread-safe or multi-processing safe. When developing multi-threaded or multi-process applications, you must create a separate `wmill.Windmill()` client instance for each thread or process to avoid unexpected behavior.
- breaking The `wmill.write_s3_file()` function's signature changed in version `1.421.0`. It now requires `content_type` and `content_disposition` as positional arguments, leading to `TypeError` if not provided.
- gotcha For local development outside the Windmill Web IDE, you must explicitly set environment variables (`WM_TOKEN`, `BASE_URL`, `WORKSPACE`) for the `wmill` client to authenticate and connect to your Windmill instance. Without these, client methods may fail or connect to incorrect endpoints.
- gotcha Windmill automatically resolves Python script dependencies by analyzing top-level `import` statements. It uses a heuristic assuming the import root name matches the PyPI package name. If your package structure deviates (e.g., `import my_lib.sub_module` where the package is `my-library`), automatic resolution might fail.
Install
-
pip install wmill
Imports
- wmill
import wmill
- Windmill
from wmill import Windmill
- S3Object
from wmill import S3Object
Quickstart
import os
import wmill
def main():
# When running inside Windmill, WM_TOKEN, BASE_URL, and WORKSPACE
# are automatically available via environment variables.
# For local development, ensure these are set.
# Example: WM_TOKEN=your_token BASE_URL=http://localhost:8000 WORKSPACE=your_workspace python your_script.py
try:
# Get a resource (e.g., database configuration)
db_config = wmill.get_resource('u/user/db_config')
print(f"Retrieved DB config: {db_config}")
# Get a variable (e.g., an API key)
api_key = wmill.get_variable('u/user/api_key')
print(f"Retrieved API key (first 5 chars): {api_key[:5]}...")
# Run another script synchronously and get its result
result = wmill.run_script_by_path(
'f/scripts/my_helper_script',
args={'input_data': 'hello'}
)
print(f"Script 'my_helper_script' result: {result}")
# Advanced usage: instantiate the client directly
client = wmill.Windmill(
base_url=os.environ.get('BASE_URL', 'http://localhost:8000'),
token=os.environ.get('WM_TOKEN', ''),
workspace=os.environ.get('WORKSPACE', 'your_workspace')
)
user_info = client.user
print(f"Current Windmill user: {user_info.email}")
except Exception as e:
print(f"An error occurred: {e}")
if __name__ == '__main__':
main()