Working with the file system

The Workspaces file system

The files shown in the left-hand pane of the Workspaces environment represent the contents of your Workspace directory, which is the notebook’s working directory.

To view the full path, run pwd or the following command:

import os
print(os.getcwd())
Copy

This prints a path in the following format:

/workspace/<workspace_hash representing your workspace>
Copy

Listing files using ls displays notebook files along with any folders or project assets stored in the Workspace directory.

Limitations

Although the Workspaces directory is read/write, file persistence is limited:

  • Files created in code or from the terminal exist only for the duration of the current notebook service session. When the notebook service is suspended, these files are removed. During the session, you will see these files if you list the directory (using ls) under /workspace/<workspace_hash>, but they do not persist after the session ends.

  • Only files that are uploaded or created in Snowsight persist across sessions.

  • Files created from code or the terminal do not appear in the left-hand pane. This is a temporary limitation. Contact your account team for more information.

The /tmp directory of the container

The /tmp directory is also read/write and is suitable for scratch work or temporary data that does not need to persist.

An example of writing a file to /tmp:

file_path = "/tmp/sample.txt"

with open(file_path, "w") as f:
    f.write("Hello from Python!\\nThis is a sample file saved in /tmp.")

print(f"File written to {file_path}")
Copy

To list files in the /tmp directory, run the following:

%%bash
cd /tmp
ls
Copy

Persisting files

To store files for later use, write them to a Snowflake stage with write access using Snowpark file operation APIs.

To learn more about required stage privileges, see write access. For Snowpark file operations, see Snowpark file operation APIs.

Language: English