> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.itential.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.itential.com/_mcp/server.

# iagctl run service python-script

Run a Python script service.

The `iagctl run service python-script` command executes a Python script service and displays the resulting `stdout`, `stderr`, return code, and execution time information.

## Syntax

```bash
iagctl run service python-script <service-name> [flags]
```

## Usage notes

### Runtime arguments

Use the `--set` flag to pass arguments to the Python script. Gateway passes each value to the script in `--key=value` format. For example, this command:

```bash
iagctl run service python-script my-script \
  --set device=10.0.0.1 \
  --set commands='["show ver"]'
```

Causes Gateway to run the following in the virtual environment:

```bash
python main.py --device=10.0.0.1 --commands='["show ver"]'
```

If you defined a decorator during service creation, Gateway validates all `--set` values against it before passing them to the script.

You can also pass a bare `--set key` without a value. How Gateway passes this to your script depends on whether the service has a decorator with the property defined as `boolean`:

* **With a decorator:** Gateway passes the flag as `--verbose`
* **Without a decorator:** Gateway passes the flag as `--verbose=true`
  For more information and script examples for both cases, see [Boolean properties in Python script services](../using-decorators#boolean-properties-in-python-script-services).

```bash
# Pass a boolean flag
iagctl run service python-script my-script --set verbose --set host=10.0.0.1

# Omit the boolean flag
iagctl run service python-script my-script --set host=10.0.0.1
```

Your script parses these arguments using Python's `argparse` module. The following example handles string values, JSON inputs, and a boolean flag:

```python
import argparse
import json

def main():
    parser = argparse.ArgumentParser(description="Run commands on a network device.")
    parser.add_argument('--device', required=True, help="Device IP address or hostname")
    parser.add_argument('--commands', required=True, help="Commands to run.")
    parser.add_argument('--verbose', action='store_true', help="Enable verbose output")
    args = parser.parse_args()

    device = args.device
    commands_input = args.commands

    try:
        commands = json.loads(commands_input)
    except json.JSONDecodeError:
        commands = [commands_input]

    if args.verbose:
        print(f"Connecting to {device} with verbose output enabled")

    print(device)
    print(commands)

if __name__ == "__main__":
    main()
```

### View accepted inputs

Use the `--use` flag with the service name to display information about the inputs a service accepts:

```bash
iagctl run service python-script <service-name> --use
```

## Examples

### Run a Python script service

```bash
iagctl run service python-script my-python-service
```

### Run a Python script service with arguments

The following example passes `device` and `commands` arguments to the script.

```bash
iagctl run service python-script my-python-service \
--set device=10.0.0.1 \
--set commands='["show ver"]'
```

## Options

```bash
      --profile string   Specify the client profile to use (case-insensitive, defaults to [client] section)
  -h, --help              Help for python-script
  --set stringArray       Runtime input arguments. Use key=value format for string arguments, or bare key format (--set key) for boolean arguments defined in a decorator schema.
  --use                   Display usage of the service.
```

## Options inherited from parent commands

```bash
  --profile string   Specify the client profile to use (case-insensitive, defaults to [client] section)
  --config string   Path to the configuration file
  --raw             Display the result of the command in raw format
  --verbose         Enable verbose output
```