domino logo
Latest (5.7)
  • Get started
  • Tech ecosystem
  • Domino Cloud
  • Develop models
  • Work with data
  • Model governance
  • Deploy models, apps, launchers
  • Model Monitoring
  • Code Assist
  • Security and credentials
  • Organizations
  • Collaborate
  • Projects
  • Workspaces
  • Environments
  • Data planes
  • Executions
  • Additional Resources
  • Domino CLI
  • Troubleshooting
  • Get help
  • Send feedback
domino logo
About Domino
Domino Data LabKnowledge BaseData Science BlogTraining
>
User Guide
>
Code Assist
>
Snippets with Code Assist

Snippets with Code Assist

Code snippets are reusable bits of code that can be easily inserted into a notebook. Code snippets offer numerous benefits to developers, and can be used to:

  • automate repetitive tasks

  • save time

  • reduce errors

  • ensure consistent coding styles

The following sections will show you how to add, use, edit, and delete snippets in notebook workspaces.

Add and edit snippets

Code Assist looks for snippets in a snippets/ directory in the root of the repository or project. Any .py or .R files in this directory are loaded as snippets, and the sub-folder structure is maintained in the Snippets menu.

Here’s an example structure of the snippets/ folder:

snippets/
├── python
│   ├── general
│   │   └── sort-dictionary.py
│   └── models
│       ├── classification.py
│       └── regression.py
└── r
    ├── general
    │   └── list-to-data-frame.R
    └── markdown
        ├── letter.Rmd
        ├── proposal.Rmd
        └── report.Rmds

The following sections show the two ways to add new snippets:

  • Import from a Git repository

  • Manually add a snippet

Import snippets from a Git repository

A snippet library can be added by linking a Git repository with a snippets/ directory in its root to your Domino project.

Use standard Git workflows to edit snippets in your repository.

Manually add and edit snippets

You can also add snippets directly in a workspace.

Enable snippet edit mode by clicking the pencil icon in the context menu:

dca context menu edit

Enter the snippet code and click on SAVE AS SNIPPET.

Enter the name of the snippet and select the repository to store the snippet. Click the Add button.

To sync the snippet back to Git, open File Changes in the left-hand sidebar and click Select and sync on the Imported Repositories section.

Use snippets

Hover over the assistant icon icon to show a popup menu. Select the Insert snippet item from the menu.

dca context menu edit

Navigate through the folders until you find the snippet you’re looking for. Select a snippet to see its contents.

Click the RUN button to insert the snippet into the active cell.

snippets insert

Refresh snippets with git pull

When snippets are updated in a Git repository, you must pull in the changes to see the updates in your workspace.

  1. Click on pull in the Imported Repositories section.

    pull
  2. Click refresh to reload snippets.

    reload snippets

Delete snippets

Choose Insert snippet in the Code Assist menu.

Choose the snippet that you want to delete and click the DELETE button.

Domino Data Lab
Knowledge Base
Data Science Blog
Training
Copyright © 2022 Domino Data Lab. All rights reserved.