Skip to content

Neptune environment variables#

To improve the security and operationalization of your workflow, you can store certain arguments of the Neptune initialization functions as environment variables.

This lets you control experiment tracking parameters separately from the model-training code.

Tip

You should always store your Neptune API token as an environment variable rather than passing it through your model-training source code.

As a best practice, we recommend you do the same for the project name. For details, see Set your API token and Set the project name.

Environment variable name Description Example
NEPTUNE_API_TOKEN Neptune API token h0dHBzOi8...aHR0cHM6E0ZjMifQ==
NEPTUNE_PROJECT Neptune project name ml-team/classification
NEPTUNE_CUSTOM_RUN_ID Custom run identifier `date | md5`
NEPTUNE_MODE Connection mode for the tracking debug
NEPTUNE_DATA_DIRECTORY Path to .neptune directory /path/to/directory/
NEPTUNE_ALLOW_SELF_SIGNED_CERTIFICATE Whether to allow self-signed certificates TRUE

NEPTUNE_API_TOKEN#

Info

If you don't provide the api_token parameter to a Neptune init function, the value of this environment variable will be used.

The API token is used for authentication. It's like a password to the application, so you should always keep it secret. The best way to do that is to store it in an environment variable called NEPTUNE_API_TOKEN. This way, Neptune picks it up from the environment automatically and you don't need to store the token in the source code.

To find and save your API token as an environment variable:

  1. In the bottom-left corner of the app, expand your user menu.
  2. Select Get Your API token.

    How to find your Neptune API token

  3. Depending on your system:

    From the API token dialog in Neptune, copy the export command and append the line to your .profile or other shell initialization file.

    Example line
    export NEPTUNE_API_TOKEN="uyVrZXkiOiIzNTd..."
    

    From the API token dialog in Neptune, copy the export command and append the line to your .profile or other shell initialization file.

    Example line
    export NEPTUNE_API_TOKEN="uyVrZXkiOiIzNTd..."
    
    1. From the API token dialog in Neptune, copy the setx command.

      Example line
      setx NEPTUNE_API_TOKEN "uyVrZXkiOiIzNTd..."
      
    2. Open a terminal app, such as PowerShell or Command Prompt.

    3. Paste the line you copied and press enter.
    4. To activate the change, restart the terminal app.

    You can use the os library to set the token as an environment variable.

    Add the following to a notebook cell:

    import os
    from getpass import getpass
    os.environ["NEPTUNE_API_TOKEN"] = getpass("Enter your Neptune API token: ")
    

    From the API token dialog, copy your token, paste it in the input box, and hit Enter.

    Note that any environment variables declared this way won't persist after the notebook kernel shuts down. If you start a new kernel, they need to be set again.

NEPTUNE_PROJECT#

Info

If you don't provide the project parameter to a Neptune init function, the value of this environment variable will be used.

The project in which new runs will be created. The project name is given in the form workspace-name/project-name.

To find and set your project name:

  1. In the top-right corner, click the settings menu ().
  2. Select Edit project details.

    How to access project details

  3. Find the copy button () next to the project name.

  4. Assign the project name to an environment variable named NEPTUNE_PROJECT:

    Append the following line to your .profile (or other shell configuration file):

    export NEPTUNE_PROJECT="workspace-name/project-name"
    

    where workspace-name/project-name is the full project name you just copied.

    Append the following line to your .profile (or other shell configuration file):

    export NEPTUNE_PROJECT="workspace-name/project-name"
    

    where workspace-name/project-name is the full project name you just copied.

    To set the project name permanently:

    1. Open a terminal app, such as PowerShell or Command Prompt.
    2. Paste in the following command and press enter:

      setx NEPTUNE_PROJECT "workspace-name/project-name"
      

      where workspace-name/project-name is the full project name you just copied.

    3. To activate the change, restart the terminal.

    You can use the os library to set the project name as an environment variable:

    import os
    os.environ["NEPTUNE_PROJECT"] = "workspace-name/project-name"
    

    where workspace-name/project-name is the full project name you just copied.

    Note that any environment variables declared this way won't persist after the notebook kernel shuts down. If you start a new kernel, they need to be set again.

NEPTUNE_CUSTOM_RUN_ID#

Info

If you don't provide the custom_run_id parameter to a Neptune init function, the value of this environment variable will be used.

A unique identifier (ID) that can be used to log metadata to a single run from multiple files or processes. This can be useful if your flow involves distributed training, or you're logging metadata at multiple steps of a pipeline.

The maximum length of the custom ID is 36 characters. Make sure to:

  • Use the same ID everywhere.
  • Clear the ID once you want to log to a different run.
export NEPTUNE_CUSTOM_RUN_ID=`date +"%Y%m%d%H%M%s%N" | md5sum`
export NEPTUNE_CUSTOM_RUN_ID=`date +"%Y%m%d%H%M%s%N" | md5`
export NEPTUNE_CUSTOM_RUN_ID=`date +"%Y%m%d%H%M%s%N"`

NEPTUNE_MODE#

The connection mode in which the tracking will work when a new run or other object is initialized.

The default is asynchronous (async), which means that Neptune periodically synchronizes the logged metadata with the server in the background.

You can change the mode, for example, to immediately synchronize the data each time a tracking call is made (such as append() or upload()). You can also log offline and manually sync the data later, or log in debug mode so that no data is stored anywhere.

To learn more, see Connection modes reference.

export NEPTUNE_MODE='debug'
export NEPTUNE_MODE='debug'
set NEPTUNE_MODE='debug'
%env NEPTUNE_MODE='debug'

NEPTUNE_DATA_DIRECTORY#

Path where the .neptune directory should be created.

Normally the Neptune data directory (.neptune/) is created in the current working directory (CWD). If your CWD is not writeable for any reason, you can use this environment variable to specify a different location for the .neptune folder.

For example, if you declare NEPTUNE_DATA_DIRECTORY=/path/to/dir then the Neptune data directory will be at /path/to/dir/.neptune/.

NEPTUNE_ALLOW_SELF_SIGNED_CERTIFICATE#

In some infrastructure setups, you may encounter problems connecting to Neptune because of the SSL certificate configuration. This can happen if, for example:

  • You are in a corporate network, behind a proxy that inspects traffic between your runs and Neptune SaaS.
  • The SSL/TLS certificate of your on-premises installation is not recognized by Python by default.
  • The software on your machine is not up to date.

Those problems typically show as an SSLError or NeptuneConnectionLostException.

To solve it, open a terminal and set the NEPTUNE_ALLOW_SELF_SIGNED_CERTIFICATE environment variable to a value of TRUE:

export NEPTUNE_ALLOW_SELF_SIGNED_CERTIFICATE='TRUE'
export NEPTUNE_ALLOW_SELF_SIGNED_CERTIFICATE='TRUE'
set NEPTUNE_ALLOW_SELF_SIGNED_CERTIFICATE='TRUE'
%env NEPTUNE_ALLOW_SELF_SIGNED_CERTIFICATE='TRUE'