Skip to main content

rstore

General purpose store for key/value pairs, time series and event sequences with optional encryption.

Values are encrypted as soon as the key argument is specified with Store(). Alternatively, the key can be fixed for the store by setting Store._key. The same store can be used in encrypted and unencrypted mode. Note: Keys must be of type ``str`` and are never encrypted.

Different backends are available for persistence. The backend is selected by the dsn argument of Store():

  • PostgreSQL database: dsn='postgresql://localhost'

  • Redis server: dsn='redis://localhost'

  • SQLite data file: dsn='sqlite://datafile.db'

Different namespaces can be used within a single store. The namespace is selected with the namespace argument of Store() or by setting Store._namespace. If no namespace is selected it defaults to default.

Values are stored using the pickle module (before encryption). This behavior can be changed by subclassing Store and overwriting _dump and _load. For example:

class JsonStore(Store):
    def _dump(self, value):
        return json.dumps(value)
    def _load(self, data):
        return json.loads(data)

Key/value

Functions for the key/value store include: set, get, delete, has, and keys. The k/v store can also be used in a dict-like fashion with s[k], del s[k], k in s, and len(s).

with Store('file.name', frozen=False) as kv:
    kv.set('some_key', value)
    value = kv.get('some_key')
    del kv['some_key']

Time series

Time series are key/value pairs where the value changes over time. Each value change (or data point) is recorded with a timestamp. The timestamp is an arbitrary int value and its meaning must be determined by the application. An even frequency between the timestamps is optional.

Functions for time series include: range, first, last, missing, iscomplete, extend, remove, and timeseries.

with Store('file.name', frozen=False) as ts:
    ts.extend('some_series', (timestamp1, value1), ...)
    timestamp, value = ts.last('some_series')
    ts.remove('some_series')

Event sequences

Event sequences are key/dict pairs where each change to the dict is recorded as an event. Events are stored as tuple (timestamp, item, op, value) where:

  • timestamp is the POSIX timestamp in milliseconds when the event was recorded (type int)

  • item is the name of the dict member (type str)

  • op is the operator to apply to the dict member (operator.setitem, operator.delitem, operator.add, …)

  • value is the value to apply to the dict member (or None for unary operators such as operator.delitem)

Functions for event sequences include: current, past, apply, prune, events, and eventsources.

with Store('file.name', frozen=False) as es:
    es.apply('some_dict', {'item': 1})       # op defaults to operator.setitem
    es.apply('some_dict', {'item': (operator.add, 1)})
    es.events('some_dict') == [(timestamp, 'item', operator.setitem, 1), (timestamp, 'item', operator.add, 1)]
    es.current('some_dict') == {'item': 2}
    es.prune('some_dict', remove=True)

Installation

$ pip install rlib-store

Getting Started

from rstore import Store

Check the doc strings and unit tests for examples.

License

“MIT”. See LICENSE for details. Copyright t5w5h5@gmail.com, 2018.

Metadata

Release files for rlib-store 0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rlib-store 0.1
File Size Uploaded Provenance Actions
rlib-store-0.1.tar.gz 11.5 kB Without provenance Details for rlib-store-0.1.tar.gz

Release files / rlib-store-0.1.tar.gz

Download URL rlib-store-0.1.tar.gz
Size 11.5 kB
Tags Source
SHA-256 checksum
How to use checksums
64e35aa3fa33418b24e483463e4b5f8c0d13906a26ef4bd440f9728a65ab99c3
BLAKE2b-256 checksum
How to use checksums
fc0f0a645d82630560a77bec64672091bec23f3039beb7f4eb69571284f7a80e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for rlib-store 0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page