Windmill Python Client

1.682.0 · active · verified Fri Apr 10

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

Install

Imports

Quickstart

This quickstart demonstrates how to use the `wmill` client to interact with the Windmill platform. It covers retrieving resources and variables, running other scripts, and direct client instantiation for advanced operations. Authentication is handled automatically within the Windmill environment or via `WM_TOKEN`, `BASE_URL`, and `WORKSPACE` environment variables for local development.

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()

view raw JSON →