Publish data and metadata to all frontends. See the ``display_data`` message in the messaging documentation for more details about this message type. The following MIME types are currently implemented: * text/plain * text/html * text/markdown
(self, data, metadata=None, source=None, *, transient=None, update=False, **kwargs)
| 59 | |
| 60 | # use * to indicate transient, update are keyword-only |
| 61 | def publish(self, data, metadata=None, source=None, *, transient=None, update=False, **kwargs) -> None: |
| 62 | """Publish data and metadata to all frontends. |
| 63 | |
| 64 | See the ``display_data`` message in the messaging documentation for |
| 65 | more details about this message type. |
| 66 | |
| 67 | The following MIME types are currently implemented: |
| 68 | |
| 69 | * text/plain |
| 70 | * text/html |
| 71 | * text/markdown |
| 72 | * text/latex |
| 73 | * application/json |
| 74 | * application/javascript |
| 75 | * image/png |
| 76 | * image/jpeg |
| 77 | * image/svg+xml |
| 78 | |
| 79 | Parameters |
| 80 | ---------- |
| 81 | data : dict |
| 82 | A dictionary having keys that are valid MIME types (like |
| 83 | 'text/plain' or 'image/svg+xml') and values that are the data for |
| 84 | that MIME type. The data itself must be a JSON'able data |
| 85 | structure. Minimally all data should have the 'text/plain' data, |
| 86 | which can be displayed by all frontends. If more than the plain |
| 87 | text is given, it is up to the frontend to decide which |
| 88 | representation to use. |
| 89 | metadata : dict |
| 90 | A dictionary for metadata related to the data. This can contain |
| 91 | arbitrary key, value pairs that frontends can use to interpret |
| 92 | the data. Metadata specific to each mime-type can be specified |
| 93 | in the metadata dict with the same mime-type keys as |
| 94 | the data itself. |
| 95 | source : str, deprecated |
| 96 | Unused. |
| 97 | transient: dict, keyword-only |
| 98 | A dictionary for transient data. |
| 99 | Data in this dictionary should not be persisted as part of saving this output. |
| 100 | Examples include 'display_id'. |
| 101 | update: bool, keyword-only, default: False |
| 102 | If True, only update existing outputs with the same display_id, |
| 103 | rather than creating a new output. |
| 104 | """ |
| 105 | |
| 106 | handlers = {} |
| 107 | if self.shell is not None: |
| 108 | handlers = getattr(self.shell, 'mime_renderers', {}) |
| 109 | |
| 110 | for mime, handler in handlers.items(): |
| 111 | if mime in data: |
| 112 | handler(data[mime], metadata.get(mime, None)) |
| 113 | return |
| 114 | |
| 115 | if 'text/plain' in data: |
| 116 | print(data['text/plain']) |
| 117 | |
| 118 | def clear_output(self, wait=False): |
no outgoing calls
no test coverage detected