Storage

Persistent data storage objects. These objects will act like normal built-in data types, except all data will be saved to disk for later access when flushed.

class codequick.storage.PersistentDict(name, ttl=None)[source]

Persistent storage with a dictionary like interface.

Parameters:
  • name (str) – Filename or path to storage file.
  • ttl (int) – [opt] The amount of time in “seconds” that a value can be stored before it expires.

Note

name can be a filename, or the full path to a file. The add-on profile directory will be the default location for files, unless a full path is given.

Note

If the ttl parameter is given, “any” expired data will be removed on initialization.

Note

This class is also designed as a “Context Manager”.

Note

Data will only be synced to disk when connection to file is “closed” or when “flush” method is explicitly called.

Example:
>>> with PersistentDict("dictfile.pickle") as db:
>>>     db["testdata"] = "testvalue"
>>>     db.flush()
flush()

Synchronize data back to disk.

Data will only be written to disk if content has changed.

close()

Flush content to disk & close file object.

items() → a set-like object providing a view on D's items[source]
class codequick.storage.PersistentList(name, ttl=None)[source]

Persistent storage with a list like interface.

Parameters:
  • name (str) – Filename or path to storage file.
  • ttl (int) – [opt] The amount of time in “seconds” that a value can be stored before it expires.

Note

name can be a filename, or the full path to a file. The add-on profile directory will be the default location for files, unless a full path is given.

Note

If the ttl parameter is given, “any” expired data will be removed on initialization.

Note

This class is also designed as a “Context Manager”.

Note

Data will only be synced to disk when connection to file is “closed” or when “flush” method is explicitly called.

Example:
>>> with PersistentList("listfile.pickle") as db:
>>>     db.append("testvalue")
>>>     db.extend(["test1", "test2"])
>>>     db.flush()
flush()

Synchronize data back to disk.

Data will only be written to disk if content has changed.

close()

Flush content to disk & close file object.

insert(index, value)[source]

S.insert(index, value) – insert value before index

append(value)[source]

S.append(value) – append value to the end of the sequence