Skip to content

Speed up pathlib.Path.glob() by working with strings internally #117586

Description

@barneygale

pathlib.Path.glob() currently generates Path objects for intermediate paths that might never be yielded to the user, which is slow and unnecessary. For example, a pattern like **/*.mp3 is evaluated by creating a Path object for every directory visited.

There are already few tricks employed to avoid instantiation, but it would be better if only real results were converted to path objects.

Linked PRs

Activity

  1. added
    performancePerformance or resource usage
    stdlibStandard Library Python modules in the Lib/ directory
    on Apr 6, 2024
  2. added 4 commits that reference this issue on Apr 6, 2024
  3. added 2 commits that reference this issue on Apr 17, 2024
  4. papahippo commented on Oct 9, 2026

    @papahippo

    The documentation doesn't seems to have been updated yet:
    3.14.8 Documentation » The Python standard library » File and Directory Access » pathlib — Object-oriented filesystem paths

    The above still says that lists of paths are returned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    performancePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directorytopic-pathlib

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions