First we need to import the library and configure an endpoint. The endpoint "sciencedata" is mapped by the pod to the private IP address of your ScienceData home silo. You can access it w/o username/password.
from sddk import cloudSession
s = cloudSession("sciencedata")
from IPython.display import Image, display
Create some objects.
### Python "str" object
string_object = "string content"
### Python "list" object
list_object = ['a', 'b', 'c', 'd']
### Python "dictionary" object
dict_object = {"a" : 1, "b" : 2, "c":3 }
### Pandas dataframe object
import pandas as pd
dataframe_object = pd.DataFrame([("a1", "b1", "c1"), ("a2", "b2", "c2")], columns=["a", "b", "c"])
### Matplotlib figure object
import matplotlib.pyplot as plt
figure_object = plt.figure() # generate object
plt.plot(range(10)) # fill it by plotted values
Write the objects to a directory, tmp
, on ScienceData. Replace tmp
with an existing directory or go create tmp
.
s.write_file("tmp/test_string.txt", string_object)
s.write_file("tmp/test_list.json", list_object)
s.write_file("tmp/test_dict.json", dict_object)
s.write_file("tmp/test_dataframe.json", dataframe_object)
s.write_file("tmp/test_figure.png", figure_object)
Read back the objects from ScienceData.
string_object = s.read_file("tmp/test_string.txt", "str")
string_object
dataframe_object = s.read_file("tmp/test_dataframe.json")
dataframe_object
figure_object = s.read_file("tmp/test_figure.png")
display(Image(figure_object))
Using the hostname sciencedata
w/o providing username/password is convenient and secure - traffic to/from ScienceData proceeds over a private, trusted network. Unfortunately it can also be slow. The transfer speed is not slow, but the authentication process is. This is because your username / access rights need to be inferred from the IP address of your pod, neccessitating a few lookups on every request. Some caching is done, but in general, it's rather heavy.
You can instead provide your username/password. This will greatly speed up things, but be careful not to write the password into your notebook. Instead, simply provide your username to sddk
and you'll be queried for your password.
ss = cloudSession("sciencedata", None, None, None, "some_user")
ss.read_file("tmp/test_string.txt", "str")
Yup - much faster.
sss = cloudSession("sciencedata", "delemappe", "test3", None, "some_user")
sss.write_file("test_string.txt", string_object)
sss.read_file("test_string.txt", "str")