neptune API reference

API reference for the neptune package and its functions.

You can use the global neptune object to initialize new Neptune objects or resume existing ones.

import neptune

init_project()

Starts a connection to an existing Neptune project. You can use it to fetch metadata of runs in the project.

You can also use the project object to manage metadata common to the whole project, such as information about datasets, links to documents, or key project metrics.

Parameters

Name Type Default Description
project str, optional None Name of a project in the form workspace-name/project-name. If None, the value of the NEPTUNE_PROJECT environment variable is used.
api_token str, optional None Your Neptune API token (or a service account's API token). If None, the value of the NEPTUNE_API_TOKEN environment variable is used. To keep your token secure, avoid placing it in source code. Instead, save it as an environment variable.
mode str, optional async Connection mode in which the logging will work. Possible values are async, sync, read-only, and debug. If you leave it out, the value of the NEPTUNE_MODE environment variable is used. If that's not set, the default async is used.
flush_period float, optional 5(seconds) In asynchronous (default) connection mode, how often Neptune should trigger disk flushing.
proxies dict, optional None Argument passed to HTTP calls made via the Requests library. For details on proxies, see the Requests documentation.
async_lag_callback NeptuneObjectCallback, optional None Custom callback function which is called if the lag between a queued operation and its synchronization with the server exceeds the duration defined by async_lag_threshold. The callback should take a Project object as the argument and can contain any custom code, such as calling stop() on the object. Note: Instead of using this argument, you can use Neptune's default callback by setting the NEPTUNE_ENABLE_DEFAULT_ASYNC_LAG_CALLBACK environment variable to TRUE.
async_lag_threshold float, optional 1800.0(seconds) Duration between the queueing and synchronization of an operation. If a lag callback (default callback enabled via environment variable or custom callback passed to the async_lag_callback argument) is enabled, the callback is called when this duration is exceeded.
async_no_progress_callback NeptuneObjectCallback, optional None Custom callback function which is called if there has been no synchronization progress whatsoever for the duration defined by async_no_progress_threshold. The callback should take a Project object as the argument and can contain any custom code, such as calling stop() on the object. Note: Instead of using this argument, you can use Neptune's default callback by setting the NEPTUNE_ENABLE_DEFAULT_ASYNC_NO_PROGRESS_CALLBACK environment variable to TRUE.
async_no_progress_threshold float, optional 300.0(seconds) For how long there has been no synchronization progress. If a no-progress callback (default callback enabled via environment variable or custom callback passed to the async_no_progress_callback argument) is enabled, the callback is called when this duration is exceeded.

To keep your token secure, avoid placing it in source code. Instead, save it as an environment variable.

If you leave it out, the value of the NEPTUNE_MODE environment variable is used. If that's not set, the default async is used.

Note: Instead of using this argument, you can use Neptune's default callback by setting the NEPTUNE_ENABLE_DEFAULT_ASYNC_LAG_CALLBACK environment variable to TRUE.

Note: Instead of using this argument, you can use Neptune's default callback by setting the NEPTUNE_ENABLE_DEFAULT_ASYNC_NO_PROGRESS_CALLBACK environment variable to TRUE.

The name parameter was changed to project in neptune-client 0.16.16.

Returns

Projectobject that can be used to interact with the project as a whole, like logging or fetching project-level metadata.

Example

Connect to the project "classification" in the workspace "ml-team":

import neptune

project = neptune.init_project(project="ml-team/classification")

project["general/data_analysis"].upload("data_analysis.ipynb")

Theprojectobject follows the same logic as other Neptune objects: If you assign a new value to an existing field, the new value overwrites the previous one.

In a given project, you always initialize and work with the sameprojectobject, so take care not to accidentally overwrite each other's entries if your team is collaborating on project metadata.

Tip

Recall that theappend()method appends the logged value to a series. It works for text strings as well as numerical values.

Connect to a project in read-only mode:

project = neptune.init_project(
 project="ml-team/classification",
 mode="read-only",
)

init_run()

Starts a new tracked run and adds it to the top of the experiments table.

Since all parameters are optional, the minimal invocation is:

import neptune

run = neptune.init_run()

See also: Defining a custom init_run() function, for keeping the logging consistent within your team.

If you initialize a run in an interactive session (Python interpreter or Jupyter Notebook), the following monitoring options are disabled by default:

  • capture_stdout
  • capture_hardware_metrics

To enable them, set each parameter to True when initializing the run. Note: The monitoring will continue until you call run.stop() or the kernel stops.

Also note: Your source files can only be tracked if you pass the path(s) to the source_code argument. For help, see Logging source code.

Parameters

Name Type Default Description
project str, optional None Name of a project in the formworkspace-name/project-name. If None, the value of theNEPTUNE_PROJECTenvironment variable is used.
api_token str, optional None Your Neptune API token (or a service account's API token). If None, the value of theNEPTUNE_API_TOKENenvironment variable is used.To keep your token secure, avoid placing it in source code. Instead,save it as an environment variable.
with_id str, optional None The Neptune identifier of an existing run to resume, such as "CLS-11". The identifier is stored in the object'ssys/idfield. If omitted orNoneis passed, a new tracked run is created.
custom_run_id str, optional None A unique identifier that can be used to log metadata to a single run from multiple locations. Max length: 36 characters. If None and theNEPTUNE_CUSTOM_RUN_IDenvironment variable is set, Neptune will use that as thecustom_run_idvalue. For details, seeSet custom run ID.
mode str, optional async Connection mode in which the logging will work. Possible values areasync,sync,offline,read-only, anddebug.If you leave it out, the value of theNEPTUNE_MODEenvironment variable is used. If that's not set, the defaultasyncis used.
name str, optional Neptune ID Custom name for the run. You can use it as a human-readable ID and add it as a column in the experiments table (sys/name). If left empty, once the run is synchronized with the server, Neptune sets the auto-generated identifier (sys/id) as the name.
description str, optional "" Editable description of the run. You can add it as a column in the experiments table (sys/description).
tags list, optional [] Must be a list ofstrwhich represent the tags for the run. You can edit them after run is created, either in the run information or experiments table.
source_files listorstr, optional None List of source files to be uploaded. Must be list ofstror a singlestr. Uploaded sources are displayed in theSource codesection of the run.If Noneis passed, the Python file from which the run was created will be uploaded. When resuming a run, no file will be uploaded by default. Pass an empty list ([]) to upload no files.Unix style pathname pattern expansion is supported. For example, you can pass".py"to upload all Python source files from the current directory. Paths of uploaded files are resolved relative to the calculated common root of all uploaded source files. For recursion lookup, use"**/.py"(for Python3.5and later). For details, see thegloblibrary.
capture_stdout Boolean, optional True Whether to log the standard output stream. Is logged in themonitoringnamespace.
capture_stderr Boolean, optional True Whether to log the standard error stream. Is logged in themonitoringnamespace.
capture_hardware_metrics Boolean, optional True Whether to track hardware consumption (CPU, GPU, memory utilization). Logged in themonitoringnamespace.
fail_on_exception Boolean, optional True If an uncaught exception occurs, whether to set run'sFailedstate toTrue.
monitoring_namespace str, optional "monitoring" Namespace inside which all monitoring logs will be stored.
flush_period float, optional 5(seconds) In asynchronous (default) connection mode, how often Neptune should triggerdisk flushing.
proxies dict, optional None Argument passed to HTTP calls made via theRequestslibrary. For details on proxies, see the Requests documentation.
capture_traceback Boolean, optional True In case of an exception, whether to log the traceback of the run.
git_ref GitReforBoolean None GitRefobject containing information about the Git repository path.If None, Neptune looks for a repository in the path of the script that is executed.To specify a different location, set toGitRef(repository_path="path/to/repo").To turn off Git tracking for the run, set toGitRef.DISABLEDorFalse.For examples, seeLogging Git info.
dependencies str, optional None Tracks environment requirements. If you pass"infer"to this argument, Neptune logs dependencies installed in the current environment. You can also pass a path to your dependency file directly. If left empty, no dependency file is uploaded.
async_lag_callback NeptuneObjectCallback, optional None Custom callback function which is called if the lag between a queued operation and its synchronization with the server exceeds the duration defined byasync_lag_threshold. The callback should take aRunobject as the argument and can contain any custom code, such as callingstop()on the object.Note:Instead of using this argument, you can use Neptune's default callback by setting theNEPTUNE_ENABLE_DEFAULT_ASYNC_LAG_CALLBACKenvironment variable toTRUE.
async_lag_threshold float, optional 1800.0(seconds) Duration between the queueing and synchronization of an operation. If a lag callback (default callback enabled via environment variable or custom callback passed to theasync_lag_callbackargument) is enabled, the callback is called when this duration is exceeded.
async_no_progress_callback NeptuneObjectCallback, optional None Custom callback function which is called if there has been no synchronization progress whatsoever for the duration defined byasync_no_progress_threshold. The callback should take aRunobject as the argument and can contain any custom code, such as callingstop()on the object.Note:Instead of using this argument, you can use Neptune's default callback by setting theNEPTUNE_ENABLE_DEFAULT_ASYNC_NO_PROGRESS_CALLBACKenvironment variable toTRUE.
async_no_progress_threshold float, optional 300.0(seconds) For how long there has been no synchronization progress. If a no-progress callback (default callback enabled via environment variable or custom callback passed to theasync_no_progress_callbackargument) is enabled, the callback is called when this duration is exceeded.

To keep your token secure, avoid placing it in source code. Instead,save it as an environment variable.

If you leave it out, the value of theNEPTUNE_MODEenvironment variable is used. If that's not set, the defaultasyncis used.

List of source files to be uploaded. Must be list ofstror a singlestr. Uploaded sources are displayed in theSource codesection of the run.

IfNoneis passed, the Python file from which the run was created will be uploaded. When resuming a run, no file will be uploaded by default. Pass an empty list ([]) to upload no files.

Unix style pathname pattern expansion is supported. For example, you can pass".py"to upload all Python source files from the current directory. Paths of uploaded files are resolved relative to the calculated common root of all uploaded source files. For recursion lookup, use"**/.py"(for Python3.5and later). For details, see thegloblibrary.

IfNone, Neptune looks for a repository in the path of the script that is executed.

To specify a different location, set toGitRef(repository_path="path/to/repo").

To turn off Git tracking for the run, set toGitRef.DISABLEDorFalse.

Note:Instead of using this argument, you can use Neptune's default callback by setting theNEPTUNE_ENABLE_DEFAULT_ASYNC_LAG_CALLBACKenvironment variable toTRUE.

Note:Instead of using this argument, you can use Neptune's default callback by setting theNEPTUNE_ENABLE_DEFAULT_ASYNC_NO_PROGRESS_CALLBACKenvironment variable toTRUE.

Therunparameter was changed towith_idin neptune-client0.16.7.

Returns

Runobject that is used to manage the tracked run and log metadata to it.

Examples

Create a new run:

import neptune

run = neptune.init_run()

Create a run with a custom name:

run = neptune.init_run(name="timid-bramble")

Create a run with:

  • a name and description
  • custom monitoring namespace (recommended)
  • no sources files or Git info uploaded
run = neptune.init_run(
 name="jolly-butter",
 description="neural net trained on MNIST",
 monitoring_namespace="monitoring",
 source_files=[],
 git_ref=False,
)

Resume an existing run, to continue logging to it:

import neptune

run = neptune.init_run(with_id="CLAS-134")

run["namespace/field"] = some_metadata
...

The Neptune ID is a unique identifier for the run. TheExperimentstab displays it in the leftmost column.

In the run structure, the ID is stored in the system namespace (sys).

  • If the run is active, you can obtain its ID withrun["sys/id"].fetch(). For example: >>>run=neptune.init_run()...>>>run["sys/id"].fetch()'CLS-26'
  • If you set a custom run ID, it's stored atsys/custom_run_id: >>>run["sys/custom_run_id"].fetch()'vigilant-puffin-20bt9'

If the run is active, you can obtain its ID withrun["sys/id"].fetch(). For example:

>>> run = neptune.init_run()
...
>>> run["sys/id"].fetch()
'CLS-26'

If you set a custom run ID, it's stored atsys/custom_run_id:

>>> run["sys/custom_run_id"].fetch()
'vigilant-puffin-20bt9'

Resume a run in read-only mode, to only read metadata from it:

run = neptune.init_run(with_id="CLAS-134", mode="read-only")

run["train/model_weights"].download()

Resume a run in order todelete data:

run = neptune.init_run(
 with_id="CLAS-134",
 capture_hardware_metrics=False,
 capture_stderr=False,
 capture_stdout=False,
 capture_traceback=False,
 git_ref=False,
 source_code=[],
)

del run["namespace"]

Start a new run and log all Python files in the current working directory (excluding hidden files with names beginning with a dot):

run = neptune.init_run(source_files="*.py")

Log all Python files from all subdirectories (excluding hidden files):

run = neptune.init_run(source_files="**/*.py")

Log all files and directories in the current working directory (excluding hidden files):

run = neptune.init_run(source_files="*")

Log all files and directories in the current working directory, including hidden files

run = neptune.init_run(source_files=["*", ".*"])

Larger example:

run = neptune.init_run(
 name="first-pytorch-ever",
 description="Write a longer description here.",
 tags=["pytorch", "test", "do-not-delete"],
 source_files=["training_with_pytorch.py", "net.py"],
 capture_hardware_metrics=False,
 dependencies="infer",
)

While it's not a recommended practice, you can also pass your Neptune credentials in the code when initializing Neptune.

run = neptune.init_run(
 project="ml-team/classification", # your full project name here
 api_token="h0dHBzOi8aHR0cHM6Lkc78ghs74kl0jvYh3Kb8", # your API token here
)

Set your Neptune API token and full project name to theNEPTUNE_API_TOKENandNEPTUNE_PROJECTenvironment variables, respectively.

export NEPTUNE_API_TOKEN="h0dHBzOi8aHR0cHM.4kl0jvYh3Kb8...ifQ=="
export NEPTUNE_PROJECT="ml-team/classification"
export NEPTUNE_API_TOKEN="h0dHBzOi8aHR0cHM.4kl0jvYh3Kb8...ifQ=="
export NEPTUNE_PROJECT="ml-team/classification"
setx NEPTUNE_API_TOKEN "h0dHBzOi8aHR0cHM.4kl0jvYh3Kb8...ifQ=="
setx NEPTUNE_PROJECT "ml-team/classification"

You can also navigate toSettings→Edit the system environment variablesand add the variables there.

%env NEPTUNE_API_TOKEN="h0dHBzOi8aHR0cHM.4kl0jvYh3Kb8...ifQ=="
%env NEPTUNE_PROJECT="ml-team/classification"

To find your credentials:

  • API token : In the bottom-left corner of the Neptune app, expand your user menu and select Get your API token . If you need the token of a service account, go to the workspace or project settings and enter the Service accounts settings.
  • Project name : Your full project name has the form workspace-name/project-name . You can copy it from the project menu ( → Details & privacy ).

If you're working in Google Colab, you can set your credentials with the os and getpass libraries:

import os
from getpass import getpass
os.environ["NEPTUNE_API_TOKEN"] = getpass("Enter your Neptune API token: ")
os.environ["NEPTUNE_PROJECT"] = "workspace-name/project-name"

ANONYMOUS_API_TOKEN

API token for anonymous logging.

You can use this value for theapi_tokenargument of theinitfunctions.

Example

Start a run as an anonymous user:

import neptune

run = neptune.init_run(
 api_token=neptune.ANONYMOUS_API_TOKEN,
 project="common/quickstarts",
)

If you're not using a function from theneptunepackage to initialize Neptune, you can also import and use the anonymous API token separately.

from pytorch_lightning import Trainer
from pytorch_lightning.loggers import NeptuneLogger

from neptune import ANONYMOUS_API_TOKEN

neptune_logger = NeptuneLogger(
 api_key=ANONYMOUS_API_TOKEN, 
 project=...,
)


This page is originally sourced from the legacy docs.