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 Default (if not set) Example value
NEPTUNE_API_TOKEN Neptune API token - h0dHBzOi8aHR06E0Z...jMifQ==
NEPTUNE_PROJECT Neptune project name - ml-team/classification
NEPTUNE_CUSTOM_RUN_ID Custom run identifier - `date | md5`
NEPTUNE_MODE Connection mode for the logging async debug
NEPTUNE_DATA_DIRECTORY Path to .neptune directory CWD /path/to/directory/
NEPTUNE_ALLOW_SELF_SIGNED_CERTIFICATE Whether to allow self-signed certificates False True
NEPTUNE_MAX_DISK_USAGE As a percentage, the max disk usage allowed for Neptune - 80
NEPTUNE_RAISE_ERROR_ON_DISK_USAGE_EXCEEDED Whether Neptune should raise an exception on excessive disk usage, instead of only warning True False
NEPTUNE_ENABLE_DEFAULT_ASYNC_NO_PROGRESS_CALLBACK Whether to use the default callback if the synchronization doesn't progress False True
NEPTUNE_ENABLE_DEFAULT_ASYNC_LAG_CALLBACK Whether to use the default callback when the synchronization lags False 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 also navigate to SettingsEdit the system environment variables and add the variable there.

    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. Open the project settings ( ).
  2. Select Details & privacy.

    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 also navigate to SettingsEdit the system environment variables and add the variable there.

    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`
set 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'
setx 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 self-hosted 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'
setx NEPTUNE_ALLOW_SELF_SIGNED_CERTIFICATE 'True'
%env NEPTUNE_ALLOW_SELF_SIGNED_CERTIFICATE='True'

NEPTUNE_MAX_DISK_USAGE#

You can manage the maximum allowed disk usage by setting a percentage value to the NEPTUNE_MAX_DISK_USAGE environment variable.

By default, Neptune will raise an exception if this limit is exceeded. (If you want Neptune to simply stop logging and saving data to disk instead of throwing an error, you can set NEPTUNE_RAISE_ERROR_ON_DISK_USAGE_EXCEEDED to False.)

For example, to limit Neptune's disk usage to 80%:

export NEPTUNE_MAX_DISK_USAGE=80
export NEPTUNE_MAX_DISK_USAGE=80
setx NEPTUNE_MAX_DISK_USAGE 80
%env NEPTUNE_MAX_DISK_USAGE=80

NEPTUNE_RAISE_ERROR_ON_DISK_USAGE_EXCEEDED#

If this environment variable is set to True or not set, Neptune will raise an exception if the disk usage allowed by the NEPTUNE_MAX_DISK_USAGE option is exceeded.

If you set NEPTUNE_RAISE_ERROR_ON_DISK_USAGE_EXCEEDED to False, Neptune will instead just print a warning and stop saving data to the disk.

export NEPTUNE_RAISE_ERROR_ON_DISK_USAGE_EXCEEDED='False'
export NEPTUNE_RAISE_ERROR_ON_DISK_USAGE_EXCEEDED='False'
setx NEPTUNE_RAISE_ERROR_ON_DISK_USAGE_EXCEEDED 'False'
%env NEPTUNE_RAISE_ERROR_ON_DISK_USAGE_EXCEEDED='False'

NEPTUNE_ENABLE_DEFAULT_ASYNC_LAG_CALLBACK#

Whether to enable the default callback when the lag between a queued operation and its synchronization with the server exceeds 1800 seconds (30 minutes).

You can override this default threshold with the async_lag_threshold initialization parameter.

The default callback function (stop_synchronization_callback()) stops the object after 60 seconds of the callback being called.

To enable the default callback, open a terminal and set the environment variable to a value of True:

export NEPTUNE_ENABLE_DEFAULT_ASYNC_LAG_CALLBACK='True'
export NEPTUNE_ENABLE_DEFAULT_ASYNC_LAG_CALLBACK='True'
setx NEPTUNE_ENABLE_DEFAULT_ASYNC_LAG_CALLBACK 'True'
%env NEPTUNE_ENABLE_DEFAULT_ASYNC_LAG_CALLBACK='True'

Related

For the full guide, see How to use callbacks when sync is interrupted.

NEPTUNE_ENABLE_DEFAULT_ASYNC_NO_PROGRESS_CALLBACK#

Whether to enable the default callback when the synchronization with the server has not progressed at all for 300 seconds (5 minutes).

You can override this default threshold with the async_no_progress_threshold initialization parameter.

The default callback function (stop_synchronization_callback()) stops the object after 60 seconds of the callback being called.

To enable the default callback, open a terminal and set the environment variable to a value of True:

export NEPTUNE_ENABLE_DEFAULT_ASYNC_NO_PROGRESS_CALLBACK='True'
export NEPTUNE_ENABLE_DEFAULT_ASYNC_NO_PROGRESS_CALLBACK='True'
setx NEPTUNE_ENABLE_DEFAULT_ASYNC_NO_PROGRESS_CALLBACK 'True'
%env NEPTUNE_ENABLE_DEFAULT_ASYNC_NO_PROGRESS_CALLBACK='True'

Related

For the full guide, see How to use callbacks when sync is interrupted.