Filesystem-based key-value stores¶
A straightforward implementation is a filesystem-based implementation found in
simplekv.fs.FilesystemStore
class, as well as a slightly altered
version suitable for web applications, simplekv.fs.WebFilesystemStore
.
-
class
simplekv.fs.
FilesystemStore
(root, perm=None, **kwargs)¶ Store data in files on the filesystem.
The FilesystemStore stores every value as its own file on the filesystem, all under a common directory.
Any call to
url_for()
will result in a file://-URL pointing towards the internal storage to be generated.
-
class
simplekv.fs.
WebFilesystemStore
(root, url_prefix, **kwargs)¶ FilesystemStore that supports generating URLs suitable for web applications. Most common use is to make the root directory of the filesystem store available through a webserver. Example:
>>> from simplekv.fs import WebFilesystemStore >>> webserver_url_prefix = 'https://some.domain.invalid/files/' >>> webserver_root = '/var/www/some.domain.invalid/www-data/files/' >>> store = WebFilesystemStore(webserver_root, webserver_url_prefix) >>> print(store.url_for('some_key')) https://some.domain.invalid/files/some_key
Note that the prefix is simply prepended to the relative URL for the key. It therefore, in most cases, must include a trailing slash.
url_prefix may also be a callable, in which case it gets called with the filestore and key as an argument and should return an url_prefix.
>>> from simplekv.fs import WebFilesystemStore >>> webserver_url_prefix = 'https://some.domain.invalid/files/' >>> webserver_root = '/var/www/some.domain.invalid/www-data/files/' >>> prefix_func = lambda store, key: webserver_url_prefix >>> store = WebFilesystemStore(webserver_root, prefix_func) >>> print(store.url_for('some_key')) https://some.domain.invalid/files/some_key