> For the complete documentation index, see [llms.txt](https://docs.veza.com/4yItIzMvkpAvMVFAamTf/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.veza.com/4yItIzMvkpAvMVFAamTf/integrations/configuration/python.md).

# Running Veza Scripts with Python

Veza Python Script Setup and Execution Guide for Linux, Windows, and Mac

This document provides instructions for setting up and running Veza Python scripts on Linux, Windows, and Mac operating systems. Users seeking to automate Veza Python scripts on different platforms can refer to the sections below to learn about:

* Verifying Python Installations
* Installing Required Packages
* Setting Environment Variables
* Executing Scripts
* Scheduling Periodic Script Runs
* Setting Temporary and Persistent Environment Variables

These instructions are especially intended to help run and schedule Open Authorization API connectors provided as Python packages.

### Linux

#### Setup

**Verify Python3 Installation**

Many current Linux distributions typically have `python3` installed by default.

To verify that `python3` is installed on your system, run the following command:

```shell
which python3
which pip3
```

If the outputs are filesystem paths (ex: `/usr/bin/python3`), the applications are installed.

**Installing Required Packages**

Veza Python scripts may rely on external dependencies; if this is the case, the script package will include a `requirements.txt` file.

To ensure that the dependencies are installed, run the following command from the directory in which the `requirements.txt` file is located:

```shell
pip3 install -r requirements.txt
```

**Setting Environment Variables**

Veza Python scripts often require some variable input at run time (ex: API key, service URL).

Non-secret data can be passed to the script as arguments or set as environment variables, but sensitive data **must** be set as an environment variable.

See the `README.md` packaged with a script for a description of required input data.

**Temporary Environment Variables**

Environment variables can be set temporarily from the Linux shell; these settings will last until the shell process in which they are set is terminated.

To temporarily set an environment variable from the Linux shell, run the following command:

```shell
export <variable_name>="<value>"
```

An example setting `VEZA_URL` to the FQDN of a Veza instance:

```shell
export VEZA_URL="https://example.vezacloud.com"
```

To verify currently set environment variables and their values, run the `env` command from the terminal.

To remove a currently set environment variable, run the following command:

```shell
unset <variable_name>
```

Unsetting the previously established `VEZA_URL` example:

```shell
unset VEZA_URL
```

**Persistent Environment Variables**

Environment variables can be set persistently in several ways, each with their own scope.

In each case, edit the relevant file and add the following line to set the new variable:

```shell
export <variable_name>="<value>"
```

* To set a persistent environment variable for only the currently logged-on user, edit `~/.bashrc` and add the export to the end of the file.
* To set a variable for all login shell sessions, edit `/etc/profile` and add the export to the end of the file.
* To set a system-wide variable, edit `/etc/environment` and add the export to the end of the file.

Current shell sessions will not reflect the file update immediately - to make use of the newly set variable, `source` the file first:

```shell
source ~/.bashrc
```

#### Execution

To run the Veza Python script, `chmod` the file to make it executable, then execute it:

```shell
chmod +x <script_name>.py
./<script_name>.py
```

To pass additional parameters not set as environment variables when executing the script:

```shell
./<script_name>.py --<parmeter1_name> <parameter1_value> --<flag_parmeter>
```

An example of setting a parameter with a value along with a flag parameter:

```shell
./veza_script.py --veza_url https://example.vezacloud.com --debug
```

#### Scheduling

Periodic executions of scripts can be configured to run via `cron` or via `systemd`, depending on your environment.

**Cron**

Scheduling via `cron` requires a line to be added to the `crontab`.

**Note**: `cron` executes commands without a login shell; environment variables set in `~/.bashrc` or `/etc/profile` will not be loaded.

To edit the `crontab`, run `crontab -e`, then add the following:

```shell
VEZA_URL="https://example.vezacloud.com"
VEZA_API_KEY="k124c021...fc1d281"
0 * * * * /usr/bin/python3 /path/to/<veza_script.py>
```

Some distributions do not honor environment variables set in the `crontab` file; in those cases, they can be set inline:

```
0 * * * * root env VEZA_URL="https://example.vezacloud.com" VEZA_API_KEY="k124c021...fc1d281" /usr/bin/python3 /path/to/<veza_script.py>
```

**Systemd**

Scheduling via `systemd` requires a timer unit file and a corresponding service unit file.

Begin by creating the timer unit file (`vim /etc/system/systemd/<veza_script>.timer`):

```shell
[Unit]
Description=Execute Veza Python Script Every Hour

[Timer]
OnCalendar=daily

Unit=<veza_script>.service

[Install]
WantedBy=timers.target
```

Then create the service file (`vim /etc/system/systemd/<veza_script>.service`):

```shell
[Unit]
Description=Veza Python Script Service

[Service]
# Environment variables can be defined here
Environment=VEZA_URL="https://example.vezacloud.com"
Environment=VEZA_API_KEY="k124c021...fc1d281"
Type=simple
ExecStart=/usr/bin/python3 /path/to/<veza_script.py>

[Install]
WantedBy=multi-user.target
```

Run the following commands to reload service definitions and enable the new service:

```shell
systemctl daemon-reload
systemctl enable <veza_script>.service
systemctl start <veza_script>.service
```

### Windows

#### Setup

**Verify Python Installation**

Install python by browsing to <https://www.python.org/downloads/windows/> and selecting the latest stable 64-bit installer.

Alternatively, on Windows workstations, Python may be installed via the **Microsoft Store**. See <https://learn.microsoft.com/en-us/windows/python/beginners> for details.

**Note**: During installation, ensure the `Add python.exe to PATH` checkbox is selected.

To ensure that python and pip are properly installed and added to the `PATH`, open a `Command Prompt` and run:

```shell
where python
where pip
```

Both commands will return paths on the filesystem if the executables are located.

**Installing Required Packages**

Veza Python scripts may rely on external dependencies; if this is the case, the script package will include a `requirements.txt` file.

To ensure that the dependencies are installed, run the following command from the directory in which the `requirements.txt` file is located:

```shell
pip install -r requirements.txt
```

**Setting Environment Variables**

**Temporary Environment Variables**

**Command Prompt**

To set an environment variable for an existing **Command Prompt** session, run the following:

```shell
set <variable_name>=<value>
```

An example setting `VEZA_URL` to the FQDN of a Veza instance:

```shell
set VEZA_URL="https://example.vezacloud.com"
```

To remove the previously set `VEZA_URL` example:

```shell
set VEZA_URL=
```

**PowerShell**

To set an environment variable for an existing **PowerShell** session, run the following:

```powershell
$env:<variable_name> = '<value'
```

An example setting `VEZA_URL` to the FQDN of a Veza instance:

```powershell
$env:VEZA_URL = 'https://example.vezacloud.com'
```

To remove the previously set `VEZA_URL` example:

```powershell
Remove-Item env:\VEZA_URL
```

**Persistent Environment Variables**

To set environment variables on a Windows system, follow these steps:

* On the taskbar, right-click the Windows icon and click **System**
* In the **Settings** window, locate and click **Advanced system settings**
* In the **System Properties** window that appears, click the **Environment Variables** button near the bottom.
* In the **Environment Variables** window that appears, choose the scope for the new variable. User-specific variables are listed at the top of the window with system-wide variables below.
* Click the **New** button underneath the appropriate scope.
* Complete the **New System Variable** dialog that appears, providing a **Variable name** and **Variable value**, then click **OK** **Note**: no quotes are required for complex variable values when set via this method

Current **Command Prompt** and **PowerShell** sessions will not update immediately - to make use of the newly set variable, start a new **Command Prompt** or **PowerShell** session.

#### Execution

To run the Veza Python script, open a **Command Prompt** window and execute the following:

```powershell
python <script_name>.py
```

To pass additional parameters not set as environment variables when executing the script:

```powershell
./<script_name>.py --<parmeter1_name> <parameter1_value> --<flag_parmeter>
```

An example of setting a parameter with a value along with a flag parameter:

```powershell
./veza_script.py --veza_url https://example.vezacloud.com --debug
```

#### Scheduling

Periodic executions of scripts can be configured via the **Task Scheduler** interface on Windows.

**Note**: ensure that any required environment variables have been stored as system-wide variables before scheduling a task that utilizes them. Also stop the `Taskeng.exe` process to force **Task Scheduler** to reload environment variables.

* In the search bar, type `Task Scheduler`, then click on the search result to open the interface.
* In the **Actions** pane on the right side of the window, click **Create Basic Task**
* In the **Create Basic Task Wizard**, provide the following:
  * **Name**: A name for the scheduled task
  * **Description**: An optional longer description of what the task does
  * **Trigger**: Select a time-based trigger (`Daily`)
  * Daily time settings for task triggering
  * **Program/script**: Enter or browse to the installation location of the python executable
    * **Add arguments**: `<script_name>.py --<parameter1_name> <parameter1_value>`
    * **Start in**: `c:\path\to\script\`

### Mac

#### Setup

**Verify Python3 Installation**

To install `python3` on MacOS, ensure that Homebrew is installed and run the following command:

```zsh
brew install python
```

To verify that `python3` is installed on your system, run the following command:

```zsh
which python3
which pip3
```

If the outputs are filesystem paths (ex: `/usr/local/bin/python3`), the applications are installed.

**Installing Required Packages**

Veza Python scripts may rely on external dependencies; if this is the case, the script package will include a `requirements.txt` file.

To ensure that the dependencies are installed, run the following command from the directory in which the `requirements.txt` file is located:

```zsh
pip3 install -r requirements.txt
```

**Setting Environment Variables**

Veza Python scripts often require some variable input at run time (ex: API key, service URL).

Non-secret data can be passed to the script as arguments or set as environment variables, but sensitive data **must** be set as an environment variable.

See the `README.md` packaged with a script for a description of required input data.

**Temporary Environment Variables**

Environment variables can be set temporarily from the Linux shell; these settings will last until the shell process in which they are set is terminated.

To temporarily set an environment variable from the Linux shell, run the following command:

```zsh
export <variable_name>="<value>"
```

An example setting `VEZA_URL` to the FQDN of a Veza instance:

```zsh
export VEZA_URL="https://example.vezacloud.com"
```

To verify currently set environment variables and their values, run the `env` command from the terminal.

To remove a currently set environment variable, run the following command:

```zsh
unset <variable_name>
```

Unsetting the previously established `VEZA_URL` example:

```zsh
unset VEZA_URL
```

**Persistent Environment Variables**

Environment variables can be set persistently in several ways, each with their own scope.

In each case, edit the relevant file and add the following line to set the new variable:

```zsh
export <variable_name>="<value>"
```

* To set a persistent environment variable for only the currently logged-on user, edit `~/.zshrc` and add the export to the end of the file.
* To set a variable for all login shell sessions, edit `/etc/profile` and add the export to the end of the file.

Current shell sessions will not reflect the file update immediately - to make use of the newly set variable, `source` the file first:

```zsh
source ~/.zshrc
```

#### Execution

To run the Veza Python script, `chmod` the file to make it executable, then execute it:

```zsh
chmod +x <script_name>.py
./<script_name>.py
```

To pass additional parameters not set as environment variables when executing the script:

```zsh
./<script_name>.py --<parmeter1_name> <parameter1_value> --<flag_parmeter>
```

An example of setting a parameter with a value along with a flag parameter:

```zsh
./veza_script.py --veza_url https://example.vezacloud.com --debug
```

#### Scheduling

**Cron**

Scheduling via `cron` requires a line to be added to the `crontab`.

**Note**: `cron` executes commands without a login shell; environment variables set outside of the `crontab` will not be loaded.

To edit the `crontab`, run `crontab -e`, then add the following:

```zsh
VEZA_URL="https://example.vezacloud.com"
VEZA_API_KEY="k124c021...fc1d281"
0 * * * * /usr/bin/python3 /path/to/<veza_script.py>
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.veza.com/4yItIzMvkpAvMVFAamTf/integrations/configuration/python.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
