For more information on accessing existing packages see the section "Installing a Package".
Adding data to a package
Use the set and set_dir commands to add individual files and whole directories, respectively, to a Package:
The first parameter to these functions is the logical key, which will determine where the file lives within the package. So after running the commands above our package will look like this:
The second parameter is the physical key, which states the file's actual location. The physical key may point to either a local file or a remote object (with an s3:// path).
If the physical key and the logical key are the same, you may omit the second argument:
Another useful trick. Use "." to set the contents of the package to that of the current directory:
Deleting data in a package
Use delete to remove entries from a package:
Note that this will only remove this piece of data from the package. It will not delete the actual data itself.
Adding metadata to a package
Packages support metadata anywhere in the package. To set metadata on package entries or directories, use the meta argument:
You can also set metadata on the package as a whole using set_meta.
# add entries individually using `set`
# ie p.set("foo.csv", "/local/path/foo.csv"),
# p.set("bar.csv", "s3://bucket/path/bar.csv")
# create test data
with open("data.csv", "w") as f:
f.write("id, value\na, 42")
p = quilt3.Package()
p.set("data.csv", "data.csv")
p.set("banner.png", "s3://quilt-example/imgs/banner.png")
# or grab everything in a directory at once using `set_dir`
# ie p.set_dir("stuff/", "/path/to/stuff/"),
# p.set_dir("things/", "s3://path/to/things/")
# create test directory
import os
os.mkdir("data")
p.set_dir("stuff/", "./data/")
p.set_dir("imgs/", "s3://quilt-example/imgs/")
# assuming data.csv is in the current directory
p = quilt3.Package()
p.set("data.csv")
(local Package)
└─data.csv
# switch to a test directory and create some test files
import os
%cd data/
os.mkdir("stuff")
with open("new_data.csv", "w") as f:
f.write("id, value\na, 42")
# set the contents of the package to that of the current directory
p.set_dir(".", ".")