A unified file handling abstraction layer for multiple file formats.
Project description
ATmulti_file_handler
A unified file handling abstraction layer for multiple file formats. This Python package provides a consistent interface to work with various file types including text, JSON, CSV, YAML, XML, Dill, binary files, and a custom VariableDB database.
Features
- Unified
Filebase class with consistent interface. - Format-specific subclasses:
TxtFile→.txtJsonFile→.jsonCsvFile→.csvDillFile→.dillXmlFile→.xmlYamlFile→.yml/.yamlByteFile→.bin/.exe/.img/.jpgVarDBFile→.db(requiresavi_toolspackage)
- Common operations:
read,write,append,exist,copy,move,delete. - Automatic directory and file creation if missing.
- Factory function
file()to automatically choose the right subclass based on extension.
Installation
You can install the package directly from PyPI:
pip install ATmulti_file_handler
This will also install all required dependencies:
dill, PyYAML, avi_tools.
Usage
Import the package
from ATmulti_file_handler import file
Working with Text Files
f = file("notes.txt")
f.write("Hello World")
print(f.read()) # -> "Hello World"
f.append("\nAppended text")
Working with JSON
f = file("data.json")
f.write({"a": 1})
print(f.read()) # -> {"a": 1}
f.append({"b": 2})
print(f.read()) # -> {"a": 1, "b": 2}
Working with CSV
f = file("table.csv")
f.write([["Name","Age"],["Alice","30"]])
f.append(["Bob","25"])
print(f.read()) # -> [["Name","Age"],["Alice","30"],["Bob","25"]]
Working with Dill (Python objects)
f = file("data.dill")
f.write([1,2,3])
f.append(4)
print(f.read()) # -> [1,2,3,4]
Working with YAML
f = file("config.yaml")
f.write({"setting": True})
f.append({"debug": False})
print(f.read()) # -> {"setting": True, "debug": False}
Working with XML
import xml.etree.ElementTree as ET
f = file("data.xml")
root = ET.Element("root")
f.write(root)
child = ET.Element("child")
root.append(child)
f.append(ET.Element("another_child"))
Working with Binary Files
f = file("data.bin")
f.write(b"Hello")
f.append(b" World")
print(f.read()) # -> b"Hello World"
Working with VariableDB Files
b = 20
f = file("config.db", scope=globals(), data={"a": 10})
f.append(b)
print(f.read()) # -> {"a": 10, "b": 20}
Common Operations
f = file("notes.txt")
print(f.exist()) # True/False
f.copy("/tmp") # Copies file to /tmp
f.move("/tmp") # Moves file to /tmp
f.delete() # Deletes the file
Author
Avi Twil
GitHub: https://github.com/avitwil/ATmulti_file_handler
License
MIT License
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 atmulti_file_handler-2.0.2.tar.gz.
File metadata
- Download URL: atmulti_file_handler-2.0.2.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1144280ab9a79dbe72885bd67c48a203e52844de28983d778bcce0b81aa34f9b
|
|
| MD5 |
bebdcbba681192a1d9e6ec55ef647574
|
|
| BLAKE2b-256 |
49fb7414799004d7d70d4200bddb877d6ebc2c89734213e3a139f0a1aee3c4b0
|
File details
Details for the file atmulti_file_handler-2.0.2-py3-none-any.whl.
File metadata
- Download URL: atmulti_file_handler-2.0.2-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
670854a489bc2e4fb05f04c2ddb8ac1cdd8eda1167750f02b9bcdbb8d70ac92a
|
|
| MD5 |
4ef8ccb4fc5c664b5942375fefb08ee6
|
|
| BLAKE2b-256 |
b3f5699bf176665f44a8fda853037e0f4cb61a4165e98a1cba782fbb18eeb3dd
|