-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compared to V2: - support module_name as positional or named arg (-m/--module_name) - support -c/--config - support -h/--help - ignores -r/--rebuild-drivers - ignores -v/--verbose - richer support for -c/--config - alias %%insert_module to %%module_to_cell - creates a temporary file for the temporary modules to play nicely with Hamilton UI - in `incr_cell_to_module`, -i/--identifier is now a required positional argument - added try/except over dynamic module creation Others: - fixed dynamic module registration in ad_hoc_utils.create_module() which was causing a bug for function_modifiers.macros (e.g., @pipe) - updated existing examples/ notebooks --------- Co-authored-by: zilto <tjean@DESKTOP-V6JDCS2> Co-authored-by: Stefan Krawczyk <stefan@dagworks.io>
- Loading branch information
1 parent
f70af85
commit 831a093
Showing
6 changed files
with
2,344 additions
and
757 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,27 @@ | ||
# This example shows a notebook using the Hamilton Jupyter magic | ||
# Hamilton notebook extension | ||
|
||
One of the best part about notebooks is the ability to execute and immediately inspect results. They provide a "read-eval-print" loop (REPL) coding experience. However, the way Hamilton separates dataflow definition (functions in a module) from execution (building and executing a driver) creates an extra step that can slowdown this loop. | ||
|
||
We built the Hamilton notebook extension to tighten that loop and even give a better experience than the core notebook experience! | ||
|
||
To load the magic: | ||
```python | ||
# load some extensions / magic... | ||
%load_ext hamilton.plugins.jupyter_magic | ||
``` | ||
|
||
Then to use it: | ||
For example, this would allow you to define the module `joke` from your notebook | ||
|
||
```python | ||
%%cell_to_module -m MODULE_NAME # more args | ||
``` | ||
Other arguments (--help to print this.): | ||
-m, --module_name: Module name to provide. Default is jupyter_module. | ||
-c, --config: JSON config string, or variable name containing config to use. | ||
-r, --rebuild-drivers: Flag to rebuild drivers. | ||
-d, --display: Flag to visualize dataflow. | ||
-v, --verbosity: of standard output. 0 to hide. 1 is normal, default. | ||
%%cell_to_module joke --display | ||
def topic() -> str: | ||
return "Cowsay" | ||
|
||
Example use: | ||
def joke_prompt(topic: str) -> str: | ||
return f"Knock, knock. Who's there? {topic}" | ||
|
||
```python | ||
%%cell_to_module -m MODULE_NAME --display --rebuild-drivers | ||
def reply(joke_prompt: str) -> str: | ||
_, _, right = joke_prompt.partition("? ") | ||
return f"{right} who?" | ||
``` | ||
|
||
Go explore `tutorial.ipynb` to learn about all interactive features! |
Oops, something went wrong.