Leaf is a small (just two .py files) on-demand hierachical filesystem database.
Project description
LEAF
Leaf is a small (just two .py files) in-memory on-demand graph filesystem database.
Example usage:
import os
import shutil
from leaf import DirectoryObject
from src.leaf import FileObject
root_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'files')
os.mkdir(root_dir)
root = DirectoryObject(root_dir)
directory: DirectoryObject = root.add_directory('test')
print(os.path.isdir(os.path.join(root_dir, 'test'))) # True
f1: FileObject = directory.add_file('first_file.json')
f2: FileObject = directory.add_file('second_file.json')
print(os.path.isfile(os.path.join(root_dir, 'test', 'first_file.json'))) # True
# Find a file recursively
f3: FileObject | None = root.first_or_default(lambda o: o.name == 'first_file.json', recursive=True)
print(f1 == f3) # True
# Get children
for children in directory.children:
print(children)
# FILE: D:\PycharmProjects\leaf\leaf\src\files\test\first_file.json
# FILE: D:\PycharmProjects\leaf\leaf\src\files\test\second_file.json
# Get descendants
for desc in root.descendants:
print(desc)
# DIRECTORY: D:\PycharmProjects\leaf\leaf\src\files\test
# FILE: D:\PycharmProjects\leaf\leaf\src\files\test\first_file.json
# FILE: D:\PycharmProjects\leaf\leaf\src\files\test\second_file.json
# Write contents
f1.write_string('hello')
print(f1.read_string())
# hello
shutil.rmtree(root_dir)
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
leaf_BasedLabs-0.0.1.tar.gz
(4.4 kB
view details)
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 leaf_BasedLabs-0.0.1.tar.gz.
File metadata
- Download URL: leaf_BasedLabs-0.0.1.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c7e174f8a057096ae2dfd8cfef70cf712d8820510be917a8be0329c283abfe1f
|
|
| MD5 |
998ae4b05c04b8518c4ff1577cab8cf7
|
|
| BLAKE2b-256 |
1c4348468507fd71379565004e18d5125dbf1617cb746b42134ab8bb0809b11e
|
File details
Details for the file leaf_BasedLabs-0.0.1-py3-none-any.whl.
File metadata
- Download URL: leaf_BasedLabs-0.0.1-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b14afb3eaca573ecb6dd1c14ca1c49c008d7c462a7fbbaef5ade2218897794c1
|
|
| MD5 |
2a03a6cc3068a383494c29189a9e10f9
|
|
| BLAKE2b-256 |
e7a7305be3c3b6d9a141de54ac1226e3a58cc49dcc8632a11627dcffb0fad100
|