create service python-script
Create a new Python script service
Synopsis
Create
This command will create a Python script service in torero's data store. The service can
later be executed via torero's run
command. Before creating a Python script service, you
will need to ensure that a repository with the actual script exists.
See torero create repository -h
for more information.
Consider a Python script that exists in a repository called example-repo
. The repository has
the following directory layout:
├── README.md
├── interface-scripts
│ ├── main.py
│ └── requirements.txt
We can specify that we want to use example-repo
via the --repository
flag.
Notice that our script exists in a directory called interface-scripts
. We can denote this using
the --working-dir
flag.
Our particular script also has a requirements.txt
file that specifies the various libraries
that main.py
requires. If a requirements.txt
file exists within the working-dir
,
torero will automatically pip install
the dependencies into a virtual environment and
execute the script within that virtual environment when service is run
.
Separate from our example, if a project uses pyproject.toml
instead of a requirements.txt
,
you can specify the path to the pyproject.toml
file relative to the working-dir
using the --req-file
flag.
The --req-file
flag can also be used to hardcode the path to a specific requirements.txt
file.
If no --req-file
is specified on the service, torero will fall back to using the value set at
TORERO_PYTHON_SCRIPT_REQUIREMENTS_FILE
.
torero can run any script defined in a pyproject.toml
using the --pyproj-script
flag.
Any optional dependencies found in a pyproject.toml
script can be specified using the --pyproj-optional-deps
flag.
Environment variables that will be applied during runtime can be specified using the --env
flag.
Finally, a decorator can be specified to allow for input validation when the service is executed
via the run
command.
For more information on decorators, run torero create decorator -h
.
To see how Python scripts are expected to read in arguments passed at runtime,
reference torero run service python-script -h
and view the
Stub Code For Taking In Arguments
section.
torero create service python-script <service-name> --repository <string> --filename <string> [flags]
Examples
Create A Simple Python Service
Creates a simple Python service called my-python-service
where a Python script named main.py
is at the root of the my-repo
repository.
>_ torero create service python-script my-python-service \
--repository my-repo \
--filename main.py
Create A More Complex Python Service
Creates a Python service that takes advantage of many of the options available.
>_ torero 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
Create A Python Script That Uses Pyproject.toml
Creates a Python service that uses a pyproject.toml
to denote its build configuration.
>_ torero create service python-script bgp-configure \
--repository example-repo \
--working-dir bgp-scripts \
--req-file pyproject.toml \
--pyproj-script some-script \
--pyproj-optional-deps networking-deps
Options
--decorator string The name of the decorator to be associated with the service
--description string A brief description of the service
--env stringArray One or more environment variables set as key=value pairs
--filename string The name of the Python script file in the repository. This must exist in the
working-dir
-h, --help help for python-script
--pyproj-optional-deps stringArray Specifies optional dependencies defined in the pyproject.toml to install before
executing
--pyproj-script string Defines the script to execute as would be defined in the pyproject.toml
--registry stringArray Registry to pull dependencies from when executing the service
--repository string The repository that contains the Python script
--req-file string The path to the requirements file. This could also be a path deeper than the
--working-dir
--tag stringArray Metadata tag(s) to associate with the service
--working-dir string The path to the directory where the Python script exists. The path must be
relative to the root of the repository
Options inherited from parent commands
--config string Path to the configuration file
--raw Displays the result of the command in its raw format
--verbose Enable verbose output
SEE ALSO
- torero create service - Create a service