> ## Documentation Index
> Fetch the complete documentation index at: https://anaconda.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Code Snippets

Code Snippets enable you to securely upload reusable blocks of code to Anaconda's cloud storage. You can then provide access to other users, as well as import your code snippets to separate workbooks to repeat your efforts from any machine, anytime.

## Understanding connections

Let's take a look at the different elements within Code Snippets.

<Frame>
  <img src="https://mintcdn.com/anaconda-29683c67/3yNXdf8uBXJiT_qs/images/snippets_anatomy.png?fit=max&auto=format&n=3yNXdf8uBXJiT_qs&q=85&s=af0ef0dce219c126230b2d603399718f" alt="" style={{ width: "400px" }} width="534" height="800" data-path="images/snippets_anatomy.png" />
</Frame>

<Steps>
  <Step title="New Project">
    Create a new project to store and share snippets
  </Step>

  <Step title="New Snippet">
    Create and store a new snippet in Anaconda's cloud storage
  </Step>

  <Step title="Filters">
    Apply filters to efficiently locate snippets in your catalog
  </Step>

  <Step title="My Snippets">
    A collection of all your cloud projects and their nested snippets
  </Step>

  <Step title="User Snippets">
    Projects to which you have access, owned by other individuals
  </Step>

  <Step title="Organization Snippets">
    Projects to which you have access, owned by organizations
  </Step>

  <Step title="Project actions">
    Edit, delete, and [share projects](#sharing-a-snippet)
  </Step>

  <Step title="Snippet actions">
    Edit and delete snippets
  </Step>

  <Step title="Running snippets">
    Multiple methods for [adding and running snippets in a workbook](#adding-snippets-to-a-workbook)
  </Step>
</Steps>

## Create a project

When you first access Code Snippets, you are prompted to create a new project. You can think of projects as folders for storing your snippets.

You must create a project before uploading your first snippet. Create a project at any time using the following steps:

1. Click **+ New Project**.

2. Enter a unique title for your project and an optional description.

3. Designate the project owner(s) for your project. By default, you are set as the only project owner.

   <Note>
     Administrators and project owners are the only users allowed to edit projects. Anaconda.com organization administrators have full permissions for any projects owned by their organization.
   </Note>

4. (Optional) Provide access to your project by inviting users from one of your organizations.

5. Click **Save**.

## Sharing a snippet

You can share a snippet with others in your organization by sharing the project containing that snippet. This can be done as you're creating a new project or at any time using the following steps:

1. Click actions beside a project for which you have edit permissions, then click <Icon icon="pencil" iconType="light" /> **Edit**.
2. Provide access to your project by inviting users from one of your [organizations](https://anaconda.com/app/profile/organizations).

   1. Under **Your Organizations**, select an organization.
   2. Under **Organization Users**, select a user to share your project with.
   3. Choose whether the user should have read or write access to your project.
3. Click **Save**.

## Uploading a snippet

With a project in Anaconda's cloud storage, you can now create a snippet and upload it to that project. This can be done from Code Snippets or, if you want to save code generated while creating visualizations of your data, you can upload a snippet from [Visualize with Python](./visualize).

<Tabs>
  <Tab title="Upload from Code Snippets">
    1. Click **+ New Snippet**.
    2. Under **Project**, select an existing project to house your snippet.
    3. Under **Snippet Title**, provide a title for your snippet.
    4. Select a language, then enter your code in the code editor. Alternatively, click **+ Add From Grid** to add existing code from your workbook.
    5. Click **Save to Cloud**.

    Your snippet appears in its assigned project folder.
  </Tab>

  <Tab title="Upload from Visualize with Python">
    When working in Visualize with Python, Anaconda Toolbox writes code to render your data as a visualization. You can then open this code in Code Snippets to edit and save to Anaconda's cloud storage using the following steps:

    1. From the Toolbox home screen, open **Visualize with Python**.

    2. Click **New Chart**, then select a chart type.

    3. Select the source range and adjust the chart settings from the **Setup** tab, customize the chart from the **Design** tab, and then open the **Code** tab.

    4. Click <Icon icon="rectangle-code" iconType="regular" /> **Save as code snippet** to open the code in Code Snippets.

           <Frame>
             <img src="https://mintcdn.com/anaconda-29683c67/3yNXdf8uBXJiT_qs/images/snippets_visualize.png?fit=max&auto=format&n=3yNXdf8uBXJiT_qs&q=85&s=e8179d569f0d935eb8340dae2c15478c" alt="" style={{ width: "400px" }} width="535" height="800" data-path="images/snippets_visualize.png" />
           </Frame>

    5. Select a project to upload the snippet to, then provide a title.

    6. If needed, edit the code to suit multiple use cases by converting labels to variables, parameterizing functions, and so on.

    7. Click **Save to Cloud**.

    Your snippet appears in its assigned project folder.
  </Tab>
</Tabs>

## Adding snippets to a workbook

When you're ready to make use of your saved snippets, import them to a workbook using the following steps:

1. Expand the <Icon icon="chevron-down" iconType="regular" /> dropdown beside your snippet. A preview of your snippet appears.

   <Frame>
     <img src="https://mintcdn.com/anaconda-29683c67/3yNXdf8uBXJiT_qs/images/snippets_add.png?fit=max&auto=format&n=3yNXdf8uBXJiT_qs&q=85&s=933f4857a332ff0090ebb9f401e88864" alt="" style={{ width: "400px" }} width="535" height="800" data-path="images/snippets_add.png" />
   </Frame>

2. You can now import your snippet in one of two ways:

<Tabs>
  <Tab title="Run in cell">
    1) Click <Icon icon="play" iconType="regular" /> **Run in cell**.
    2) Select the cell where you want to insert the snippet, then click **OK**.
  </Tab>

  <Tab title="Copy code">
    1. Click <Icon icon="copy" iconType="regular" /> **Copy** to copy the snippet to your clipboard.
    2. In an open cell, type `=PY`, press Tab, and then paste your snippet in the green PY formula bar.
    3. Use Ctrl+Enter (Windows)/Ctrl+Return (Mac) to run the code.
  </Tab>
</Tabs>

## Editing a snippet

Changes made to a saved snippet in a workbook will not automatically update that snippet in Anaconda's cloud storage. Instead, you must make changes to the snippet directly within the Anaconda Toolbox extension.

1. Expand the <Icon icon="chevron-down" iconType="regular" /> dropdown beside your snippet. A preview of your snippet appears.

2. Click <Icon icon="pencil" iconType="light" /> **Edit**.

   <Frame>
     <img src="https://mintcdn.com/anaconda-29683c67/3yNXdf8uBXJiT_qs/images/snippets_edit.png?fit=max&auto=format&n=3yNXdf8uBXJiT_qs&q=85&s=996e2fefee2a252ecb9014100ecca0cc" alt="" style={{ width: "400px" }} width="535" height="800" data-path="images/snippets_edit.png" />
   </Frame>

3. Adjust your snippet, then click **Save to Cloud**.

   <Note>
     Changing the title of your snippet will create a new snippet, rather than updating the existing one.
   </Note>
