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:
- In the bottom-left corner of the app, expand your user menu.
-
Select Get Your API token.
-
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.From the API token dialog in Neptune, copy the
export
command and append the line to your.profile
or other shell initialization file.-
From the API token dialog in Neptune, copy the
setx
command. -
Open a terminal app, such as PowerShell or Command Prompt.
- Paste the line you copied and press enter.
- 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:
- In the top-right corner, click the settings menu ().
-
Select Edit project details.
-
Find the copy button () next to the project name.
-
Assign the project name to an environment variable named
NEPTUNE_PROJECT
:Append the following line to your
.profile
(or other shell configuration file):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):where
workspace-name/project-name
is the full project name you just copied.To set the project name permanently:
- Open a terminal app, such as PowerShell or Command Prompt.
-
Paste in the following command and press enter:
where
workspace-name/project-name
is the full project name you just copied. -
To activate the change, restart the terminal.
You can use the os library to set the project name as an environment variable:
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.
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.
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/
.
See also
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
: