The metadata API#

We already learned how to display metadata to provide humans with context (e.g., Basic metadata).

If we want to build functionality on top of notebook metadata, we can access metadata through the API.

from nbproject import header, meta
import pandas as pd

time_init2022-06-29 14:38
time_run2023-05-30 10:47
pypackagenbproject==0.8.6 pandas==2.0.2

If you’d like a simple dictionary and intialization state, call:

({'id': 'k6Bj4FXM9oPm',
  'time_init': '2022-06-29T14:38:42.171771+00:00',
  'version': '0'},

For instance, we can retrieve the stored notebook ID as follows.

assert not
🔶 Cells [(2, 4), (9, 11)] were not run consecutively.
Hide code cell content
assert == "k6Bj4FXM9oPm"
assert hasattr(, "time_init")

Manually add pypackages to["pytest"])
Wrapper object for the stored metadata:
  id='k6Bj4FXM9oPm' version='0' time_init='2022-06-29T14:38:42.171771+00:00' pypackage={'pytest': '7.3.1'} parent=None user_handle=None user_id=None user_name=None
{'pytest': '7.3.1'}
'The metadata API'
# assert  # it'd be nice to test this here, but that would require flushing the ci buffer before this cell
{'pandas': '2.0.2', 'nbproject': '0.8.6'}
Fields: consecutive_cells pypackage time_passed time_run title user_handle user_id user_name