# PyFilesystem2
Python's Filesystem abstraction layer.
[![PyPI version](https://img.shields.io/pypi/v/fs)](https://pypi.org/project/fs/)
[![PyPI](https://img.shields.io/pypi/pyversions/fs.svg)](https://pypi.org/project/fs/)
[![Downloads](https://pepy.tech/badge/fs/month)](https://pepy.tech/project/fs/)
[![Build Status](https://img.shields.io/github/workflow/status/PyFilesystem/pyfilesystem2/Test/master?logo=github&cacheSeconds=600)](https://github.com/PyFilesystem/pyfilesystem2/actions?query=branch%3Amaster)
[![Windows Build Status](https://img.shields.io/appveyor/build/willmcgugan/pyfilesystem2/master?logo=appveyor&cacheSeconds=600)](https://ci.appveyor.com/project/willmcgugan/pyfilesystem2)
[![Coverage Status](https://img.shields.io/coveralls/github/PyFilesystem/pyfilesystem2/master?cacheSeconds=600)](https://coveralls.io/github/PyFilesystem/pyfilesystem2)
[![Codacy Badge](https://img.shields.io/codacy/grade/30ad6445427349218425d93886ade9ee/master?logo=codacy)](https://www.codacy.com/app/will-mcgugan/pyfilesystem2?utm_source=github.com&utm_medium=referral&utm_content=PyFilesystem/pyfilesystem2&utm_campaign=Badge_Grade)
[![Docs](https://img.shields.io/readthedocs/pyfilesystem2?maxAge=3600)](http://pyfilesystem2.readthedocs.io/en/stable/?badge=stable)
## Documentation
- [Wiki](https://www.pyfilesystem.org)
- [API Documentation](https://docs.pyfilesystem.org/)
- [GitHub Repository](https://github.com/PyFilesystem/pyfilesystem2)
- [Blog](https://www.willmcgugan.com/tag/fs/)
## 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.
```python
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:
```python
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:
```python
projects_fs = open_fs('zip://projects.zip')
```
Or to count the Python lines on an FTP server:
```python
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:
```python
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:
- [Will McGugan](https://github.com/willmcgugan)
- [Martin Larralde](https://github.com/althonos)
- [Giampaolo Cimino](https://github.com/gpcimino)
- [Geoff Jukes](https://github.com/geoffjukes)
See [CONTRIBUTORS.md](https://github.com/PyFilesystem/pyfilesystem2/blob/master/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](mailto:willmcgugan@gmail.com).
Raw data
{
"_id": null,
"home_page": "https://github.com/PyFilesystem/pyfilesystem2",
"name": "fs",
"maintainer": "Martin Larralde",
"docs_url": "https://pythonhosted.org/fs/",
"requires_python": "",
"maintainer_email": "martin.larralde@embl.de",
"keywords": "",
"author": "Will McGugan",
"author_email": "will@willmcgugan.com",
"download_url": "https://files.pythonhosted.org/packages/5d/a9/af5bfd5a92592c16cdae5c04f68187a309be8a146b528eac3c6e30edbad2/fs-2.4.16.tar.gz",
"platform": "any",
"description": "# PyFilesystem2\n\nPython's Filesystem abstraction layer.\n\n[![PyPI version](https://img.shields.io/pypi/v/fs)](https://pypi.org/project/fs/)\n[![PyPI](https://img.shields.io/pypi/pyversions/fs.svg)](https://pypi.org/project/fs/)\n[![Downloads](https://pepy.tech/badge/fs/month)](https://pepy.tech/project/fs/)\n[![Build Status](https://img.shields.io/github/workflow/status/PyFilesystem/pyfilesystem2/Test/master?logo=github&cacheSeconds=600)](https://github.com/PyFilesystem/pyfilesystem2/actions?query=branch%3Amaster)\n[![Windows Build Status](https://img.shields.io/appveyor/build/willmcgugan/pyfilesystem2/master?logo=appveyor&cacheSeconds=600)](https://ci.appveyor.com/project/willmcgugan/pyfilesystem2)\n[![Coverage Status](https://img.shields.io/coveralls/github/PyFilesystem/pyfilesystem2/master?cacheSeconds=600)](https://coveralls.io/github/PyFilesystem/pyfilesystem2)\n[![Codacy Badge](https://img.shields.io/codacy/grade/30ad6445427349218425d93886ade9ee/master?logo=codacy)](https://www.codacy.com/app/will-mcgugan/pyfilesystem2?utm_source=github.com&utm_medium=referral&utm_content=PyFilesystem/pyfilesystem2&utm_campaign=Badge_Grade)\n[![Docs](https://img.shields.io/readthedocs/pyfilesystem2?maxAge=3600)](http://pyfilesystem2.readthedocs.io/en/stable/?badge=stable)\n\n## Documentation\n\n- [Wiki](https://www.pyfilesystem.org)\n- [API Documentation](https://docs.pyfilesystem.org/)\n- [GitHub Repository](https://github.com/PyFilesystem/pyfilesystem2)\n- [Blog](https://www.willmcgugan.com/tag/fs/)\n\n## Introduction\n\nThink of PyFilesystem's `FS` objects as the next logical step to\nPython's `file` objects. In the same way that file objects abstract a\nsingle file, FS objects abstract an entire filesystem.\n\nLet's look at a simple piece of code as an example. The following\nfunction uses the PyFilesystem API to count the number of non-blank\nlines of Python code in a directory. It works _recursively_, so it will\nfind `.py` files in all sub-directories.\n\n```python\ndef count_python_loc(fs):\n \"\"\"Count non-blank lines of Python code.\"\"\"\n count = 0\n for path in fs.walk.files(filter=['*.py']):\n with fs.open(path) as python_file:\n count += sum(1 for line in python_file if line.strip())\n return count\n```\n\nWe can call `count_python_loc` as follows:\n\n```python\nfrom fs import open_fs\nprojects_fs = open_fs('~/projects')\nprint(count_python_loc(projects_fs))\n```\n\nThe line `project_fs = open_fs('~/projects')` opens an FS object that\nmaps to the `projects` directory in your home folder. That object is\nused by `count_python_loc` when counting lines of code.\n\nTo count the lines of Python code in a _zip file_, we can make the\nfollowing change:\n\n```python\nprojects_fs = open_fs('zip://projects.zip')\n```\n\nOr to count the Python lines on an FTP server:\n\n```python\nprojects_fs = open_fs('ftp://ftp.example.org/projects')\n```\n\nNo changes to `count_python_loc` are necessary, because PyFileystem\nprovides a simple consistent interface to anything that resembles a\ncollection of files and directories. Essentially, it allows you to write\ncode that is independent of where and how the files are physically\nstored.\n\nContrast that with a version that purely uses the standard library:\n\n```python\ndef count_py_loc(path):\n count = 0\n for root, dirs, files in os.walk(path):\n for name in files:\n if name.endswith('.py'):\n with open(os.path.join(root, name), 'rt') as python_file:\n count += sum(1 for line in python_file if line.strip())\n return count\n```\n\nThis version is similar to the PyFilesystem code above, but would only\nwork with the OS filesystem. Any other filesystem would require an\nentirely different API, and you would likely have to re-implement the\ndirectory walking functionality of `os.walk`.\n\n## Credits\n\nThe following developers have contributed code and their time to this projects:\n\n- [Will McGugan](https://github.com/willmcgugan)\n- [Martin Larralde](https://github.com/althonos)\n- [Giampaolo Cimino](https://github.com/gpcimino)\n- [Geoff Jukes](https://github.com/geoffjukes)\n\nSee [CONTRIBUTORS.md](https://github.com/PyFilesystem/pyfilesystem2/blob/master/CONTRIBUTORS.md)\nfor a full list of contributors.\n\nPyFilesystem2 owes a massive debt of gratitude to the following\ndevelopers who contributed code and ideas to the original version.\n\n- Ryan Kelly\n- Andrew Scheller\n- Ben Timby\n\nApologies if I missed anyone, feel free to prompt me if your name is\nmissing here.\n\n## Support\n\nIf commercial support is required, please contact [Will McGugan](mailto:willmcgugan@gmail.com).\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Python's filesystem abstraction layer",
"version": "2.4.16",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "a3943b641699f1b97998cb96809dceff",
"sha256": "660064febbccda264ae0b6bace80a8d1be9e089e0a5eb2427b7d517f9a91545c"
},
"downloads": -1,
"filename": "fs-2.4.16-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "a3943b641699f1b97998cb96809dceff",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 135261,
"upload_time": "2022-05-02T09:25:52",
"upload_time_iso_8601": "2022-05-02T09:25:52.363589Z",
"url": "https://files.pythonhosted.org/packages/b9/5c/a3d95dc1ec6cdeb032d789b552ecc76effa3557ea9186e1566df6aac18df/fs-2.4.16-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"md5": "2c9dae3d52950407fe265c3576396c33",
"sha256": "ae97c7d51213f4b70b6a958292530289090de3a7e15841e108fbe144f069d313"
},
"downloads": -1,
"filename": "fs-2.4.16.tar.gz",
"has_sig": false,
"md5_digest": "2c9dae3d52950407fe265c3576396c33",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 187441,
"upload_time": "2022-05-02T09:25:54",
"upload_time_iso_8601": "2022-05-02T09:25:54.220887Z",
"url": "https://files.pythonhosted.org/packages/5d/a9/af5bfd5a92592c16cdae5c04f68187a309be8a146b528eac3c6e30edbad2/fs-2.4.16.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2022-05-02 09:25:54",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "PyFilesystem",
"github_project": "pyfilesystem2",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"appveyor": true,
"lcname": "fs"
}