Neptune Client

1.14.0.post2 · active · verified Thu Apr 16

Neptune Client is the Python library for interacting with Neptune.ai, an MLOps platform for experiment tracking and model management. It allows users to log, organize, and visualize machine learning metadata, including hyperparameters, metrics, and artifacts. The current version is 1.14.0.post2, and the library is actively maintained with frequent releases.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a Neptune run, log hyperparameters, track metrics over time, and upload an artifact. It assumes `NEPTUNE_API_TOKEN` and `NEPTUNE_PROJECT` are set as environment variables for authentication and project selection. If not, replace the placeholders with your actual token and project name. The code creates a local 'sample_output.txt' file and uploads it as an artifact.

import neptune
import os

# Replace with your actual API token and project name
# It is recommended to set NEPTUNE_API_TOKEN and NEPTUNE_PROJECT as environment variables
# os.environ["NEPTUNE_API_TOKEN"] = "YOUR_NEPTUNE_API_TOKEN"
# os.environ["NEPTUNE_PROJECT"] = "YOUR_WORKSPACE/YOUR_PROJECT"

# Initialize a Neptune run
run = neptune.init_run(
    project=os.environ.get('NEPTUNE_PROJECT', 'common/quickstarts'), # Replace with your workspace and project name
    api_token=os.environ.get('NEPTUNE_API_TOKEN', ''), # Replace with your API token or set env variable
    name='my-first-run',
    tags=['quickstart', 'example']
)

# Log hyperparameters
hparams = {
    'learning_rate': 0.001,
    'epochs': 10,
    'batch_size': 32
}
run['hyperparameters'] = hparams

# Log metrics
for i in range(10):
    run['metrics/accuracy'].append(0.85 + i * 0.01)
    run['metrics/loss'].append(0.3 - i * 0.02)

# Log a file
with open('sample_output.txt', 'w') as f:
    f.write('This is a sample output file.')
run['artifacts/output_file'].upload('sample_output.txt')

# Stop the run
run.stop()

view raw JSON →