Safely perform file I/O operations in Python — with backups and auto-rotation
Project description
safeiofile
Safely perform file I/O operations in Python — with built-in backups, smart appends, and automatic rotation.
Table of Contents
What is it?
safeiofile is a Python library that makes it easier and safer to work with files — especially when you're dealing with logs, configuration files, or any content that might be written to or read from repeatedly.
It provides:
- Clean and chainable syntax
- Automatic timestamped backups
- Safe appending and reading
- File rotation when size exceeds a limit
Unlike traditional Python file operations, this library abstracts away common pitfalls like overwriting, file collisions, and manual rotation.
Installation
Install via pip:
pip install safeiofile
Usage
from safeiofile import File
log = File("logs/activity.log")
log.write("Session started")
log.append("User logged in")
log.backup()
log.rotate_if_large(max_mb=1)
print(log.read())
Object
File(path)
A safe, cross-platform object to handle common file operations like reading, writing, appending, backups, and rotation — all in one clean interface.
Methods
File(path)
A safe file object for basic and extended file operations.
read()
Reads and returns full file content as a string.
write(data)
Overwrites the file with the provided content.
Returns the File object for chaining.
append(data)
Appends the provided data to the file with a newline.
Returns the File object for chaining.
backup()
Creates a timestamped .bak backup file in the same directory.
Example: log.txt.20250708_120045.bak
Returns the path to the backup.
rotate_if_large(max_mb=1)
If file size exceeds max_mb (default 1MB), creates a backup and truncates the original.
Returns the File object for chaining.
Returns the File object for chaining.
Tips
You can easily integrate safeiofile in your scripting workflows:
log = File("system.log")
if condition_met:
log.append("New entry detected")
log.rotate_if_large(max_mb=2)
Credits
safeiofile by Omkar D. Dorugade
© Omkar D. Dorugade — 2025
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 safeiofile-0.1.1.tar.gz.
File metadata
- Download URL: safeiofile-0.1.1.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0c9c25e70f8f30e989563e510814276a0968031f672b10d3a651e9e3416efeaa
|
|
| MD5 |
d8d2acab261576b39b25dd334cebd3a4
|
|
| BLAKE2b-256 |
6fd94c72dc5967e9e76d27b32512451a41573c0c13f12ace2035f6502525267d
|
File details
Details for the file safeiofile-0.1.1-py3-none-any.whl.
File metadata
- Download URL: safeiofile-0.1.1-py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7baaf5b4f625260656bff4c9a2e582c9fe4802d88051283a42f1d868939167ba
|
|
| MD5 |
13a7f0a302983cf176b7d3362d5159d8
|
|
| BLAKE2b-256 |
266d60356ad217affe49a13e4ec904aeec8ecb39bf0534505bae6dc31b3e3ead
|