> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mirage.strukto.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# OneNote in Python

> Virtualize OneNote notebooks from Python.

`OneNoteVFS` mounts OneNote notebooks read only through Microsoft Graph:
each notebook, section group and section becomes a folder, and each page
the HTML OneNote renders for it. Set up a token as in
[OneNote setup](https://docs.mirage.strukto.ai/home/setup/onenote.md).

## Install

```bash theme={null}
pip install mirage-ai
```

## Configure

```python theme={null}
import os

from mirage import MountMode, Workspace
from mirage.vfs.onenote import OneNoteConfig, OneNoteVFS

config = OneNoteConfig(access_token=os.environ["MS_GRAPH_NOTES_TOKEN"])
ws = Workspace({"/onenote": OneNoteVFS(config)}, mode=MountMode.READ)

result = await ws.shell("ls /onenote && grep -rl 'checks row' /onenote")
print(await result.stdout_str())
await ws.close()
```

With no `user_id`, the mount is the signed-in user's notebooks (`/me`).

### Fields

**access\_token** `str | callable` *required*

Microsoft Graph bearer token, or a callable that returns one; it is called for each request and again after a `401`.

**graph\_base\_url** `str`

Full Graph service root, version segment included, for a private endpoint or a test server; Microsoft serves the OneNote API only in the worldwide cloud. Unset uses `https://graph.microsoft.com/v1.0`.

**timeout** `float` (default: 30)

Seconds a Graph request may wait to connect, or between two reads of its answer, before it fails; also how long a server-side copy is polled before it fails as unconfirmed.

**max\_retries** `int` (default: 5)

Times a request is retried after a `429`, `503` or `504` response. Each retry waits what `Retry-After` asks or an exponential backoff, at most 30 seconds.

**user\_id** `str`

User ID or UPN whose notebooks the mount reads, ones the signed-in user may open; unset reads the signed-in user's.

Fields marked secret are redacted in snapshots.

## Authentication

`access_token` is a Microsoft Graph bearer token, or a callable that returns
one. A callable is called for each request and again after a `401`, so a
long-running mount outlives one token; a plain string lasts about an hour.

The token is delegated: OneNote's Graph API refuses app-only tokens since
March 31, 2025. With `Notes.Read` it reads the signed-in user's notebooks.
`user_id` names another user, by id or UPN, whose notebooks the signed-in
user may open, which takes `Notes.Read.All`.

## Layout

```text theme={null}
/onenote/
  Research Desk/
    Standards/
      Build_Conventions__0-9f6d26e0e2b14271!1-816F7725BFE7F3F8!1124.html
      Naming__0-9f6d26e0e2b14271!1-816F7725BFE7F3F8!1131.html
    Archive/
      Q4/
        Close/
          Close_checklist__0-4ab0a1c3d2e94f10!1-816F7725BFE7F3F8!1210.html
  Project Falcon/
    Open Items/
      Open_items__0-6c1e5d7b8a2f4c03!1-816F7725BFE7F3F8!1302.html
```

* A notebook, a section group and a section are each a folder named by its
  display name, with `/` shown as `∕`. A section group nests inside its
  notebook or another group, to any depth.
* A name two siblings share (a section and a section group may) carries the
  later one's `__<id>`, and so does a folder named like a page file.
* A page file is named `<title>__<page-id>.html`, the title sanitized and cut
  short when needed, and `Untitled_Page` when it has none. `ls` the section
  rather than build the name.
* A section lists its pages flat: a subpage sits beside its parent.

## Behavior

* **Read only:** no command changes a notebook.
* **OneNote's HTML:** a page file is the page as Microsoft Graph renders it
  (`GET /pages/{id}/content`): a `<title>`, the creation time in
  `<meta name="created">`, then the page's paragraphs, headings, lists,
  tables and links. A to-do item carries `data-tag="to-do"`, and
  `data-tag="to-do:completed"` once ticked. An image points at Graph's
  resource URL, which needs the token to open.
* **Listings:** the root asks for every notebook with the sections and
  section groups directly inside it, so entering a notebook costs no request;
  a section group asks for its own the same way, and a section lists its
  pages a hundred at a time.
* **Sizes and dates:** a page is listed with no size, since Graph names one
  only once the HTML is fetched; `cat` and `wc` read it. A page is dated when
  last modified, a folder likewise.
* **Service root:** mounts address `https://graph.microsoft.com/v1.0` unless
  `graph_base_url` names another root, given in full with its version
  segment.

## VFS.md

The [VFS.md](https://docs.mirage.strukto.ai/home/setup/vfs-md.md) an agent reads with OneNote mounted at
`/<path>`.

> [tab] Rendered
>
> **Virtual Filesystem**
>
> | Path | Description |
> | - | - |
> | `/<path>` | `onenote`, read |
>
> **VFS Layout**
>
> **`/<path>`**
>
> ```text theme={null}
> /<path>
>   <notebook>/                    # a notebook, by its name
>     <section>/
>       <title>__<page-id>.html    # a page, as OneNote renders it
>     <section group>/             # nested to any depth
>       <section>/
>         <title>__<page-id>.html
> ```
>
> * `<notebook>`, `<section group>` and `<section>` are display names.
>   When two siblings share a name, the later one carries `__<id>`, as
>   does a name shaped like a page file (`<title>__<page-id>.html`).
> * A page file is the HTML OneNote answers for the page: its `<title>`,
>   its creation time in `<meta name="created">`, then its paragraphs,
>   headings, lists, tables and links. A to-do item carries
>   `data-tag="to-do"`, and `data-tag="to-do:completed"` once ticked.
> * A section lists its pages flat, subpages beside their parent.
> * `ls` a section for the names rather than building `<title>`; `grep -r`
>   reads every page below a directory.
> * The mount is read-only.
>
> **Supported Unix Commands for VFS**
>
> Unix commands work on each path as on a local filesystem, as far as the path supports them:
>
> | Path | Supported |
> | - | - |
> | `/<path>` | Commands that read files (`ls`, `cat`, `grep`, `find`, `jq` and the rest). |
>
> **Limitations of Unix Commands for VFS**
>
> Where a path differs from a local filesystem:
>
> | Path | Limitations |
> | - | - |
> | `/<path>` | Read only: no command changes files. `grep -r`, `find` and `du` stop after 1000 files; a glob matching more, `tar -c`, `cp -r` and `rm -r` are refused. |
>
> Run `man <cmd>` or `<cmd> --help` for one command's usage.

> [tab] Raw
>
> ````markdown theme={null}
> ---
> name: workspace-filesystem
> description: The virtual filesystem layout of this workspace.
> ---
>
> # Virtual Filesystem
>
> | Path | Description |
> | --- | --- |
> | `/<path>` | `onenote`, read |
>
> ## VFS Layout
>
> ### `/<path>`
>
> ```text
> /<path>
>   <notebook>/                    # a notebook, by its name
>     <section>/
>       <title>__<page-id>.html    # a page, as OneNote renders it
>     <section group>/             # nested to any depth
>       <section>/
>         <title>__<page-id>.html
> ```
>
> - `<notebook>`, `<section group>` and `<section>` are display names.
>   When two siblings share a name, the later one carries `__<id>`, as
>   does a name shaped like a page file (`<title>__<page-id>.html`).
> - A page file is the HTML OneNote answers for the page: its `<title>`,
>   its creation time in `<meta name="created">`, then its paragraphs,
>   headings, lists, tables and links. A to-do item carries
>   `data-tag="to-do"`, and `data-tag="to-do:completed"` once ticked.
> - A section lists its pages flat, subpages beside their parent.
> - `ls` a section for the names rather than building `<title>`; `grep -r`
>   reads every page below a directory.
> - The mount is read-only.
>
> ## Supported Unix Commands for VFS
>
> Unix commands work on each path as on a local filesystem, as far as the path supports them:
>
> | Path | Supported |
> | --- | --- |
> | `/<path>` | Commands that read files (`ls`, `cat`, `grep`, `find`, `jq` and the rest). |
>
> ## Limitations of Unix Commands for VFS
>
> Where a path differs from a local filesystem:
>
> | Path | Limitations |
> | --- | --- |
> | `/<path>` | Read only: no command changes files. `grep -r`, `find` and `du` stop after 1000 files; a glob matching more, `tar -c`, `cp -r` and `rm -r` are refused. |
>
> Run `man <cmd>` or `<cmd> --help` for one command's usage.
> ````


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.