Skip to main content

A library to handle persistent memory

Project description

membank

Python library for storing data in persistent memory (sqlite, postgresql, berkeley db)

goals

Provide interface to database storage that automates heavy lifting of database setup, migration, table definition, query construction.

quick intro

add items to persistent storage

import dataclasses as data # Python standard library

from membank import LoadMemory

@data.dataclass
class Dog():
    breed: str
    color: str = "black"
    weight: float = 0
    data: dict = data.field(default_factory=dict)
    picture: bytes = b''
    aliases: list = data.field(default_factory=list)

@data.dataclass
class DogWithID():
    id: str = data.field(default=None, metadata={"key": True})
    breed: str
    color: str = "black"
    weight: float = 0
    data: dict = data.field(default_factory=dict)
    picture: bytes = b''
    alive: bool = True

memory = LoadMemory() # defaults to sqlite memory
memory.put(Dog('Puli')) # stores object into database
dog = memory.get.dog() # retrieves first object found
assert dog.breed == 'Puli'
dog.color = "white"
memory.put(dog) # be carefull you store another dog
dog = memory.put(DogWithID("AB1234", "Puli"))
dog = memory.get.dogwithid(id="AB1234")
dog.color = "white"
memory.put(dog) # now you update existing dog

retrieve those after

memory = LoadMemory() # to make this work in new process, don't use sqlite memory
dog = memory.get.dog() # get first found or None
assert dog.color == 'black'
dogs = memory.get("dog") # always returns list (empty or with items)
assert len(dogs) >= 0

editing returned objects

dog = memory.get.dog()
dog.breed = 'Labdrador'
memory.put(dog) # stores edited object back

filter objects

dog = memory.get.dog(breed='Labdrador')
assert dog.breed == 'Labrador'

Known issues

  • return class is stored(pickled) into underlying database table with reference to the module to load it back. If module name or class name is changed, membank won't always be able to load previous data as object pointer could be missing

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

membank-0.4.2.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

membank-0.4.2-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file membank-0.4.2.tar.gz.

File metadata

  • Download URL: membank-0.4.2.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.0

File hashes

Hashes for membank-0.4.2.tar.gz
Algorithm Hash digest
SHA256 a8318722d36b6b870a43857c27b2d902371193bad9a7872a60b2f13a661769ad
MD5 11aa2694a8344570bb65e04a84d87ffe
BLAKE2b-256 0f0b09e69d41d4bf63ac508af85dcf24744885da33409e2329919dea406f56a7

See more details on using hashes here.

File details

Details for the file membank-0.4.2-py3-none-any.whl.

File metadata

  • Download URL: membank-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.0

File hashes

Hashes for membank-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9ad335fd03a55cb85a232a6aaa68beb09a56915e6d8941200af9b15e535b4a67
MD5 a69ea2c49e110f564b2540001a483f4d
BLAKE2b-256 2146c9722f862f8f6901f076a59201a779f2f91b11dae793f8490813b6bb43c0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page