Skip to main content
A VFS is a class that extends BaseVFS. Override readdir, stat and read, and ls, cat, grep, find and the other read commands work on your service. Every other method is optional: override one, and the commands that need it start working, or answer with fewer requests.

The base class

The methods you can override, with the arguments you normally use:

How to integrate your service

Required

Write

Writes need a writable mount: MountMode.WRITE, or mode: write in YAML.

Answer commands with your service

Override these to answer from your service’s own search, query or metadata API instead of reading files. Each links to its guide.

Attributes

Set them as class attributes or pass them to super().__init__() (super({...}) in TypeScript).

Example: a read-only VFS

This VFS serves pages from a dictionary:
notes.py
Mount it like any other VFS:
cat /notes/hello.txt then prints hello mirage, and grep -rn mirage /notes reads every page. In YAML, vfs names the class as file:Class, relative to the YAML file, and config is what its constructor gets; the TypeScript server takes ./notes.ts:NotesVFS. To name it vfs: notes instead, register it with register_vfs in Python or registerVfs in TypeScript.

Example: make it writable

Override write and unlink:
On a writable mount, echo hi > /notes/new.txt, sed -i and rm now work, and >> reads the page and writes it back. mv still answers Operation not supported until you override rename. Override files_containing to name the files that may contain the text:
grep -rn mirage /notes now reads only the pages this returns, and Mirage still checks each line, so the output is the same. The dictionary stands in for your service’s search API. mounted_path turns a name inside the mount into a path. grep -ri gets None here, so it reads every page. For a real one, see Chroma, the search behind a RAG knowledge base: its files_containing asks Chroma for the chunks whose text contains the word ($contains) and returns their pages, and it also returns None for -i. Source: Python, TypeScript.

Example: count lines without reading

Override line_count:
wc -l /notes/hello.txt now answers without reading the page. For a database, this is where a count(*) query goes. Plain wc still reads the page, since it also counts words and bytes.

Next

The Python and TypeScript guides add folders, snapshots, packaging and contributing a VFS to Mirage.