https://github.com/user0332/declarativefs
A Python library for declaring and serializing filesystem structures declaratively
https://github.com/user0332/declarativefs
Last synced: 9 months ago
JSON representation
A Python library for declaring and serializing filesystem structures declaratively
- Host: GitHub
- URL: https://github.com/user0332/declarativefs
- Owner: User0332
- License: mit
- Created: 2025-04-17T20:02:12.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-17T20:42:15.000Z (about 1 year ago)
- Last Synced: 2025-04-18T11:02:21.362Z (about 1 year ago)
- Language: Python
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DeclarativeFS
A Python library for declaring and serializing filesystem structures declaratively.
Currently, `declarativefs` supports creating basic filesystem structures using a declarative, tree-like syntax.
Configuration/object deserialization/data loading support may be added in the future.
Filesystem schema validation support may be added in the future.
### Example: Creating a Complex Filesystem Structure
```py
import json
import pickle
from declarativefs import *
structure = Directory(
name="test",
children=[
Directory(name="subdir"),
File(
name="text.txt",
content="some text content"
),
File(
name="data.json",
content={
"key": "value",
"num": 12,
"nested": {
"values": [12, 6, None, False, "hello"],
"true": False
}
},
content_serializer=lambda obj: json.dumps(obj, indent=1)
),
File(
name="pickled.obj",
content=object(),
content_serializer=pickle.dumps
)
]
)
structure.serialize(force=True)
```
The above code will result in a structure that looks like the following:
```
test/
├── subdir/
├── text.txt (contains ASCII text)
├── data.json (contains JSON data)
└── pickled.obj (contains a pickled Python object)
```