List Files
List the files in a Haystack Enterprise Platform workspace. You can use the CLI or Python SDK to do it.
About This Task
list-files prints a table of the files in a workspace. Each row shows the file ID, URL, name, size, creation date, and metadata.
When using the Haystack Enterprise SDK on Windows, if haystack-enterprise isn't on your PATH, replace it with python -m haystack_enterprise_sdk.cli, for example:
haystack-enterprise validate pipeline.py
becomes
python -m haystack_enterprise_sdk.cli validate pipeline.py
Paging Through Results
The CLI fetches files in batches. After each batch, it asks Print more results?. Press Enter to see the next batch, or type any other key to stop.
This prompt needs an interactive terminal. In a non-interactive shell, such as a CI job, the command prints the first batch and then exits with an error. To list files in a script, use the Python generator instead.
Choosing Which Files to List
To narrow the list, filter by file name or by metadata:
--namelists only files whose name matches.--odata-filterlists only files whose metadata matches an OData filter, for example--odata-filter "category eq 'news'".
Prerequisites
Set up the SDK to authenticate and specify the workspace whose files you want to list.
List Files
Run the following command to list the files in your default workspace:
haystack-enterprise list-files
To list files in another workspace, add --workspace-name:
haystack-enterprise list-files --workspace-name my-workspace
List Files with Python
list_files returns a generator that yields one batch of files at a time. Each file is an object with file_id, url, name, size, created_at, and meta attributes. Because it's a generator, it works in scripts where the CLI's paging prompt can't run.
from haystack_enterprise_sdk.workflows.sync_client.files import list_files
for batch in list_files(workspace_name="my-workspace", batch_size=100):
for file in batch:
print(file.name, file.file_id, file.meta)
Examples
- List the files in a specific workspace:
haystack-enterprise list-files --workspace-name my-workspace
- List only files with a specific name:
haystack-enterprise list-files --name "report.pdf"
- List only files whose metadata matches a filter:
haystack-enterprise list-files --odata-filter "category eq 'news'"
- List with INFO and DEBUG logs turned on:
haystack-enterprise --verbose list-files
Related Information
Was this page helpful?