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.5.4.tar.gz (18.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

membank-0.5.4-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: membank-0.5.4.tar.gz
  • Upload date:
  • Size: 18.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for membank-0.5.4.tar.gz
Algorithm Hash digest
SHA256 b14babfa32377616c4c4db715f2a439981332df90f29b9142d0a99130548dc00
MD5 1aeedf4dc6b9f2637df6a3ab741df2a4
BLAKE2b-256 b398476d6783f42fbf918ae75ec4d0f0163ffcf351d971c5f7b031623cc75285

See more details on using hashes here.

File details

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

File metadata

  • Download URL: membank-0.5.4-py3-none-any.whl
  • Upload date:
  • Size: 10.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for membank-0.5.4-py3-none-any.whl
Algorithm Hash digest
SHA256 918fe85cd799be87dccee757870984cf3e2db44014e1005480f22e0a981a0445
MD5 4d61a7e4cb8237d8ad0039eaeabc2b43
BLAKE2b-256 718bf6b01462deb21d86e8e420f65af63880986c76f253749d26a43c123fa052

See more details on using hashes here.

Supported by

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