Skip to main content

pyfileops

pyfileops is a simple, friendly Python library for everyday file and directory operations.
No need to juggle os, shutil, pathlib, or zipfile — everything lives behind one clean object: fs.

from pyfileops import fs

fs.copy("report.pdf", "backup/")
fs.delete("temp.log")
print(fs.size("video.mp4"))

PyPI version Python License: MIT


Installation

pip install pyfileops

Requires Python 3.8+. No external dependencies — only the standard library.


Quickstart

from pyfileops import fs

# ── Files ──────────────────────────────────────────────────────────────
fs.copy("notes.txt", "backup/")           # copy into an existing folder
fs.copy("notes.txt", "backup/notes2.txt") # copy with a new name
fs.cut("draft.docx", "archive/")          # move file
fs.rename("old.txt", "new.txt")           # rename in place
fs.delete("trash.log")                    # delete a file

# ── Directories ────────────────────────────────────────────────────────
fs.mkdir("project/src/utils")             # create (nested) directories
fs.rmdir("tmp")                           # remove directory and contents

# ── Compression ────────────────────────────────────────────────────────
fs.zip("project", "project_v1.zip")       # zip a directory
fs.zip("report.pdf", "report.zip")        # zip a single file
fs.unzip("project_v1.zip", "restored/")   # extract a zip

# ── Queries ────────────────────────────────────────────────────────────
fs.exists("config.ini")    # True or False
fs.size("video.mp4")       # size in bytes (int)
fs.is_file("data.csv")     # True or False
fs.is_dir("assets")        # True or False

API Reference

File Operations

fs.copy(source, destination) → Path

Copies a file or directory to destination.

  • If destination is an existing directory, the source is placed inside it.
  • If destination does not exist, it becomes the new file/folder name.
  • Missing intermediate directories are created automatically.
fs.copy("logo.png", "assets/")          # → assets/logo.png
fs.copy("logo.png", "assets/icon.png")  # → assets/icon.png
fs.copy("src/", "src_backup/")          # copies whole directory tree

fs.cut(source, destination) → Path

Moves a file or directory to destination (copy + delete original).

fs.cut("uploads/photo.jpg", "gallery/")

fs.rename(path, new_name) → Path

Renames a file or directory in place (same parent directory).
To move to a different location, use cut().

fs.rename("report_draft.pdf", "report_final.pdf")

fs.delete(path) → None

Deletes a file or an entire directory tree.

fs.delete("temp.log")    # file
fs.delete("cache/")      # directory and all its contents

Directory Operations

fs.mkdir(path) → Path

Creates a directory (and any missing parent directories). Safe to call even if it already exists.

fs.mkdir("project/assets/images")

fs.rmdir(path) → None

Removes a directory and everything inside it.

fs.rmdir("build/")

Compression

fs.zip(source, zip_file) → Path

Compresses source (file or directory) into a ZIP archive at zip_file.

fs.zip("my_project", "my_project.zip")
fs.zip("data.csv", "data.zip")

fs.unzip(zip_file, destination) → Path

Extracts a ZIP archive into destination.

fs.unzip("my_project.zip", "restored/")

Queries

fs.exists(path) → bool

Returns True if path exists (file or directory).

if fs.exists("config.ini"):
    print("Config found!")

fs.size(path) → int

Returns the size in bytes.

  • For files: the file size.
  • For directories: the total size of all contained files.
bytes_used = fs.size("video.mp4")
print(f"{bytes_used / 1_000_000:.2f} MB")

fs.is_file(path) → bool

Returns True if path is a regular file (returns False if it doesn't exist).

fs.is_file("README.md")  # True
fs.is_file("src/")       # False

fs.is_dir(path) → bool

Returns True if path is a directory (returns False if it doesn't exist).

fs.is_dir("src/")        # True
fs.is_dir("README.md")   # False

Error Handling

pyfileops raises clear, specific exceptions so you always know what went wrong.

Exception When it's raised
FileOpsError Base class for all pyfileops errors
PathNotFoundError Source path does not exist
CopyError A copy or move operation failed
DeleteError A delete operation failed
ZipError A zip or unzip operation failed

All exceptions inherit from FileOpsError, which inherits from Exception.

from pyfileops import fs
from pyfileops import PathNotFoundError, CopyError, ZipError, FileOpsError

# Catch a specific error
try:
    fs.copy("missing.txt", "backup/")
except PathNotFoundError as e:
    print(e)  # Path not found: 'missing.txt'

# Catch any pyfileops error
try:
    fs.zip("project", "output.zip")
    fs.delete("tmp/")
except FileOpsError as e:
    print(f"Operation failed: {e}")

Author

Made by Fede · github.com/FefinDev/pyfileops


License

MIT

Metadata

Release files for pyfileops 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyfileops 1.0.0
File Size Uploaded Provenance Actions
pyfileops-1.0.0.tar.gz 9.7 kB Without provenance Details for pyfileops-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyfileops 1.0.0
File Interpreter ABI Platform Actions
pyfileops-1.0.0-py3-none-any.whl Python 3 none any Details for pyfileops-1.0.0-py3-none-any.whl

Total release size: 18.5 kB

Release files / pyfileops-1.0.0.tar.gz

Download URL pyfileops-1.0.0.tar.gz
Size 9.7 kB
Tags Source
SHA-256 checksum
How to use checksums
d57a42791d60567d4ab87e22c7e5914c93dac1847475c74c59fa16f62888709f
BLAKE2b-256 checksum
How to use checksums
7a11ac15ca5e6ce7d6888deaaf1f5583b694493df4f76ccaa8fbb1db92597eaa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.0

Release files / pyfileops-1.0.0-py3-none-any.whl

Download URL pyfileops-1.0.0-py3-none-any.whl
Size 8.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7fea8124edc3c4b19dee3d9f8512da9697ef1e97bfbaacff35eae86554b7ba41
BLAKE2b-256 checksum
How to use checksums
dcc1a15c02d202a1550732be10be1a822ca55be9cc709ee161941ed291ad733f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.0

Security for pyfileops 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page