pmemkv.pmemkv module¶
Python bindings for pmemkv.
-
class
pmemkv.pmemkv.
Database
(engine, config)[source]¶ 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)[source]¶ 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)[source]¶ 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
()[source]¶ Returns number of currently stored key/value pairs in the pmemkv datastore.
Returns: number – Total number of elements in the datastore. Return type: int
-
count_below
(key)[source]¶ 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)[source]¶ 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)[source]¶ 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)[source]¶ 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)[source]¶ 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)[source]¶ 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)[source]¶ 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)[source]¶ 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)[source]¶ 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)[source]¶ 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)[source]¶ 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)[source]¶ 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)[source]¶ Gets copy (as a string) of value for given key.
Value returned by get_string() is still accessible after removal of element from datastore.
Parameters: key (str) – key to query for. Returns: value – Copy of value associated with the given key. Return type: str or byte-like object
-
put
(key, value)[source]¶ 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.
-