Skip to main content

Leaf is a small (just two .py files) on-demand hierachical filesystem database.

Project description

LEAF

Leaf is a small (just two .py files) on-demand hierachical filesystem database.

Install

pip install leaf-BasedLabs

Example usage

import os
import shutil

from leaf import DirectoryObject, 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


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.8.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

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

leaf_BasedLabs-0.0.8-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file leaf_BasedLabs-0.0.8.tar.gz.

File metadata

  • Download URL: leaf_BasedLabs-0.0.8.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.12

File hashes

Hashes for leaf_BasedLabs-0.0.8.tar.gz
Algorithm Hash digest
SHA256 9aec00649ea806b06b336f862947c5e15a90e5dd52ea1b1e5541d07df907b1a4
MD5 7d18472b1bf188a126106b3acdd4e76c
BLAKE2b-256 2e9a2a7383e56ad04508608b0c24f76c9a43d7e721a36fc0fe3e4e2907bb19ff

See more details on using hashes here.

File details

Details for the file leaf_BasedLabs-0.0.8-py3-none-any.whl.

File metadata

  • Download URL: leaf_BasedLabs-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.12

File hashes

Hashes for leaf_BasedLabs-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 8d188cb28db993de1accd6fc97708869dde038270ac5e938e72c89765375d7ca
MD5 59c9b7d448922ec404cc542cb8840bb3
BLAKE2b-256 b1f5ef0fe7e3bbac427d0c59f22a72dc2f8f4a95754f08e5226e7f6d0c64882a

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