Skip to main content

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 File base class with consistent interface.
  • Format-specific subclasses:
    • TxtFile.txt
    • JsonFile.json
    • CsvFile.csv
    • DillFile.dill
    • XmlFile.xml
    • YamlFile.yml / .yaml
    • ByteFile.bin / .exe / .img / .jpg
    • VarDBFile.db (requires avi_tools package)
  • 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

atmulti_file_handler-2.0.2.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

atmulti_file_handler-2.0.2-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

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

Hashes for atmulti_file_handler-2.0.2.tar.gz
Algorithm Hash digest
SHA256 1144280ab9a79dbe72885bd67c48a203e52844de28983d778bcce0b81aa34f9b
MD5 bebdcbba681192a1d9e6ec55ef647574
BLAKE2b-256 49fb7414799004d7d70d4200bddb877d6ebc2c89734213e3a139f0a1aee3c4b0

See more details on using hashes here.

File details

Details for the file atmulti_file_handler-2.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for atmulti_file_handler-2.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 670854a489bc2e4fb05f04c2ddb8ac1cdd8eda1167750f02b9bcdbb8d70ac92a
MD5 4ef8ccb4fc5c664b5942375fefb08ee6
BLAKE2b-256 b3f5699bf176665f44a8fda853037e0f4cb61a4165e98a1cba782fbb18eeb3dd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page