Registry / data / fs
library2.4.16pypypi✓ verified 31d ago

PyFilesystem2 is a Python library that provides a common, high-level abstraction layer for interacting with various filesystems, including local, memory, zip, FTP, and more. It enables consistent management of files and directories across different storage backends. The current version is 2.4.16, with frequent maintenance and minor feature releases.

pip install fs
INSTALL
IMPORT
SIG · FS
F
fs
datapythonv2.4.16
Install
1.9s avg
Import
515ms
Disk
20MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v2.4.16 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.346s · 19.8MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 1.9s · import 0.272s · 20MB
20MB installed
● package 20MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

open_fs
✓ from fs import open_fs
✗ from fs import open_fs

Demonstrates opening and interacting with a memory filesystem and a local OS filesystem. It shows creating, writing, reading, listing, and cleaning up resources, emphasizing the use of context managers for proper resource handling.

from fs import open_fs from fs.osfs import OSFS import os # Example 1: Using a memory filesystem print("--- Memory Filesystem Example ---") with open_fs("mem://") as mem_fs: mem_fs.writetext("hello.txt", "Hello from MemoryFS!") print(f"Content of hello.txt: {mem_fs.readtext('hello.txt')}") print(f"Files in memory FS: {mem_fs.listdir('/')}") # Example 2: Using the local operating system filesystem print("\n--- OS Filesystem Example ---") # Opens a filesystem for the current working directory with OSFS('.') as os_fs: temp_dir_path = "_fs_temp_dir_" temp_file_path = os.path.join(temp_dir_path, "temp_quickstart.txt") if not os_fs.exists(temp_dir_path): os_fs.makedir(temp_dir_path) print(f"Created directory: {temp_dir_path}") os_fs.writetext(temp_file_path, "This is a temporary file in OSFS.") print(f"Content of {temp_file_path}: {os_fs.readtext(temp_file_path)}") # Clean up the created file and directory os_fs.remove(temp_file_path) os_fs.removedir(temp_dir_path) print(f"Cleaned up: {temp_file_path} and {temp_dir_path}")
fs --version
Debug
Known issues
breakingPyFilesystem v1 (pyfilesystem) vs. v2 (fs) - Complete API and import path rewrite.
fix
Code written for `pyfilesystem` (v1) is incompatible with `fs` (v2). You must rewrite your code to use the `fs` (v2) API and import paths (e.g., `from fs import open_fs` instead of `from fs.opener import open_fs`). The `fs` package on PyPI refers to v2.
affects: <2.0.0 (pyfilesystem) vs. >=2.0.0 (fs)
gotchaFilesystem objects should be properly closed using context managers or explicit close() calls.
fix
Always use filesystem objects within a `with` statement (e.g., `with open_fs('osfs://') as my_fs:`). This ensures resources (like file handles or network connections) are released automatically. If not using a context manager, call `my_fs.close()` explicitly when done.
affects: >=2.0.0
gotchaPaths within PyFilesystem are 'universal' and use `/` as the separator, regardless of the underlying OS.
fix
Always use `/` as the path separator when interacting with `fs` objects. Avoid using `os.sep` or platform-specific separators directly within `fs` methods. The `fs.path` module provides utility functions for path manipulation that are consistent with `fs` conventions.
affects: >=2.0.0
gotchaAttempting write operations on a read-only filesystem will raise errors.
fix
Ensure the filesystem is opened with write permissions if you intend to modify it. `fs.open_fs` has a `writable` parameter, and some filesystems (e.g., `ZipFS` opened in read mode) are inherently read-only. Check `my_fs.is_writable` before attempting writes. For creating read-only views of a writable FS, use `fs.wrap.read_only`.
affects: >=2.0.0
breakingPyFilesystem v2 (fs) relies on `pkg_resources` (a part of `setuptools`), which might not be automatically present in minimal Python environments, leading to a `ModuleNotFoundError` on import.
fix
Ensure `setuptools` is installed in your Python environment (e.g., by adding `setuptools` to your `requirements.txt` or explicitly installing it via `pip install setuptools`).
affects: fs >=2.0.0
Upgrade
Version history
2.4.16latest on PyPI · released May 2, 2022
Audit
Dependencies

No dependency data recorded yet.

Agent activity
19 hits · last 30 days
node
18
Amazon
1
Resources
fs — pip install fs · libregistry