Lightweight, object-oriented utility library for convenient file management in Python.
Project description
fileio
fileio is a lightweight, object-oriented utility library for convenient file management in Python. It provides a robust and intuitive API to perform file operations such as creation, reading, writing, appending, deleting, backup, and hashing, along with JSON and CSV support.
Installation
fileio is a standalone Python package. To use it, simply download the File.py module and place it in your project directory.
Alternatively, if you plan to publish it on PyPI, you could install it via pip:
pip install fileio
(Assuming the package is published under that name.)
Usage
Here’s how to use the File class:
Import the module
from pz_fileio import File
Creating a File instance
f = File("path/to/your/file.txt")
Basic operations
-
Check if file exists
exists = f.Exists()
-
Create a new file
f.Create()
-
Delete a file
f.Delete()
-
Recreate the file (delete and create a new empty one)
f.Recreate()
-
Get basic information
print(f.GetBasename()) # filename only print(f.GetDirname()) # directory name print(f.GetAbsolutePath()) # absolute path print(f.GetFileSize()) # file size in bytes print(f.GetMimeType()) # file MIME type
Reading and writing content
-
Read the entire file content
content = f.Read()
-
Read lines
lines = f.ReadLines()
-
Append content
f.Append("This is a new line.")
-
Overwrite content
f.Overwrite("This will replace everything.")
JSON and CSV handling
-
Read as JSON
data = f.ReadAsJson()
-
Write as JSON
f.WriteAsJson({"name": "fileio", "version": 1.0})
-
Read as CSV
rows = f.ReadAsCsv()
-
Write as CSV
f.WriteAsCsv([["name", "value"], ["fileio", "awesome"]])
Hashing and backup
-
Calculate file hash
file_hash = f.Hash() # Defaults to SHA-256
-
Create a backup
backup_path = f.Backup() print(f"Backup created at: {backup_path}")
Context manager usage
The File class implements the context management protocol (with statement). Use it for read-only scenarios:
with File("path/to/your/file.txt") as f:
content = f.Read()
License
MIT License
Want to tweak this further (like adding examples for CSV, JSON, or advanced usage)? Let me know and I’ll extend it! 🚀
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pz_fileio-1.0.1.tar.gz.
File metadata
- Download URL: pz_fileio-1.0.1.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
50be1e6713375ed951d766ea4208129131130487a16e3dbc9fd3328d1c7e4adc
|
|
| MD5 |
a0a4063b3283620185e0f9216aa29369
|
|
| BLAKE2b-256 |
988a1998e44fecf65ffd54ed3cdacedc51329ef337d40c1f89f6412fa9c42832
|
File details
Details for the file pz_fileio-1.0.1-py3-none-any.whl.
File metadata
- Download URL: pz_fileio-1.0.1-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
85ef62c1569203e4a521277d9384f9fab5dc0f17112b5a9a3f4f2d1acc340e0e
|
|
| MD5 |
6f9ecdcbe2625aa5d8fbad83261d5118
|
|
| BLAKE2b-256 |
d3ffd12b1901262e23e2547ec9964ad45d30ac6286797fbf394d01d713afd251
|