Neptune Client

1.14.0.post2 · active · verified Thu Apr 16

Neptune is an MLOps platform for experiment tracking and model management, focusing on machine learning metadata. The `neptune-client` Python library provides the interface to log, store, display, and compare MLOps artifacts and metadata directly from your code. It is currently at version 1.14.0.post2, with active development including an upcoming 2.x branch, and releases frequent updates.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart initializes a Neptune run, logs basic parameters and metrics, tracks a placeholder for a model checkpoint, and then stops the run. Ensure you have your `NEPTUNE_API_TOKEN` and `NEPTUNE_PROJECT` (e.g., 'your_workspace/your_project') set as environment variables or passed directly to `init_run`.

import neptune
import os
import random

# Initialize a new Neptune run
# Replace 'YOUR_WORKSPACE/YOUR_PROJECT_NAME' with your actual project name, e.g., 'common/quickstart-python'
# Set NEPTUNE_API_TOKEN and NEPTUNE_PROJECT as environment variables for production use.
run = neptune.init_run(
    project=os.environ.get("NEPTUNE_PROJECT", "common/quickstart-python"),
    api_token=os.environ.get("NEPTUNE_API_TOKEN", "YOUR_NEPTUNE_API_TOKEN"), # Replace with your token if not using env var
    name="Minimal Example",
    tags=["quickstart", "example"]
)

# Log some parameters
params = {"learning_rate": 0.001, "optimizer": "Adam"}
run["parameters"] = params

# Log some metrics
for i in range(10):
    run["train/loss"].append(random.uniform(0.1, 0.9))
    run["train/accuracy"].append(random.uniform(0.5, 0.99))

# Log a model checkpoint placeholder (e.g., a path or a link)
run["model_checkpoints/best_model"].track_files("s3://my-bucket/models/best_model.pth")

# Stop the run
run.stop()

print(f"Neptune run URL: {run.get_url()}")

view raw JSON →