Skip to main content

A fast, easy and complete file and directory management library

Project description

Geraci

A fast, easy and complete file and directory management library for Python.

pip install geraci

Quick Start

from geraci import File, Folder

# Read and write files
f = File("note.txt")
f.write("Hello, World!").append("\nSecond line")
print(f.read())

# Chain operations
f.copy("backup.txt").rename("backup_old.txt")

# File info with hash
info = File("note.txt").info()
print(info.size_human, info.hash_sha256)

# List and search
folder = Folder("my_project")
for py_file in folder.glob("**/*.py", exclude="test_*"):
    print(py_file)

# File locking
with File("data.json").lock():
    f.write('{"key": "value"}')

# Compress / extract
File("document.pdf").compress("docs.zip")
Folder("photos").compress("photos.tar.gz")

Features

  • File operations: read, write, append, copy, move, rename, delete
  • Folder operations: create, delete, list, walk, size
  • Glob searching: pattern matching with exclusions
  • File watching: watchdog integration with callbacks
  • Sync/Backup: incremental folder sync with hash comparison
  • Compression: zip, tar, tar.gz, gz, bz2
  • Locking: cross-platform file locking
  • Async support: all operations available as async
  • Metadata: file info, hash, size formatting
  • Logging: configurable logging system
  • No dependencies beyond watchdog and portalocker

File Class

Method Description Returns
read() Read file content str
write(content) Write to file self
append(content) Append to file self
copy(dst) Copy file File (new)
move(dst) Move file self
rename(name) Rename file self
delete() Delete file None
compress(archive) Compress file self
lock() Lock file FileLock (ctx)
info() File metadata FileInfo
exists() Check existence bool
aread() Async read await str
awrite(content) Async write await self
acopy(dst) Async copy await File
amove(dst) Async move await self
adelete() Async delete await None

Folder Class

Method Description Returns
create() Create directory self
delete(recursive) Delete directory None
list(recursive) List contents `List[File
walk() Walk recursively `Iterator[File
glob(pattern, exclude) Search files List[File]
sync(dst) Sync to destination self
watch(...) Watch for changes Observer
compress(archive) Compress folder self
size() Total size int
exists() Check existence bool

Standalone Functions

from geraci import read_file, write_file, copy_file, move_file
from geraci import glob_files, watch_folder, sync_folders
from geraci import compress_file, decompress

Async

from geraci import aread, awrite, acopy, amove, aglob

content = await aread("file.txt")
await awrite("file.txt", "new content")
files = await aglob("src", "**/*.py")

Watchdog

from geraci import watch_folder

def handler(event):
    print(f"{event.event_type}: {event.src_path}")

observer = watch_folder("input/", on_created=handler, on_modified=handler)
# observer.stop() to stop

Or use the FileWatcher class:

from geraci import FileWatcher

watcher = FileWatcher("data/").start()
watcher.on_event(lambda e: print(e))
# watcher.stop()

Logging

from geraci import configure_logging

configure_logging(level="DEBUG", file="geraci.log")

License

MIT

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

geraci-2.0.0.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

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

geraci-2.0.0-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

Details for the file geraci-2.0.0.tar.gz.

File metadata

  • Download URL: geraci-2.0.0.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for geraci-2.0.0.tar.gz
Algorithm Hash digest
SHA256 97515d5df3db36c91aacdf26eae9f5526cdeb4e47a7afc72c07a8f4b3b297e5e
MD5 9277c5341fe02e79eb570953b0ba85d5
BLAKE2b-256 b486053b7601348384b4dcd763bff6a3a1c3f2fc30a7dd38d69f008d3368fb87

See more details on using hashes here.

File details

Details for the file geraci-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: geraci-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 13.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for geraci-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 94812fb62ab967c0bcbe7cf09a89b938bdc28addae21ddd6d9b17b8a4d295dd3
MD5 10eebbd049a0224b5b0557da3c7b8830
BLAKE2b-256 0f4393be605fec72f005a5718b4a517cfbe8dde4a99e4ee45939857a4d79bb99

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