Skip to content

[Python] Add FileSystem.get_file_info_iterator() for incremental file listing #55752

Backlog

Description

@dragongu

FileSystem.get_file_info(selector) returns a list, so the whole listing is materialized before the caller sees the first entry. For a very large directory or prefix that means waiting for the complete listing, and holding all of it in memory, even when the caller only wants to process entries as they arrive, or to stop once it has found what it needs.

It would be useful to overlap listing with processing: start working on the entries that have already been discovered while the rest are still being listed.

The primary use case is listing very large S3 prefixes through PyArrow's native S3FileSystem. Callers should be able to start computing on objects from the first listing page while subsequent pages are still being fetched, rather than waiting for the entire prefix to be listed. The C++ S3 implementation already pushes results as each ListObjectsV2 page completes; exposing this to Python would enable pipelined listing and processing without changing the S3 backend.

Arrow C++ already has FileSystem::GetFileInfoGenerator() for this, but it is not exposed in Python.

Proposal, with naming open to discussion: add FileSystem.get_file_info_iterator(selector), returning an iterator that yields FileInfo objects one at a time and fetches them from the filesystem in batches, so that a listing can be consumed incrementally and abandoned early.

for info in fs.get_file_info_iterator(FileSelector(path, recursive=True)):
    ...  # info is a FileInfo

Backend differences

How incremental this actually is depends on the backend. In C++ only LocalFileSystem and S3FileSystem override GetFileInfoGenerator(). GcsFileSystem, AzureFileSystem, HadoopFileSystem and PyFileSystem, which backs the fsspec integration, fall back to the base-class implementation, which lists everything and wraps the result in a single batch.

On those backends the iterator yields the same entries as get_file_info(), but the full listing is still materialized on the first next() call, so neither the memory nor the early-termination benefit applies. Only LocalFileSystem and S3FileSystem would get those today.

Possible follow-ups, out of scope here

  • A capability query so callers can tell whether a filesystem actually lists incrementally. There is currently no way to detect this: GetFileInfoGenerator() is a plain virtual method, and wrappers such as SubTreeFileSystem override it but forward to an inner filesystem, so the behaviour depends on what is wrapped.
  • Implementing GetFileInfoGenerator() for GcsFileSystem and AzureFileSystem, whose underlying APIs are already paginated but are currently collected into a single vector.

Component(s)

Python

Activity

  1. added a commit that references this issue on Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions