Skip to content

feat: add ipython autocomplete support for MetaflowObject instances#1348

Merged
romain-intel merged 1 commit into
Netflix:masterfrom
bsridatta:ipython-auto-complete-for-metaflow-objects
Apr 12, 2023
Merged

feat: add ipython autocomplete support for MetaflowObject instances#1348
romain-intel merged 1 commit into
Netflix:masterfrom
bsridatta:ipython-auto-complete-for-metaflow-objects

Conversation

@bsridatta
Copy link
Copy Markdown
Contributor

@bsridatta bsridatta commented Apr 6, 2023

relates to #1114

The autocomplete for objects works with this simple addition of returning children ids. Suggestions when initiating classes like Flow(" could be helpful too but I couldn't find a way to do this. But for the class instances of Flow, Run, Step, Task, the autocomplete works and for reference the options are printed by calling the function that ipython would use.

Any thoughts @romain-intel ?

from metaflow import Flow, Metaflow

Metaflow().flows
>>> [Flow('HelloFlow'), Flow('MovieStatsFlow')]

flow = Flow('HelloFlow') # No autocomplete here
flow._ipython_key_completions_()
>>> 
['1680815181013681',
 '1680815178214737',
 '1680432265121345',
 '1680430310127401']

run = flow["1680815178214737"]
run._ipython_key_completions_()
>>> ['end', 'hello', 'start']

step = run["hello"]
step._ipython_key_completions_()
>>> ['2']

task = step["2"]
task._ipython_key_completions_()
>>> ['name']

data = task["name"]
data._ipython_key_completions_()
>>> Error (since no childern), so autcomplete just list unrelated things

Copy link
Copy Markdown
Collaborator

@savingoyal savingoyal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! @romain-intel any thoughts here?

@romain-intel
Copy link
Copy Markdown
Contributor

This looks great. I did do some research about adding in constructor but yes, it's not straightforward so we can merge this. Thanks for the contribution.

@romain-intel romain-intel merged commit 74247ed into Netflix:master Apr 12, 2023
talsperre added a commit that referenced this pull request May 31, 2026
#3071)

## PR Type

- [ ] Bug fix
- [x] New feature
- [ ] Core Runtime change
- [ ] Docs / tooling
- [ ] Refactoring

## Summary

Adds IPython tab-completion support for the `Metaflow` class
(`Metaflow()['<TAB>']` suggests flow names) and the `MetaflowData` class
(`task.data.<TAB>` suggests artifact names). This closes the remaining
gaps from issue #1114 after PR #1348 added completions to
`MetaflowObject`.

## Issue

Fixes #1114

## Tests

- [ ] Unit tests added/updated
- [ ] Reproduction script provided
- [ ] CI passes
- [x] If tests are impractical: The changes are two small method
additions (`_ipython_key_completions_` and `__dir__`) that follow the
exact same pattern already merged in PR #1348. They can be verified
interactively in a Jupyter notebook.

## Non-Goals

Does not add completions for other Metaflow objects since those were
already handled by PR #1348.

## AI Tool Usage

- [ ] No AI tools were used in this contribution
- [x] AI tools were used (describe below)

Claude Sonnet 4.6 was used to explore and help me understand the
codebase and identify the gaps.

Co-authored-by: Shashank Srikanth <s.shashank2401@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants