About the Neptune Python Library

Neptune client is an open source Python library that lets you integrate your Python scripts with Neptune so that you can more easily track and organize your experiments in the rich Neptune dashboard.

Once you have integrated with Neptune, you can also:

  • Create experiments. Example.

  • Manage running experiments. Example.

  • Fetch experiment and project data. Example.

The Neptune Python Library reference provides a complete description of these capabilities.

Note

You must register with Neptune to use neptune-client.

Installation

pip install neptune-client

Once you have successfully installed the package, add import neptune to your code to use neptune-client capabilities. See the following example.

Example

The following code creates a Neptune experiment in the project shared/onboarding. Name (Python str) and parameters (Python dict) are added to the experiment in the create_experiment() method. The code logs iteration, loss and text_info metrics to Neptune in real time, using three dedicated methods. It also showcases a common use case for Neptune client, that is, tracking progress of machine learning experiments.

import neptune
import numpy as np

# select project
neptune.init('shared/onboarding',
             api_token='ANONYMOUS')

# define parameters
PARAMS = {'decay_factor': 0.7,
          'n_iterations': 117}

# create experiment
neptune.create_experiment(name='quick_start_example',
                          params=PARAMS)

# log some metrics
for i in range(1, PARAMS['n_iterations']):
    neptune.log_metric('iteration', i)
    neptune.log_metric('loss', PARAMS['decay_factor']/i**0.5)
    neptune.log_text('text_info', 'some value {}'.format(0.95*i**2))

# add tag to the experiment
neptune.append_tag('quick_start')

# log some images
for j in range(5):
    array = np.random.rand(10, 10, 3)*255
    array = np.repeat(array, 30, 0)
    array = np.repeat(array, 30, 1)
    neptune.log_image('mosaics', array)

Note

Save the code as main.py and run it using the command: python main.py.