A simple, light, easy-to-use, and extensible memory module
Project description
Xmem
Simple to use, extensible key-based storage module.
Built around python dictionary.
How to install
pip install xmem
Sample
from xmem import MemoryEngine
# for json based storage
from xmem.templates import JsonTemplate
# or for pickle based storage
from xmem.templates import PickleTemplate
# instantiate memory using save :location and :template instance
# location may be str, or pathlib.Path object
memory = MemoryEngine('data', JsonTemplate())
# optional: register save to python script exit event
memory.save_atexit()
CRUD
Create, Update
Create and update is handled using same functions.
put, putall
If key doesnt exist it would be created, else the value updated.
# add or update memory using :put
# method :put may be chained
memory\
.put('One', 1)\
.put('Two', 2)
# or by using :putall
memory.putall({
'three': 3,
'Four': 4
})
Read
# read from memory using :get
two = memory.get('Two')
# output: 2
Delete
# delete keys using :delete
memory.delete('Two', 'Four')
# or clear the whole memory using :clear
memory.clear()
Method :delete takes one or more keys as parameters
Create a template
A template has two methods that need to be overwridden
def save(self, data: dict):
...
def load(self) -> dict:
...
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
xmem-0.1.0.tar.gz
(5.4 kB
view details)
File details
Details for the file xmem-0.1.0.tar.gz.
File metadata
- Download URL: xmem-0.1.0.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2412d720bb9015bb1ddafd070a67c4eab26dd738b14d3c52c910fdf91044e433
|
|
| MD5 |
39ae7c8c1aac280aa1ba8eb182e76e11
|
|
| BLAKE2b-256 |
1ac8d8fa0773482c375901393bccda8095ca732a53f2cfe32d8d0260f2819f70
|