.. _notebook_exports: Notebook Backups and Exports ============================ Use :meth:`~labapi.tree.notebook.Notebook.backup` to save the native LabArchives response, or :meth:`~labapi.tree.notebook.Notebook.export` to write a readable directory tree. Download a Native Backup ------------------------ Write LabArchives' native backup archive to a local file: .. code-block:: python notebook.backup("my_notebook.7z") To leave attachments out of the archive, pass ``include_attachments=False``: .. code-block:: python notebook.backup("metadata_only.7z", include_attachments=False) Only the notebook owner can request a native backup. Error code ``4547`` means you are not authenticated as the owner; check ``Notebook Settings > Users`` in the LabArchives web UI and retry with the owner's credentials. Export a Directory Tree ----------------------- Export the whole notebook to a local destination: .. code-block:: python export = notebook.export("my_notebook") destination = export.path The destination contains numeric ordering prefixes, page content files, and a ``.labarchives.json`` manifest for every page. The manifest records the page and entry IDs, output filenames, entry types, and available attachment details. For example: .. code-block:: text my_notebook/ └── 1_Experiments/ └── 1_Run 1/ ├── 1_text.html ├── 2_results.csv └── .labarchives.json Empty directories are created, and empty pages still receive their manifest. If the destination already exists and is not empty, :meth:`~labapi.tree.notebook.Notebook.export` raises :class:`FileExistsError`. Pass ``overwrite=True`` to replace it. Choose an Export Source ----------------------- ``source="auto"`` is the default. It uses a native backup archive when available and otherwise walks the live API tree. To read native archives, install the ``export`` extra: .. code-block:: bash pip install "labapi[export]" Use ``source="backup"`` to require the native archive, or ``source="walk"`` to bypass it and read the live tree directly. A live walk is slow for large notebooks, because it takes many API requests to list and download pages and attachments. Related Pages ------------- - :ref:`installation` for optional dependency installation. - :ref:`limitations` for known API and entry-type constraints.