Skip to content

API reference: Sacred integration#

The Neptune-Sacred integration provides a Sacred observer that logs experiment metadata to Neptune.


Logs Sacred experiment data to Neptune.


Name      Type Default     Description
run Run or Handler - An existing run reference, as returned by neptune.init_run(), or a namespace handler.
base_namespace str, optional "experiment" Namespace under which all metadata logged by the observer will be stored.


Start a Neptune run:

import neptune

run = neptune.init_run()
If Neptune can't find your project name or API token

As a best practice, you should save your Neptune API token and project name as environment variables:

export NEPTUNE_API_TOKEN="h0dHBzOi8aHR0cHM6Lkc78ghs74kl0jv...Yh3Kb8"
export NEPTUNE_PROJECT="ml-team/classification"

Alternatively, you can pass the information when using a function that takes api_token and project as arguments:

run = neptune.init_run( # (1)!
    api_token="h0dHBzOi8aHR0cHM6Lkc78ghs74kl0jv...Yh3Kb8",  # your token here
    project="ml-team/classification",  # your full project name here
  1. Also works for init_model(), init_model_version(), init_project(), and integrations that create Neptune runs underneath the hood, such as NeptuneLogger or NeptuneCallback.

  2. API token: In the bottom-left corner, expand the user menu and select Get my API token.

  3. Project name: You can copy the path from the project details ( Edit project details).

If you haven't registered, you can log anonymously to a public project:


Make sure not to publish sensitive data through your code!

Create an experiment:

from sacred import Experiment

ex = Experiment("image_classification", interactive=True)

Add a Neptune observer:

from neptune.integrations.sacred import NeptuneObserver


Define the model and run the experiment:

class BaseModel(torch.nn.Module):

model = BaseModel()

def cfg():

def _run(...):

See also

neptune-sacred repo on GitHub