[IPython-dev] magics and metadata

Jonathan Taylor jonathan.taylor at stanford.edu
Tue Jun 19 11:08:51 EDT 2012

Yes, it would not be good to have the API of cell magics be notebook
specific. What about providing a reference to the current cell metadata in
the Magics class that can be used to update the NotebookNode after
executing cell.input? So, cell_magics would not have access to the metadata
on execution but could pass any metadata it wanted to back to the notebook.

This is already sort of possible if you're willing to go through the
outputs of the cell on the frontend by a hack along the lines of

metadata["type"] = "cell_metadata"
publish_display_data("cell_metadata", {"application/json":metadata)

Followed by (on the front end)

for output in cell.outputs:
    if (output.json is not None and "type" in output.json and
output.json['type'] == "cell_metadata"):

This will obviously have a problem if metadata had a key called "type" but
maybe its logic could be encapsulated into an "update_cell_metadata"

On Tue, Jun 19, 2012 at 2:48 AM, Thomas Kluyver <takowl at gmail.com> wrote:

> On 19 June 2012 09:18, Jonathan Taylor <jonathan.taylor at stanford.edu>
> wrote:
> > With the addition of cell-level metadata in cells in ipython/master it
> would
> > be nice to be able to easily add metadata to cells, say, through a cell
> > magic?
> I agree that there are reasons why the user might want to alter the
> metadata, but I don't think cell magics are the way to do it. Cell
> magics are run in the kernel, which doesn't know about the frontend.
> And you can use cell magics in the qt console or the terminal, so
> their API can't be notebook specific.
> Thomas
> _______________________________________________
> IPython-dev mailing list
> IPython-dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev

Jonathan Taylor
Dept. of Statistics
Sequoia Hall, 137
390 Serra Mall
Stanford, CA 94305
Tel:   650.723.9230
Fax:   650.725.8977
Web: http://www-stat.stanford.edu/~jtaylo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20120619/4e0c2fd8/attachment.html>

More information about the IPython-dev mailing list