0
votes

I'm looking to use the %storage magic in a Datalab notebook, but within a function. The line looks like:

%storage write --variable df --object $bucket_object

and when calling the function I get this error:

Undefined variable referenced in command line: $bucket_object

bucket_object is defined previously in the function, and this works when running outside a function.

This answer regarding a similar question for iPython recommends finding the path and then importing like:

from IPython.core.magics.display import Javascript

Is there a similar approach to call a Datalab magic's respective function so that it would work within another function?

1

1 Answers

3
votes

The %storage and other similar commands are mostly syntactic sugar over underlying APIs.

For example, in this case google.datalab.storage APIs. Documentation is at http://googledatalab.github.io/pydatalab/google.datalab.storage.html

Something like this might work:

import google.datalab.storage as storage

bucket = storage.Bucket(bucket_name)
obj = bucket.object(object_key)
obj.write_stream(data, content_type)

Hope that helps.