snippet()
Run a block and publish its code and printed output as a code snippet.
::
with fw.snippet("fit-ols"):
model = smf.ols("score ~ income", data=df).fit()
print(model.summary())
Usage
snippet(
label: str,
*,
output: bool = True,
folded: bool | None = None,
links: dict[str, str] | None = None,
repository: str | None = None,
publish: bool = True,
slug: str | None = None,
title: str | None = None,
description: str | None = None,
visibility: str | None = None,
password: str | None = None,
collection: str | int | None = None,
share_unlisted: bool = False,
to: str | None = None,
include_private: bool = False,
display: dict[str, bool] | None = None,
) -> Iterator[None]
Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| label required | str |
Names the snippet. The default slug and title come from it. |
|
| output | bool | True |
False publishes the code alone. |
| folded | bool | None | None |
True folds every output block, False unfolds them. Default: Framework Cloud folds output longer than 12 lines. |
| links | dict[str, str] | None | None |
Links shown with the snippet: |
| repository | str | None | None |
Repository URL to name, such as |
| publish | bool | True |
False records the block without publishing it. |
| slug | str | None | None |
Artifact slug. Default: from |
| title | str | None | None |
Artifact title. Default: |
| description | str | None | None |
Artifact description. |
| visibility | str | None | None |
"public", "unlisted", or "private". |
| password | str | None | None |
Password required to view the snippet. |
| collection | str | int | None | None |
Project collection ID or slug. |
| share_unlisted | bool | False |
Allow collection readers to see an unlisted snippet. |
| to | str | None | None |
A configured destination name, or "cloud". |
| include_private | bool | False |
Publish without asking about private folders. |
| display | dict[str, bool] | None | None |
What embeds of the snippet show, on Framework Cloud: |
Details
The block runs as usual and its output still prints. When it ends, the block's code and what it printed to stdout (as output) and stderr (as messages) are published to Framework Cloud as a code snippet. A script shows no expression values, so none are recorded. If the block raises, the snippet ends with the traceback, is published, and the exception continues.
The code comes from the source file, so with fw.snippet() needs a script
or a module, not the interactive prompt. In Jupyter, use the %%fw_snippet
cell magic instead (%load_ext framework).
The snippet names its source: the file's path from the git repository's top
(or the project root), the label, the block's lines, and the commit checked
out. The repository URL is sent only when repository is given or
publish.repository is set in settings.yml. Framework Cloud builds a GitHub
permalink from a GitHub repository, the commit, the file, and the lines.