A simple, reactive local storage library.
Project description
Stora
Stora is a simple, reactive local storage library.
>>> from stora import stora
>>> apple = {"name": "Apple", "price": "10", "size": "small"}
>>> s = stora(apple)
>>> s.state
'{"name": "Apple", "price": "10", "size": "small"}'
>>> s.file
'/home/user/project/state.json'
>>> s.state["size"] = "middle"
>>> s.state
'{"name": "Apple", "price": "10", "size": "middle"}'
Stora allows you to save dict to local as json extremely easily. There’s no need to manually open file and read, or save file after change your dict data — but nowadays, just editor the state, and Stora will automatically save for you!
Stora is a new Python package, welcome issue and pull request.
Installing Stora and Supported Versions
Stora is available on PyPI:
$ python3 -m pip install stora
Stora only support Python 3.6+.
Supported Features & Best–Practices
Stora is ready for simple data storage.
if you need high performance, use a professional database is a better choice.
- Data persistence saving.
- Synchronize data saving to local.
- Customizable file names.
- Customize the save directory.
- Save format is json by default.
- Read format is dict by default.
- TODO Save files asynchronously
- TODO Debounce function
Quick Start
Stora will save data as state.json
in current working directory.
from stora import stora
apple = {"name": "Apple", "price": "10", "size": "small"}
s = stora(apple)
print(s.state) # {"name": "Apple", "price": "10", "size": "small"}
PS: You can also decide the filename and filepath.
s = stora(apple, filename='apple.json', filepath='~/.data/')
Now open state.json
, you will see:
{
"name": "Apple",
"price": "10",
"size": "small"
}
Next time when you initialize a stora class in the same working directory, Stora will search if there is a file called state.json
, if it exists it will load it and return a reactive dict.
from stora import stora
s = stora() # Stora will search state.json and load it
print(s.state) # {"name": "Apple", "price": "10", "size": "small"}
PS: If the filename and filepath are specified, use the following code to initialize it.
s = stora(filename='apple.json', filepath='~/.data/')
Fetching and assignment operations are exactly the same as dict.
# Fetching
print(s.state['name']) # Apple
print(s.state['price']) # 10
# Assignment
s.state['name'] = 'Banana'
s.state['price'] = 20
Now you will see that the contents of the state.json
have changed.
{
"name": "Banana",
"price": "20",
"size": "small"
}
Here's a feature that may cause confusion. If initialize stora again,
from stora import stora
apple = {"name": "Apple", "price": "10", "size": "small"}
s = stora(apple)
print(s.state) # {"name": "Banana", "price": "20", "size": "small"}
run print(s.state)
, you will find the data is not what you assign to stora, it's data saved in state.json
.
That's because stora sets the data already read under the current filepath and filename to a higher priority in order to prevent data loss.
You can force an overwrite of the stora state, or define a new stora with different filename or filepath.
s1 = stora(apple, force=True) # force an overwrite
s2 = stora(apple, filename='apple-10.json') # define a new stora with different filename or filepath
API Reference and User Guide available on Read the Docs
Coming soon.
Cloning the repository
git clone https://github.com/louisyoungx/stora.git
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
File details
Details for the file stora-0.0.3.tar.gz
.
File metadata
- Download URL: stora-0.0.3.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.0 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b4f697e46b8f5029f13a768bed246969be83c0c90c603dc986a792c6106bf72 |
|
MD5 | 47bbdf96329275c0997d2a420c71c649 |
|
BLAKE2b-256 | b8d03cc75e35f3fc1b5ee5b47ce1f61c1c5a7ddada6673dd1a060d8a9f310835 |
File details
Details for the file stora-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: stora-0.0.3-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.0 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e9ea300c9b6b0b56f6642c478b0f521ea762a253216cfe524761b1df823fe90 |
|
MD5 | 83fe164976064fc4d882efb7384990c0 |
|
BLAKE2b-256 | ac51964ef9831d5c1e27c8a4febefb8b91f7b52a0a1f734f939a03e17e560853 |