Files
windmill/rust-client
Ruben Fiszel 52fc7bf94c feat(sdk): allow overriding worker tag when running jobs (WIN-2105) (#9807)
* feat(sdk): allow overriding worker tag when running jobs

Add an optional `tag` parameter to every job-running helper across the
TypeScript, Python, PowerShell and Rust client SDKs. When set, it is
forwarded as the `tag` query param on the `jobs/run/*` endpoints, which
the backend already honors as a worker-tag override.

The parameter is appended last and defaults to null/None everywhere, so
existing positional and keyword callers are unaffected. Rust has no
optional params, so its existing `run_script_async`/`run_script_sync`
signatures are left untouched and new `*_with_tag` variants are added.

Fixes WIN-2105

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* chore(system_prompts): regenerate SDK docs for tag param

Regenerate auto-generated system prompts so the TypeScript/Python SDK
references (and the script skills that embed them) reflect the new
optional `tag` parameter on the job-running helpers.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(powershell-sdk): preserve original RunScriptAsync/RunFlowAsync arities

PowerShell class methods dispatch by exact argument count and have no
default parameter values, so adding `$Tag` in place dropped the old
4-arg `RunScriptAsync` / 3-arg `RunFlowAsync` overloads — existing direct
class calls would fail with "Cannot find an overload". Re-add the
original arities as thin overloads that forward `$null` for `$Tag`.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(system_prompts): generate prompts.d.ts to stop literal-content drift

prompts.d.ts was a tracked declaration file with string-literal types
baked in, but generate.py never regenerated it — only prompts.ts and the
hand-written index.d.ts. So every prompt change (e.g. the new SDK `tag`
param) left prompts.d.ts stale, and check-freshness didn't catch it
because generate.py never wrote the file.

Emit prompts.d.ts from generate.py as plain `export declare const X:
string;` declarations. The contents now live only in prompts.ts, so the
declaration file can't drift, and check-freshness covers it going forward.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-26 11:54:09 +02:00
..
2025-06-10 18:38:18 +02:00
2025-06-10 18:38:18 +02:00

Windmill Rust SDK

A Rust client library for interacting with Windmill API, providing type-safe abstractions for variables, resources, scripts, jobs, and state management.

Installation

Add this to your Cargo.toml:

[dependencies]
wmill = "0.1.0"

For async support (recommended):

[dependencies]
wmill = { version = "0.1.0", features = ["async"] }

Usage

Initialize Client

use wmill::Windmill;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Read config from env vars
    let wm = Windmill::default()?;
    
    // Or override specific values
    let wm = Windmill::new(
        Some("custom_token".to_string()),
        Some("my_workspace".to_string()),
        Some("http://localhost:8000".to_string())
    )?;
    
    Ok(())
}

Variables

// Get variable (auto-parsed)
let db_config: serde_json::Value = wm.get_variable("u/admin/db_config").await?;

// Get raw variable
let raw_text = wm.get_variable_raw("u/user/text_note").await?;

// Set variable
wm.set_variable("new_value".to_string(), "u/user/my_var", false).await?;

Resources

// Get resource (typed)
#[derive(serde::Deserialize)]
struct DbConfig { host: String, port: u16 }

let config: DbConfig = wm.get_resource("u/admin/db").await?;

// Get raw resource
let raw_json = wm.get_resource_any("u/admin/db").await?;

// Set resource
wm.set_resource(
    Some(serde_json::json!({"host": "localhost", "port": 5432})),
    "u/admin/db",
    "postgresql"
).await?;

Scripts

// Run script async
let job_id = wm.run_script_async(
    "u/user/my_script",
    false,
    serde_json::json!({"param": "value"}),
    Some(10) // Schedule in 10 seconds
).await?;

// Run script sync
let result = wm.run_script_sync(
    "u/user/my_script",
    false,
    serde_json::json!({"param": "value"}),
    Some(10),
    Some(30), // 30s timeout
    true,     // Verbose
    true      // Assert result not None
).await?;

Jobs

// Wait for job completion
let result = wm.wait_job(&job_id, Some(60), true, true).await?;

// Get job status
let status = wm.get_job_status(&job_id).await?; // Running/Waiting/Completed

// Get result directly
let result = wm.get_result(&job_id).await?;

State Management

// Get typed state
#[derive(serde::Deserialize)]
struct ScriptState { counter: i32 }

let state: ScriptState = wm.get_state().await?;

// Get raw state
let raw_state = wm.get_state_any().await?;

// Update state
wm.set_state(Some(serde_json::json!({"counter": 42}))).await?;

Progress Tracking

// Set job progress
wm.set_progress(75, None).await?; // Uses current job ID from env

// Get job progress
let progress = wm.get_progress(Some(job_id.to_string())).await?;

Custom API Calls

The SDK provides direct access to underlying API endpoints through the call_api method, which works in both async and sync contexts:

// Async usage
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let wm = Windmill::default()?;
    
    // Make direct API call to get user
    let user = wm.call_api(wmill::apis::admin_api::get_user(
        &wm.client_config,
        &wm.workspace,
        "Alice"
    )).await;
    
    println!("User details: {:?}", user);
    Ok(())
}

// Sync usage
fn main() {
    let wm = Windmill::default().unwrap();
    
    // Make direct API call to get user
    let user = wm.call_api(wmill::apis::admin_api::get_user(
        &wm.client_config,
        &wm.workspace,
        "Bob"
    ));
    
    println!("User details: {:?}", user);
}

This advanced feature allows access to any Windmill API endpoint, even those not covered by the SDK's convenience methods. Use this when:

  • Need to access newer/undocumented API endpoints
  • Require fine-grained control over API requests
  • Existing abstractions don't meet specific needs

Environment Variables

The SDK uses these environment variables:

Variable Required Description
WM_TOKEN Authentication token
WM_WORKSPACE Workspace name
BASE_INTERNAL_URL API base URL (without /api)
WM_JOB_ID Optional Current job ID for progress tracking
WM_STATE_PATH_NEW Optional State path override

Contributions

Contributions are welcome! Please open an issue or submit a PR.