Module Contents


NeptuneObserver(project_name, api_token=None, source_extensions=None)

Logs sacred experiment data to Neptune.


_flatten_dict(d, parent_key=’‘, sep=’ ‘)


class neptunecontrib.monitoring.sacred.NeptuneObserver(project_name, api_token=None, source_extensions=None)

Bases: sacred.observers.RunObserver

Logs sacred experiment data to Neptune.

Sacred observer that logs experiment metadata to neptune. The experiment data can be accessed and shared via web UI or experiment API. Check Neptune docs for more information

  • project_name (str) – project name in Neptune app

  • api_token (str) – Neptune API token. If it is kept in the NEPTUNE_API_TOKEN environment variable leave None here.

  • source_extensions (list(str)) – list of extensions that Neptune should treat as source files extensions and send. If None is passed, Python file from which experiment was created will be uploaded. Pass 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. For recursion lookup use ‘*/*.py’ (for Python 3.5 and later). For more information see glob library.


Create sacred experiment:

from numpy.random import permutation
from sklearn import svm, datasets
from sacred import Experiment

ex = Experiment('iris_rbf_svm')

Add Neptune observer:

from neptunecontrib.monitoring.sacred import NeptuneObserver

Run experiment:

def cfg():
    C = 1.0
    gamma = 0.7

def run(C, gamma, _run):
    iris = datasets.load_iris()
    per = permutation( =[per] =[per]
    clf = svm.SVC(C, 'rbf', gamma=gamma)[:90],
    return clf.score([90:],

Go to the app and see the experiment. For example,

started_event(self, ex_info, command, host_info, start_time, config, meta_info, _id)
completed_event(self, stop_time, result)
interrupted_event(self, interrupt_time, status)
failed_event(self, fail_time, fail_trace)
artifact_event(self, name, filename, metadata=None, content_type=None)
resource_event(self, filename)
log_metrics(self, metrics_by_name, info)
neptunecontrib.monitoring.sacred._flatten_dict(d, parent_key='', sep=' ')