Skip to main content
App version: 3.4.8

Old Fetcher API

For how to the old version of the Neptune Fetcher API, see:

Migrate to Fetcher Alpha

To use the new Alpha API instead of the old one, you need to make some changes to your code.

The following sections show the code differences side by side.

Key differences in Alpha:
  • The new API version is in the alpha module and must be imported from there.
  • The project and API token are read from environment variables at initialization. To work with other projects, you can flexibly set the context either globally for the fetching session or individually for a fetching call.
  • Instead of the query parameter and NQL queries, there are more convenient ways to construct regex search terms or more advanced filters.
  • To work with runs, you must import the run methods from the runs module.

Imports

Old
from neptune_fetcher import (
ReadOnlyProject,
ReadOnlyRun,
)
Alpha
import neptune_fetcher.alpha as npt
Optional imports

For more advanced filtering than name search, import filters from the filters module:

from neptune_fetcher.alpha.filters import (
Attribute,
AttributeFilter,
Filter,
)

To work with runs instead of experiments, import the runs module:

from neptune_fetcher.alpha import runs

Setting the project and API token

Old
project = ReadOnlyProject(
project="team-alpha/project-x",
api_token="h0dHBzOi8aHR0cHM6...Y2MifQ==",
)
Alpha
project = Context(
project="team-alpha/project-x",
api_token="h0dHBzOi8aHR0cHM6...Y2MifQ==",
)
context = npt.set_context(project)
tip

With alpha, the context is set automatically from environment variables. Set the context manually only if you aren't using environment variables or you want to use a different context temporarily.

Listing experiments or runs of the project

Old
project = ReadOnlyProject()

for exp in project.list_experiments():
print(exp)

for run in project.list_runs():
print(run)
Alpha
npt.list_experiments()
runs.list_runs()
tip

With alpha, you can also list attribute names present in the project.

Fetching metadata as table

With alpha, you can use a filter object to set criteria for the experiments to search, or for the attributes to include as columns in the returned table.

Old
project.fetch_experiments_df()
Alpha
npt.fetch_experiments_table()

Match experiment names:

Old
project.fetch_experiments_df(
names_regex=r"exp.*"
)
Alpha
npt.fetch_experiments_table(r"exp.*")

Match run IDs:

Old
project.fetch_experiments_df(
custom_id_regex=r"run.*"
)
Alpha
runs.fetch_runs_table(r"run.*")

Filter by metadata value:

Old
project.fetch_experiments_df(
query="(last(`acc`:floatSeries) > 0.88)"
)
Alpha
npt.fetch_experiments_table(
experiments=Filter.gt("acc", 0.88)
)

Specify columns to include:

Old
project.fetch_experiments_df(
columns_regex=r"acc"
)
Alpha
npt.fetch_experiments_table(
attributes=r"acc"
)

Fetching metric values

With alpha, you can fetch metric values from multiple experiments or runs at once.

Old
# For each experiment or run
run = ReadOnlyRun(
ReadOnlyProject(...),
experiment_name="exp123",
)
run.prefetch(["loss"])
run["loss"].fetch_values()
Alpha
npt.fetch_metrics(
experiments=r"exp.*",
attributes=r"loss",
)

Fetching a config or single value

To fetch the f1 attribute value from a particular experiment:

Old
run = ReadOnlyRun(
ReadOnlyProject(...),
experiment_name="exp123",
)
value = run["f1"].fetch()
Alpha
name_filter = Filter.eq("sys/name", r"exp123")
f1_filter = AttributeFilter(name_eq="f1")
f1_value = npt.fetch_experiments_table(
experiments=precise_experiment,
attributes=f1,
).iat[0, 0]

Note that it might be more convenient to omit the filter objects and pass regex patterns directly to the experiments and attributes arguments. However, the above method shows how to use built-in methods to require the names to equal the specified strings exactly.