Getting started

SFS can be accessed directly from Python. It allows you to copy files to and from the workspace.

At the start of a project import the SFS library:

In [1]:
import sherlockml.filesystem as sfs

List Files

You can list all the files in your project’s SFS directory with:

In [2]:
sfs.ls()
Out[2]:
['/input/',
 '/input/client-data.csv',
 '/input/extra/',
 '/input/extra/file1.txt',
 '/input/extra/file2.txt',
 '/input/extra/file3.txt',
 '/input/extra/file4.txt',
 '/output/']

To see a subset of files, just provide a prefix:

In [3]:
sfs.ls('/input/extra')
Out[3]:
['/input/extra/',
 '/input/extra/file1.txt',
 '/input/extra/file2.txt',
 '/input/extra/file3.txt',
 '/input/extra/file4.txt']

Get Files

Get particular files from SFS into your workspace with the get function:

In [4]:
sfs.get('/input/client-data.csv', 'client-data.csv')
with open('client-data.csv') as f:
    print(f.read())
name,email,age
"Jane Smith",jane.smith@example.com,32
"John White",john.white@example.com,28

You can also get whole directories:

In [5]:
sfs.get('/input/extra', 'extra')

import os
os.listdir('extra')
Out[5]:
['file1.txt', 'file4.txt', 'file2.txt', 'file3.txt']

Put Files

We can go in reverse and put a file from the workspace into SFS with the put function:

In [6]:
sfs.put('results.csv', '/output/results.csv')
sfs.ls()
Out[6]:
['/input/',
 '/input/client-data.csv',
 '/input/extra/',
 '/input/extra/file1.txt',
 '/input/extra/file2.txt',
 '/input/extra/file3.txt',
 '/input/extra/file4.txt',
 '/output/',
 '/output/results.csv']

Again, this works with whole directories:

In [7]:
sfs.put('figures', '/output/figures')
sfs.ls()
Out[7]:
['/input/',
 '/input/client-data.csv',
 '/input/extra/',
 '/input/extra/file1.txt',
 '/input/extra/file2.txt',
 '/input/extra/file3.txt',
 '/input/extra/file4.txt',
 '/output/',
 '/output/figures/',
 '/output/figures/plot.png',
 '/output/figures/regression.png',
 '/output/results.csv']