pmemkv-python - pmemkv-python 1.0
Python bindings for pmemkv
pmemkv is a local/embedded key-value datastore optimized for
persistent memory. For more information, see
https://pmem.io/pmemkv.
Python bindings for pmemkv.
- class
pmemkv.pmemkv.Database(engine, config)
- Bases: object
Main Python pmemkv class, it provides functions to operate on
data in database.
This class can be used dict-like, i.a. accessing and assigning
data using ‘[]’. If an error/exception is thrown from any
method it will contain pmemkv’s status and error message.
Currently returned statuses are described in libpmemkv manpage:
https://pmem.io/pmemkv/master/manpages/libpmemkv.3.html#errors
Possible exceptions to be thrown in Python binding are as
follows: - Error, - UnknownError, - NotSupported, - InvalidArgument, -
ConfigParsingError, - ConfigTypeError, - StoppedByCallback, -
WrongEngineName, - TransactionScopeError.
- __init__(engine, config)
- Parameters
- engine (str) – Name of the engine to work with.
- config (dict) – Dictionary with parameters specified
for the engine. Required configuration parameters are dependent on
particular engine. For more information on engine configuration please
look into pmemkv man pages.
- count_above(key)
- Returns number of currently stored key/value pairs in the pmemkv
datastore, whose keys are greater than the given key.
- Parameters
- key (str) – Sets the lower bound for querying.
- Returns
- number – Number of key/value pairs in the datastore, whose
keys are greater than the given key.
- Return
type
- int
- count_all()
- Returns number of currently stored key/value pairs in the pmemkv
datastore.
- count_below(key)
- Returns number of currently stored key/value pairs in the pmemkv
datastore, whose keys are less than the given key.
- Parameters
- key (str) – Sets the upper bound for querying.
- Returns
- number – Number of key/value pairs in the datastore, whose
keys are lower than the given key.
- Return
type
- int
- count_between(key1,
key2)
- Returns number of currently stored key/value pairs in the pmemkv
datastore, whose keys are greater than the key1 and less than the
key2.
- Parameters
- key1 (str) – Sets the lower bound for querying.
- key2 (str) – Sets the upper bound for querying.
- Returns
- number – Number of key/value pairs in the datastore, between
given keys.
- Return
type
- int
- exists(key)
- Verifies the presence key/value pair in the pmemkv datastore.
- Parameters
- key (str) – key to query for.
- Returns
- exists – true if element with given key exists in the
datastore, false if not.
- Return
type
- bool
- get(key,
func)
- Executes callback function for value for given key.
- Parameters
- key (str) – key to query for.
- func (function (may be lambda))
– Function to be called for specified key/value pair. Value passed
to func is read-only buffer and may be accessed by memoryview function.
Callback function should accept one positional argument, which is value.
Please notice, key is not passed to callback function. For more
information please look into Buffer Protocol documentation.
- get_above(key,
func)
- Executes callback function for every key/value pair stored in the pmemkv
datastore, whose keys are greater than the given key.
- Parameters
- key (str) – Sets the lower bound for querying.
- func (function (may be lambda))
– Function to be called for each specified key/value pair. Key and
value passed to func are read-only buffers and may be accessed by
memoryview function. Callback function should accept two positional
arguments, which are key and value. For more information please look into
Buffer Protocol documentation.
- get_all(func)
- Executes callback function for every key/value pair stored in the pmemkv
datastore.
- Parameters
- func (function (may be lambda))
– Function to be called for each key/value pair in the datastore.
Key and value passed to func are read-only buffers and may be accessed by
memoryview function. Callback function should accept two positional
arguments, which are key and value. For more information please look into
Buffer Protocol documentation.
- get_below(key,
func)
- Executes callback function for every key/value pair stored in the pmemkv
datastore, whose keys are lower than the given key.
- Parameters
- key (str) – Sets the upper bound for querying.
- func (function (may be lambda))
– Function to be called for each specified key/value pair. Key and
value passed to func are read-only buffers and may be accessed by
memoryview function. Callback function should accept two positional
arguments, which are key and value. For more information please look into
Buffer Protocol documentation.
- get_between(key1,
key2, func)
- Executes callback function for every key/value pair stored in the pmemkv
datastore, whose keys are greater than the key1 and less than the
key2.
- Parameters
- key1 (str) – Sets the lower bound for querying.
- key2 (str) – Sets the upper bound for querying.
- func (function (may be lambda))
– Function to be called for each specified key/value pair. Key and
value passed to func are read-only buffers and may be accessed by
memoryview function. Callback function should accept two positional
arguments, which are key and value. For more information please look into
Buffer Protocol documentation.
- get_keys(func)
- Executes callback function for every key stored in the pmemkv
datastore.
- Parameters
- func (function (may be lambda))
– Function to be called for each key. Key passed to func is
read-only buffer and may be accessed by memoryview function. Callback
function should accept one positional argument, which is key. For more
information please look into Buffer Protocol documentation.
- get_keys_above(key,
func)
- Executes callback function for every key stored in the pmemkv datastore,
whose keys are greater than the given key.
- Parameters
- key (str or byte-like object) – Sets
the lower bound for querying.
- func (function (may be lambda))
– Function to be called for each key above one specified in key
parameter. Key passed to func is read-only buffer and may be accessed by
memoryview function. Callback function should accept one positional
argument, which is key. For more information please look into Buffer
Protocol documentation.
- get_keys_below(key,
func)
- Executes callback function for every key stored in the pmemkv datastore,
whose keys are lower than the given key.
- Parameters
- key (str or byte-like object) – Sets
the upper bound for querying.
- func (function (may be lambda))
– Function to be called for each key below one specified in key
parameter. Key passed to func is read-only buffer and may be accessed by
memoryview function. Callback function should accept one positional
argument, which is key. For more information please look into Buffer
Protocol documentation.
- get_keys_between(key1,
key2, func)
- Executes callback function for every key stored in pmemkv datastore, whose
keys are greater than the key1 and less than the key2.
- Parameters
- key1 (str or byte-like object) – Sets
the lower bound for querying.
- key2 (str) – Sets the upper bound for querying.
- func (function (may be lambda))
– Function to be called for each key between key1 and key2. Key
passed to func is read-only buffer and may be accessed by memoryview
function. Callback function should accept one positional argument, which
is key. For more information please look into Buffer Protocol
documentation.
- get_string(key)
- Gets copy (as a string) of value for given key.
Value returned by get_string() is still accessible after
removal of element from datastore.
- put(key,
value)
- Inserts the key/value pair into the pmemkv datastore. This method accepts
Unicode objects as well as bytes-like objects. Unicode objects are stored
using ‘utf-8’ encoding.
- Parameters
- key (str or byte-like object) –
record’s key; record will be put into database under its name.
- value (str or byte-like object) – data
to be inserted into this new datastore record.
- remove(key)
- Removes key/value pair from the pmemkv datastore for given key.
- Parameters
- key (str) – Record’s key to query for, to be
removed.
- Returns
- removed – true if element was removed, false if element
didn’t exist before removal.
- Return
type
- bool
- stop()
- Stops the running engine.
Readme file can be found here.