> For the complete documentation index, see [llms.txt](https://docs.redivis.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.redivis.com/api/client-libraries/redivis-python/reference/directory.md).

# Directory

## *class* <mark style="color:purple;">Directory</mark>

Any table or query result on Redivis that contains file ids can be read as a directory, where the file names are parsed according to any `/` separators, and a directory tree is created.&#x20;

This virtual directory can then be used to navigate, download, and even mount a given file tree.

## Constructors

<table data-header-hidden><thead><tr><th width="319">Method</th><th>Description</th></tr></thead><tbody><tr><td><a href="/api/client-libraries/redivis-python/reference/directory/directory.get.md"><strong><code>Directory.get</code></strong></a>(path)</td><td>Returns a subdirectory within a directory.</td></tr><tr><td><a href="/api/client-libraries/redivis-python/reference/table/table.to_directory.md"><strong><code>Query.to_directory</code></strong></a>(name)</td><td>Load query results that contain a <code>file_id</code> variable as a directory.</td></tr><tr><td><a href="/api/client-libraries/redivis-python/reference/table/table.to_directory.md"><strong><code>Table.to_directory</code></strong></a>(name)</td><td>Load any table contains a <code>file_id</code> variable as a directory.</td></tr></tbody></table>

## Examples

{% tabs %}
{% tab title="Basics" %}

```python
import redivis

dir = redivis.table("table_ref").to_directory()
print(dir.list()) # list files + directories within this directory
all_files = dir.list(mode="files", recursive=True)

file = dir.get("path/to/file.txt") # Will return None if doesn't exist
subdir = dir.get("path/to/subdir")
```

{% endtab %}

{% tab title="Mount & Download files" %}

```python
import redivis

dir = redivis.table("table_ref").to_directory()

# Download all files to the provided path
dir.download("/download/path")

# dir.mount() behaves the same as dir.download() was called (all files appear on disk)
# However, this doesn't actually download the files until they're needed, 
#    and as such is much faster, particularly when all files may not need to be read.
dir.mount("/download/path")
```

{% endtab %}
{% endtabs %}

## Attributes

| **`path`**  | <p>The path of this directory (a <code>pathlib.Path</code>) relative to the root directory in the current tree. <br><br>The path of the top-level directory (that is, any directory returned from table / query <code>.to\_directory()</code> ) will always be <code>"/"</code></p> |
| ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **`query`** | A reference to the [Query](/api/client-libraries/redivis-python/reference/query.md) that constructed this directory. Will be `None` if the directory is derived from a table.                                                                                                       |
| **`table`** | A reference to the [Table](/api/client-libraries/redivis-python/reference/table.md) that constructed this directory. Will be `None` if the directory is derived from a query.                                                                                                       |

## Methods

<table data-header-hidden><thead><tr><th width="441"></th><th></th></tr></thead><tbody><tr><td><a href="/api/client-libraries/redivis-python/reference/directory/directory.download.md"><strong>Directory.download</strong></a>([path, *, overwrite, ...])</td><td>Downloads files in the directory to the specified path.</td></tr><tr><td><a href="/api/client-libraries/redivis-python/reference/directory/directory.get.md"><strong>Directory.get</strong></a>(path)</td><td>Get a file or directory relative to this directory</td></tr><tr><td><a href="/api/client-libraries/redivis-python/reference/directory/directory.list.md"><strong>Directory.list</strong></a>([max_results, *, mode, recursive])</td><td>List the contents of a directory</td></tr><tr><td><a href="/api/client-libraries/redivis-python/reference/directory/directory.mount.md"><strong>Directory.mount</strong></a>([path, *, foreground])</td><td>Mount the directory as a volume at the provided path, allowing files to be lazily loaded as they're accessed.</td></tr><tr><td><a href="/api/client-libraries/redivis-python/reference/directory/directory.unmount.md"><strong>Directory.unmount</strong></a>([path, *, foreground])</td><td>Unmounts a previously mounted directory.</td></tr></tbody></table>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.redivis.com/api/client-libraries/redivis-python/reference/directory.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
