Code Monkey home page Code Monkey logo

PyFilesystem

Note: The project has largely been replaced by PyFilesystem2 which offers many improvements over the original.

PyFilesystem is an abstraction layer for filesystems. In the same way that Python's file-like objects provide a common way of accessing files, PyFilesystem provides a common way of accessing entire filesystems. You can write platform-independent code to work with local files, that also works with any of the supported filesystems (zip, ftp, S3 etc.).

Pyfilesystem works with Linux, Windows and Mac.

Supported Filesystems

Here are a few of the filesystems that can be accessed with Pyfilesystem:

  • DavFS access files & directories on a WebDAV server
  • FTPFS access files & directories on an FTP server
  • MemoryFS access files & directories stored in memory (non-permanent but very fast)
  • MountFS creates a virtual directory structure built from other filesystems
  • MultiFS a virtual filesystem that combines a list of filesystems into one, and checks them in order when opening files
  • OSFS the native filesystem
  • SFTPFS access files & directories stored on a Secure FTP server
  • S3FS access files & directories stored on Amazon S3 storage
  • TahoeLAFS access files & directories stored on a Tahoe distributed filesystem
  • ZipFS access files and directories contained in a zip file

Example

The following snippet prints the total number of bytes contained in all your Python files in C:/projects (including sub-directories)::

from fs.osfs import OSFS
projects_fs = OSFS('C:/projects')
print sum(projects_fs.getsize(path)
          for path in projects_fs.walkfiles(wildcard="*.py"))

That is, assuming you are on Windows and have a directory called 'projects' in your C drive. If you are on Linux / Mac, you might replace the second line with something like::

projects_fs = OSFS('~/projects')

If you later want to display the total size of Python files stored in a zip file, you could make the following change to the first two lines::

from fs.zipfs import ZipFS
projects_fs = ZipFS('source.zip')

In fact, you could use any of the supported filesystems above, and the code would continue to work as before.

An alternative to explicitly importing the filesystem class you want, is to use an FS opener which opens a filesystem from a URL-like syntax::

from fs.opener import fsopendir
projects_fs = fsopendir('C:/projects')

You could change C:/projects to zip://source.zip to open the zip file, or even ftp://ftp.example.org/code/projects/ to sum up the bytes of Python stored on an ftp server.

Documentation

http://pyfilesystem.readthedocs.org

Screencast

This is from an early version of PyFilesystem, but still relevant

http://vimeo.com/12680842

Discussion Group

http://groups.google.com/group/pyfilesystem-discussion

Further Information

http://www.willmcgugan.com/tag/fs/

pyFilesystem's Projects

s3fs icon s3fs

Amazon S3 filesystem for PyFilesystem2

webdavfs icon webdavfs

Pyfilesystem low-level driver for WebDAV storages

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.