Data exchange and persistence
This project is part of the Pyrustic Open Ecosystem.
Shared is a Python package created to be the programmer's companion when it comes to storing unstructured application data, managing configuration files, caching data, and exchanging data with other programs.
Under the hood, Shared uses Paradict to encode a dictionary populated with strings, scalars (integer, float, decimal float, complex, booleans), date and time, null value, binary data and nested collections (list, set, and dictionary).
Note: This library isn't intended to replace a proper relational database such as SQLite !
from shared import Dossier, HOME
from datetime import datetime
from pathlib import Path
# load a picture
with open("/home/alex/image.png", "rb") as file:
photo = file.read()
# create a user profile dictionary embedding the picture
now = datetime.now()
profile = {"name": "alex", "access_datetime": now, "photo": photo,
"pi": 3.14, "books": ["Seul sur Mars", "The Fall"],
"is_author": True, "fingerprint": None}
# create a dossier (or access an existing one)
path = Path(HOME, "my_dossier")
dossier = Dossier(path)
# save profile dictionary in the dossier
dossier.set("my_profile", profile)
# retrieve profile dictionary
profile_bis = dossier.get("my_profile")
# let's compare the two profile objects !
assert profile == profile_bis
Explore the source code.
Shared is cross platform. It is built on Ubuntu with Python 3.8 and should work on Python 3.5 or newer.
python -m venv venv
source venv/bin/activate
pip install shared
pip install shared --upgrade --upgrade-strategy eager
deactivate
Hi, I'm Alex, a tech enthusiast ! Get in touch with me !