fs 2.4.16


pip install fs

  Latest version

Released: May 02, 2022


Meta
Author: Will McGugan
Maintainer: Martin Larralde

Classifiers

Development Status
  • 5 - Production/Stable

Intended Audience
  • Developers

License
  • OSI Approved :: MIT License

Operating System
  • OS Independent

Programming Language
  • Python
  • Python :: 2.7
  • Python :: 3.5
  • Python :: 3.6
  • Python :: 3.7
  • Python :: 3.8
  • Python :: 3.9
  • Python :: 3.10
  • Python :: Implementation :: CPython
  • Python :: Implementation :: PyPy

Topic
  • System :: Filesystems

Typing
  • Typed

PyFilesystem2

Python's Filesystem abstraction layer.

PyPI version PyPI Downloads Build Status Windows Build Status Coverage Status Codacy Badge Docs

Documentation

Introduction

Think of PyFilesystem's FS objects as the next logical step to Python's file objects. In the same way that file objects abstract a single file, FS objects abstract an entire filesystem.

Let's look at a simple piece of code as an example. The following function uses the PyFilesystem API to count the number of non-blank lines of Python code in a directory. It works recursively, so it will find .py files in all sub-directories.

def count_python_loc(fs):
    """Count non-blank lines of Python code."""
    count = 0
    for path in fs.walk.files(filter=['*.py']):
        with fs.open(path) as python_file:
            count += sum(1 for line in python_file if line.strip())
    return count

We can call count_python_loc as follows:

from fs import open_fs
projects_fs = open_fs('~/projects')
print(count_python_loc(projects_fs))

The line project_fs = open_fs('~/projects') opens an FS object that maps to the projects directory in your home folder. That object is used by count_python_loc when counting lines of code.

To count the lines of Python code in a zip file, we can make the following change:

projects_fs = open_fs('zip://projects.zip')

Or to count the Python lines on an FTP server:

projects_fs = open_fs('ftp://ftp.example.org/projects')

No changes to count_python_loc are necessary, because PyFileystem provides a simple consistent interface to anything that resembles a collection of files and directories. Essentially, it allows you to write code that is independent of where and how the files are physically stored.

Contrast that with a version that purely uses the standard library:

def count_py_loc(path):
    count = 0
    for root, dirs, files in os.walk(path):
        for name in files:
            if name.endswith('.py'):
                with open(os.path.join(root, name), 'rt') as python_file:
                    count += sum(1 for line in python_file if line.strip())
    return count

This version is similar to the PyFilesystem code above, but would only work with the OS filesystem. Any other filesystem would require an entirely different API, and you would likely have to re-implement the directory walking functionality of os.walk.

Credits

The following developers have contributed code and their time to this projects:

See CONTRIBUTORS.md for a full list of contributors.

PyFilesystem2 owes a massive debt of gratitude to the following developers who contributed code and ideas to the original version.

  • Ryan Kelly
  • Andrew Scheller
  • Ben Timby

Apologies if I missed anyone, feel free to prompt me if your name is missing here.

Support

If commercial support is required, please contact Will McGugan.

2.4.16 May 02, 2022
2.4.15 Feb 07, 2022
2.4.14 Nov 16, 2021
2.4.13 Mar 27, 2021
2.4.12 Jan 14, 2021
2.4.11 Sep 07, 2019
2.4.10 Jul 29, 2019
2.4.9 Jul 28, 2019
2.4.8 Jun 12, 2019
2.4.7 Jun 08, 2019
2.4.6 Jun 08, 2019
2.4.5 May 05, 2019
2.4.4 Feb 23, 2019
2.4.3 Feb 23, 2019
2.4.2 Feb 22, 2019
2.4.1 Feb 20, 2019
2.4.0 Feb 15, 2019
2.3.1 Feb 10, 2019
2.3.0 Jan 30, 2019
2.2.1 Jan 06, 2019
2.2.0 Jan 01, 2019
2.1.3 Dec 24, 2018
2.1.2 Nov 10, 2018
2.1.1 Oct 03, 2018
2.1.0 Aug 12, 2018
2.0.27 Aug 05, 2018
2.0.26 Jul 26, 2018
2.0.25 Jul 20, 2018
2.0.25a1 Jul 15, 2018
2.0.25a0 Jul 12, 2018
2.0.24 Jun 28, 2018
2.0.23 May 19, 2018
2.0.23a1 May 19, 2018
2.0.23a0 May 19, 2018
2.0.22 May 19, 2018
2.0.22a0 May 04, 2018
2.0.21 May 02, 2018
2.0.20 Mar 13, 2018
2.0.19 Mar 11, 2018
2.0.18 Jan 31, 2018
2.0.17 Nov 20, 2017
2.0.16 Nov 11, 2017
2.0.15 Nov 05, 2017
2.0.14 Nov 05, 2017
2.0.12 Oct 15, 2017
2.0.12a1 Oct 10, 2017
2.0.12a0 Sep 29, 2017
2.0.11 Sep 27, 2017
2.0.11a0 Sep 27, 2017
2.0.10 Sep 22, 2017
2.0.10a2 Sep 21, 2017
2.0.10a1 Sep 18, 2017
2.0.10a0 Sep 09, 2017
2.0.9 Aug 22, 2017
2.0.8 Aug 13, 2017
2.0.8a1 Aug 13, 2017
2.0.7 Aug 06, 2017
2.0.6 Aug 05, 2017
2.0.6a2 Aug 04, 2017
2.0.6a1 Aug 04, 2017
2.0.6a0 Aug 04, 2017
2.0.5 Aug 02, 2017
2.0.5a0 Aug 02, 2017
2.0.4 Jun 11, 2017
2.0.4a3 Jun 11, 2017
2.0.4a1 Apr 23, 2017
2.0.4a0 Apr 23, 2017
2.0.3 Apr 22, 2017
2.0.2 Mar 26, 2017
2.0.1 Mar 11, 2017
2.0.1a0 Feb 19, 2017
2.0.0 Dec 07, 2016
2.0.0a6 Dec 03, 2016
2.0.0a5 Dec 03, 2016
2.0.0a4 Dec 03, 2016
2.0.0a3 Dec 02, 2016
2.0.0a2 Nov 22, 2016
2.0.0a1 Oct 23, 2016
2.0.0a0 Oct 23, 2016
0.5.5a1 Jan 22, 2017
0.5.4 Nov 14, 2015
0.5.3 Sep 07, 2015
0.5.2 May 01, 2015
0.5.1 Feb 14, 2015
0.5.0 Mar 14, 2014
0.4.0 Mar 17, 2014

Wheel compatibility matrix

Platform Python 2 Python 3
any

Files in release

Extras:
Dependencies:
appdirs (~=1.4.3)
setuptools
six (~=1.10)
backports.os (~=0.1)
enum34 (~=1.1.6)
typing (~=3.6)