> ## Documentation Index
> Fetch the complete documentation index at: https://www.truefoundry.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Setup For CLI

> Install and configure the TrueFoundry CLI for managing deployments, experiments, and platform resources.

## TrueFoundry CLI Library

TrueFoundry CLI library to help you interact with the platform programmatically.

<Note>
  TrueFoundry CLI is a very lightweight CLI that only exposes the most common functionality and doesn't provide interaction with all APIs of TrueFoundry. For that, we recommend using the APIs of TrueFoundry directly or using the [TrueFoundry Python SDK](/docs/truefoundry_sdk/index).
</Note>

## Install TrueFoundry CLI

<Info>
  You need Python ≥ 3.10, ≤ 3.14 to use **truefoundry v0.17.0** and later. See [Minimum Python version raised to 3.10 — truefoundry v0.17.0](/docs/change-announcements/python-3.10-minimum-truefoundry-cli-v0.17.0).
</Info>

<Info>
  Releases **before v0.17.0** support Python ≥ 3.8, ≤ 3.14.
</Info>

```bash lines theme={"dark"}
pip install -U "truefoundry"
```

<Tip>
  Optional features can be installed with extras.

  * `workflow` extra to work with [Workflows](/docs/workflow-concepts).
  * `spark` extra to work with [Spark Tasks](/docs/spark-task) in workflows.

  <CodeGroup>
    ```bash Workflows Without Spark Tasks lines theme={"dark"}
    pip install -U "truefoundry[workflow]"
    ```

    ```bash Workflows With Spark Tasks lines theme={"dark"}
    pip install -U "truefoundry[workflow,spark]"
    ```
  </CodeGroup>

  **NOTE:** `workflow` and `spark` extras are only supported on Python ≥ 3.10, ≤ 3.12
</Tip>

## Authenticate CLI

To be able to use the TrueFoundry CLI, you first need to authenticate. You can login either via browser or using API Key.

<Tabs>
  <Tab title="Login via Browser using Device Code">
    To log in to **TrueFoundry**, run the following command:

    ```bash lines theme={"dark"}
    tfy login --host <your-truefoundry-host> # e.g. host: https://myorg.truefoundry.cloud
    ```

    <Tip>
      The value for `--host` is the first part of the url when you open the platform. This domain might be subdomain of your organization. The below example shows `https://myorg.truefoundry.cloud`

      <img src="https://mintcdn.com/truefoundry/DdP_2rhue4AQQlob/images/28d53c11-768377df9c43a945e1fcf682bb0c146021cbe5f776fec459e1b4247116e2da65-image.png?fit=max&auto=format&n=DdP_2rhue4AQQlob&q=85&s=75815a04e18ad0546dcf4f8be76fe3d4" alt="" width="2058" height="380" data-path="images/28d53c11-768377df9c43a945e1fcf682bb0c146021cbe5f776fec459e1b4247116e2da65-image.png" />
    </Tip>

    This will prompt you to open a URL and show you a `Submit` button.

    <img src="https://mintcdn.com/truefoundry/5CkapnZ7CyjQJ4bx/images/docs/login-code-screen.png?fit=max&auto=format&n=5CkapnZ7CyjQJ4bx&q=85&s=bebafa5f9bb16d2ae8d189a99bf5c50d" alt="" width="3752" height="1488" data-path="images/docs/login-code-screen.png" />

    Once you click on Submit, you will be signed in to the CLI.

    <img src="https://mintcdn.com/truefoundry/5CkapnZ7CyjQJ4bx/images/docs/login-cli-flow.png?fit=max&auto=format&n=5CkapnZ7CyjQJ4bx&q=85&s=c067d7307c822fcbf0e3ade9a2efc5e4" alt="" width="2338" height="254" data-path="images/docs/login-cli-flow.png" />
  </Tab>

  <Tab title="Login using API Key">
    For scenarios where code interacts with TrueFoundry APIs or where opening a browser is not feasible, you can log in using the TrueFoundry API Key. The steps for this are as follows:

    <Steps>
      <Step title="Generate a TrueFoundry API Key">
        Generate a TrueFoundry API Key from Access -> Personal Access Tokens.

        <iframe provider="app.supademo.com" href="https://app.supademo.com/embed/cmb6f77un3o41ppkpytsnu7ls?embed_v=2" height="450px" width="100%" src="https://app.supademo.com/embed/cmb6f77un3o41ppkpytsnu7ls?embed_v=2" style={{ border:"none",display:"flex",margin:"auto" }} />

        <Warning>
          Your API Key is a sensitive piece of information - so **Never** share it with unauthorized individuals. You will not be able to see the value of the API key on the TrueFoundry platform again - so please save it in a secure location.
        </Warning>

        <Info>
          For production environments, you can use [Virtual Account tokens](/docs/generating-truefoundry-api-keys#virtual-account-tokens-vats) instead of Personal Access Tokens to authenticate. Virtual Account tokens are not tied to a user and hence don't expire when the user leaves the organization.
        </Info>
      </Step>

      <Step title="Use the API key to login">
        You can use the API key to login in two ways:

        #### Option 1: Setting environment variables

        Set the `TFY_API_KEY` and `TFY_HOST` environment variables.

        * Set `TFY_HOST` to your TrueFoundry host URL. e.g. `https://your-domain.truefoundry.com`
        * Set `TFY_API_KEY` to your API key.

        ```bash lines theme={"dark"}
        export TFY_HOST=<your-truefoundry-host>
        export TFY_API_KEY=<your-api-key>
        ```

        You can now use the TrueFoundry SDK to interact with the platform.

        #### Option 2: Using the `login` command on CLI

        When using the CLI, you can provide the API key directly within the command:

        ```bash lines theme={"dark"}
        tfy login --host <your-truefoundry-host> --api-key <your-api-key>
        ```
      </Step>
    </Steps>
  </Tab>
</Tabs>

## FAQ

<AccordionGroup>
  <Accordion title="How do I resolve the 'SSL certificate verification failed' error?">
    This error indicates that the CLI could not verify the HTTPS certificate of the server it is connecting to. The most common causes are:

    * A **corporate proxy or firewall** on your network intercepts HTTPS traffic and re-signs it with its own certificate.
    * The required **CA certificates are missing** from your system.

    **Resolution**

    If you are behind a corporate proxy, obtain your organization's CA certificate bundle (a `.pem` file) from your IT team and point the CLI to it using the `REQUESTS_CA_BUNDLE` environment variable:

    ```bash lines theme={"dark"}
    export REQUESTS_CA_BUNDLE=/path/to/your/ca-bundle.pem
    ```

    Retry the command afterwards. To apply this setting permanently, add the export statement to your shell profile (for example, `~/.zshrc` or `~/.bashrc`).
  </Accordion>

  <Accordion title="How do I resolve the 'Couldn't connect to TrueFoundry through the configured proxy' error?">
    This error indicates that an HTTP/HTTPS proxy is configured on your machine, but the CLI could not establish a connection through it.

    **Resolution**

    * Inspect the values of the `HTTP_PROXY`, `HTTPS_PROXY`, and `NO_PROXY` environment variables:

    ```bash lines theme={"dark"}
    env | grep -i proxy
    ```

    * Verify that the proxy address and port are correct and that the proxy is reachable from your machine.
    * Confirm with your network team that the proxy permits access to your TrueFoundry host.
    * If the TrueFoundry host should be reached directly, bypassing the proxy, add it to `NO_PROXY`:

    ```bash lines theme={"dark"}
    export NO_PROXY=$NO_PROXY,your-domain.truefoundry.com
    ```
  </Accordion>

  <Accordion title="How do I resolve the 'Couldn't connect to TrueFoundry' or 'Failed to connect' error?">
    This error indicates that the CLI could not establish a network connection to the TrueFoundry host.

    **Resolution**

    * Verify that the `--host` value (or the `TFY_HOST` environment variable) is correct. It should match the URL you use to access the TrueFoundry platform in your browser, for example `https://myorg.truefoundry.cloud`.
    * Confirm the host is reachable from your machine:

    ```bash lines theme={"dark"}
    curl -sSf https://<your-truefoundry-host>
    ```

    * If your TrueFoundry installation is accessible only over a private network, ensure you are connected to the **VPN**.
    * Check whether a **firewall or proxy** on your network is blocking access to the host.
  </Accordion>

  <Accordion title="How do I get more details when a CLI command fails?">
    Run the command with the `--debug` flag to print the full traceback:

    ```bash lines theme={"dark"}
    tfy --debug <command>
    ```

    Alternatively, enable debug output through an environment variable:

    ```bash lines theme={"dark"}
    export TFY_DEBUG=1
    ```
  </Accordion>
</AccordionGroup>
