Metatree is a DBMS that uses the filesystem itself as a tree-structured database.
Project description
metatreedb
Metatree is a DBMS that uses the filesystem itself to organize and manage data in a tree-structured format.
In metadata.json in each tree node, you can manage information about child nodes, which can also be used for searching.
Features
- metadata-based index
- db-level concurrency control
- flexible filesystem support
- local
- HDFS
- http
- proper customization is required
Installation
pip install metatreedb
Quick Start
Here's an example of using Metatree as a model repository by setting up a database with (model_name, version,) as identifiers:
from metatree import Metatree
metatree = Metatree(
"/tmp/my-model-repository",
(
"model",
"version",
),
)
import uuid
import pickle
from pathlib import Path
for i in range(1, 4):
awful_uuid = uuid.uuid4()
trained = Path("/tmp/my-model-repository/trained.pkl")
with open(trained, "wb") as f:
pickle.dump(awful_uuid, f)
metatree.put(f"my-awful-model/v{i}", trained)
This will create files and directories in your filesystem as shown:
❯ tree /tmp/my-model-repository
/tmp/my-model-repository
├── metadata.json
└── my-awful-model
├── metadata.json
├── v1
│ ├── metadata.json
│ └── trained.pkl
├── v2
│ ├── metadata.json
│ └── trained.pkl
└── v3
├── metadata.json
└── trained.pkl
To add metadata information, use find and update:
metatree.find("my-awful-model")
metatree.update(active="v2")
for i in range(1, 4):
metatree.find(f"my-awful-model/v{i}").update(model_file="trained.pkl")
This will update the metadata.json files as follows:
❯ cat /tmp/my-model-repository/my-awful-model/metadata.json
{"children": ["v1", "v2", "v3"], "active": "v2"}
❯ cat /tmp/my-model-repository/my-awful-model/v*/metadata.json
{"model_file": "trained.pkl"}
{"model_file": "trained.pkl"}
{"model_file": "trained.pkl"}
You can use this search index to find files. By enclosing the keys from metadata.json within angle brackets <> and substituting them in location, you can perform searches as follows:
metatree.find("my-awful-model/<active>")
print(metatree.location)
# This returns `file:///tmp/my-model-repository/my-awful-model/v2
file = metatree.get("my-awful-model/<active>/<model_file>")
print(file)
# The given path translates to `my-awful-model/v2/trained.pkl`,
# and it returns generator object
with WebHDFS
To use WebHDFS, set the root path to the WebHDFS URL and provide a client with the necessary permissions:
from metatreedb import Metatree
from hdfs import InsecureClient
metatree = Metatree(
"webhdfs://localhost:9870/tmp/my-model-repository",
("model", "version"),
client=InsecureClient("http://localhost:9870", user="hadoop"),
)
with S3
To use S3, set the root path to the S3 bucket URL and provide a boto3 client with the necessary permissions:
from metatreedb import Metatree
import boto3
s3_client = boto3.client(
"s3",
region_name="us-east-1",
endpoint_url="http://localhost:3000", # Tested with moto package.
aws_access_key_id="your-access-key-id",
aws_secret_access_key="your-secret-access-key",
)
metatree = Metatree(
"s3://localhost:3000/tmp/my-model-repository",
("model", "version"),
client=s3_client,
s3_bucket="your-s3-bucket-name",
)
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
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 metatreedb-0.1.8.tar.gz.
File metadata
- Download URL: metatreedb-0.1.8.tar.gz
- Upload date:
- Size: 8.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
86b4803eea7b3a2124872764a21412ec480b1e09edbb9743008e77240ee60e3c
|
|
| MD5 |
0a70a3dcbf9963a3ce5a266e86303675
|
|
| BLAKE2b-256 |
7331688d1f76ee92b8bed880a33ae19ddf255b1bf1edfa8a3d42279067689288
|
File details
Details for the file metatreedb-0.1.8-py3-none-any.whl.
File metadata
- Download URL: metatreedb-0.1.8-py3-none-any.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6f78f5460cae0c86d2af9dba9c579c613a590182d69714b6120e0c16b303353c
|
|
| MD5 |
c1fe16d98ea7e1ddfb107e7eb92255e4
|
|
| BLAKE2b-256 |
b3a30d8383ba6e3753839c710a33cebdf142408386f92cf6bea7ad8028754bde
|