A library for reading and writing hierarchical data files
Project description
richfile
A more natural approach to saving hierarchical data structures.
richfile
saves any Python object into directory structures on disk, and loads them back into Python objects.\
Saving is simple:
import as rf
data = {
"name": "John Doe",
"age": 25,
"address": {
"street": "1234 Elm St",
"zip": 62701
},
"siblings": [
"Jane",
"Jim"
],
"data": np.array([1,2,3]),
(1,2,3): "complex key",
}
r = rf.RichFile("path/to/data.richfile").save(data)
Loading is simple:
import as rf
r = rf.RichFile("path/to/data.richfile")
data = r.load()
You can also load just a part of the data:
import as rf
r = rf.RichFile("path/to/data.richfile")
sibling = r["siblings"][0]
View the contents of a richfile directory without loading it:
import as rf
r = rf.RichFile("path/to/data.richfile")
r.view_tree()
## OR
r.view_directory_structure()
Installation
pip install richfile
or from source:
pip install git+https://github.com/RichieHakim/richfile.git
Examples
Try out the examples in the demo_notebook.ipynb file. Turns this Python object:
data = {
"name": "John Doe",
"age": 25,
"address": {
"street": "1234 Elm St",
"zip": None
},
"siblings": [
"Jane",
"Jim"
],
"data": np.array([1,2,3]),
(1,2,3): "complex key",
}
Into a directory structure that looks like this:
Directory structure:
Viewing tree structure of richfile at path: ~/path/data.richfile (dict)
├── name.dict_item (dict_item)
| ├── key.json (str)
| ├── value.json (str)
|
├── age.dict_item (dict_item)
| ├── key.json (str)
| ├── value.json (int)
|
├── address.dict_item (dict_item)
| ├── key.json (str)
| ├── value.dict (dict)
| | ├── street.dict_item (dict_item)
| | | ├── key.json (str)
| | | ├── value.json (str)
| | |
| | ├── zip.dict_item (dict_item)
| | | ├── key.json (str)
| | | ├── value.json (None)
| | |
| |
|
├── siblings.dict_item (dict_item)
| ├── key.json (str)
| ├── value.list (list)
| | ├── 0.json (str)
| | ├── 1.json (str)
| |
|
├── data.dict_item (dict_item)
| ├── key.json (str)
| ├── value.npy (numpy_array)
|
├── 5.dict_item (dict_item)
| ├── key.tuple (tuple)
| | ├── 0.json (int)
| | ├── 1.json (int)
| | ├── 2.json (int)
| |
| ├── value.json (str)
|
TODO:
- Tests
- Documentation
- Examples
- Readme
- License
- PyPi
-
Hashing -
Item assignment (safely) - Custom saving/loading functions
-
Put the library imports in the function calls - Add handling for data without a known type
- Change name of library to something more descriptive
- Test out memmap stuff
-
Make it a .zip type
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
richfile-0.2.0.tar.gz
(17.9 kB
view hashes)
Built Distribution
richfile-0.2.0-py3-none-any.whl
(16.8 kB
view hashes)