Skip to navigation

iagctl create service python-script

Create a new Python script service.

The iagctl create service python-script command creates a Python script service in the gateway data store. You can then run the service with the iagctl run command. For more information, see Create gateway services.

Consider a Python script in a repository called example-repo with the following directory layout:

├── README.md
├── interface-scripts
├── main.py
└── requirements.txt

To create a service from the script in the interface-scripts directory, specify the repository with --repository, the subdirectory with --working-dir, and the script file with --filename.

Prerequisites

Before you create a Python script service, you need a repository that contains your script.

Syntax

iagctl create service python-script <service-name> --repository <string> --filename <string> [flags]

Usage notes

Dependencies

If a requirements.txt file exists in the --working-dir, the gateway automatically installs the dependencies into a virtual environment and runs the script within that environment.

Environment variables

Use the --env flag to set environment variables that the gateway applies at runtime. Specify each variable as a key=value pair.

Decorators

You can attach a decorator to the service for input validation at runtime with the --decorator flag. For more information, see iagctl create decorator.

If a property’s value is too large to pass safely as a CLI argument, mark it as file-backed in the decorator schema so Gateway writes it to a temporary file and passes your script an environment variable instead. For more information, see Pass large values as files in Python script services.

File-backed properties are supported for Python script services only.

Runtime arguments

For information on how Python scripts read arguments passed at runtime, see iagctl run service python-script.

Examples

Create a basic Python script service

The following example creates a service called my-python-service where the script main.py is at the root of the my-repo repository:

iagctl create service python-script my-python-service \
--repository my-repo \
--filename main.py

Create a Python script service with all options

The following example creates a service that specifies a working directory, a decorator, environment variables, and metadata:

iagctl create service python-script interface-renamer \
--repository example-repo \
--filename main.py \
--working-dir interface-scripts \
--decorator my-decorator \
--description "A Python script to set an interface description" \
--env key1=value1 \
--env key2=value2 \
--tag interfaces

Options

--decorator string The decorator to associate with the service.
--description string A brief description of the service.
--env stringArray Environment variables as key=value pairs. Provide multiple flags for multiple variables.
--filename string The Python script file in the repository. Must exist in the working directory. (default "main.py")
-h, --help Help for python-script.
--repository string The gateway repository that contains the Python script.
--tag stringArray Metadata tags to associate with the service.
--working-dir string Path to the directory where the script exists, relative to the repository root.

Options inherited from parent commands

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