nosqlapi key-value

In this package we find abstract classes and ODM classes concerning the Key-Value database types.

client module

The client module contains the specific classes for key-value databases and they are based on the core classes.

Client module for key-value NOSQL database.

class nosqlapi.kvdb.client.KVBatch(batch, session=None)[source]

Bases: nosqlapi.common.core.Batch, abc.ABC

Key-value NOSQL database Batch class

class nosqlapi.kvdb.client.KVConnection(*args, **kwargs)[source]

Bases: nosqlapi.common.core.Connection, abc.ABC

Key-value NOSQL database Connection class

__init__(*args, **kwargs)[source]

Instantiate Connection object

Parameters
  • host – Name of host that contains database

  • user – Username for connect to the host

  • password – Password for connect to the host

  • database – Name of database

  • port – Tcp port

  • bind_address – Hostname or an IP address for multiple network interfaces

  • read_timeout – Timeout for reading from the connection in seconds

  • write_timeout – Timeout for writing from the connection in seconds

  • ssl – Ssl connection established

  • ssl_ca – Ssl CA file specified

  • ssl_cert – Ssl certificate file specified

  • tls – Tls connection established

  • ssl_key – Ssl private key file specified

  • ssl_verify_cert – Verify certificate file

  • max_allowed_packet – Max size of packet sent to server in bytes

class nosqlapi.kvdb.client.KVResponse(data, code=None, header=None, error=None)[source]

Bases: nosqlapi.common.core.Response, abc.ABC

Key-value NOSQL database Response class

__weakref__

list of weak references to the object (if defined)

class nosqlapi.kvdb.client.KVSelector(*args, **kwargs)[source]

Bases: nosqlapi.common.core.Selector, abc.ABC

Key-value NOSQL database Selector class

__init__(*args, **kwargs)[source]

Instantiate Selector object

Parameters
  • selector – Selector part of the query string

  • fields – Return fields

  • partition – Partition or collection of data

  • condition – Condition of query

  • order – Order by specific selector

  • limit – Limit result

__str__()[source]

Return str(self).

abstract first_greater_or_equal(key)[source]

First greater or equal key by selector key

Parameters

key – key to search

Returns

Union[str, list, tuple]

abstract first_greater_than(key)[source]

First greater key by selector key

Parameters

key – key to search

Returns

Union[str, list, tuple]

abstract last_less_or_equal(key)[source]

Last less or equal key by selector key

Parameters

key – key to search

Returns

Union[str, list, tuple]

abstract last_less_than(key)[source]

Last less key by selector key

Parameters

key – key to search

Returns

Union[str, list, tuple]

class nosqlapi.kvdb.client.KVSession(connection, database=None)[source]

Bases: nosqlapi.common.core.Session, abc.ABC

Key-value NOSQL database Session class

abstract copy(*args, **kwargs)[source]

Copy key to other key

Returns

Union[bool, Response]

client example

This is an example of a library for connecting to a redis server.

# mykvdb.py
import nosqlapi

# this module is my library of NOSQL key-value database, like Redis database

class Connection(nosqlapi.kvdb.KVConnection):
    def __init__(host='localhost', port=6379, database=0, username=None, password=None, ssl=None, tls=None,
                 cert=None, ca_cert=None, ca_bundle=None): ...
    def close(self): ...
    def connect(self, *args, **kwargs): ...
    def create_database(self):
        raise nosqlapi.DatabaseCreationError('See your server configuration file.')
    def has_database(self, database): ...
    def databases(self): ...
    def delete_database(self): ...
    def show_database(self, database): ...


class Session(nosqlapi.kvdb.KVSession):
    # define here all methods
    pass

conn = Connection('myredis.local', password='pa$$w0rd')
print(conn.databases())                 # (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
sess = conn.connect()                   # Session object
...

odm module

The odm module contains the specific object for key-value databases.

ODM module for key-value NOSQL database.

class nosqlapi.kvdb.odm.ExpiredItem(key, value=None, ttl=None)[source]

Bases: nosqlapi.kvdb.odm.Item

Represents Item object with ttl expired time

__init__(key, value=None, ttl=None)[source]

ExpiredItem object

Parameters
  • key – Key of item

  • value – Value of item

  • ttl – Time to live of item

__repr__()[source]

Return repr(self).

property ttl

Time to live of item

class nosqlapi.kvdb.odm.Index(name, key)

Bases: tuple

__getnewargs__()

Return self as a plain tuple. Used by copy and pickle.

static __new__(_cls, name, key)

Create new instance of Index(name, key)

__repr__()

Return a nicely formatted representation string

property key

Alias for field number 1

property name

Alias for field number 0

class nosqlapi.kvdb.odm.Item(key, value=None)[source]

Bases: object

Represents key/value like a dictionary

__init__(key, value=None)[source]

Item object

Parameters
  • key – Key of item

  • value – Value of item

__repr__()[source]

Return repr(self).

__str__()[source]

Return str(self).

__weakref__

list of weak references to the object (if defined)

get()[source]

Get item

Returns

dict

property key

Key of item

set(key, value=None)[source]

Set item

Parameters
  • key – Key of item

  • value – Value of the key

Returns

None

property value

Value of the key

class nosqlapi.kvdb.odm.Keyspace(name, exists=False)[source]

Bases: object

Represents keyspace like database

__init__(name, exists=False)[source]

Keyspace object

Parameters
  • name – Name of keyspace

  • exists – Existing keyspace (default False)

__repr__()[source]

Return repr(self).

__str__()[source]

Return str(self).

__weakref__

list of weak references to the object (if defined)

append(item)[source]

Append item into store

Parameters

item – Key/value item

Returns

None

property exists

Existence of keyspace

property name

Name of keyspace

pop(item=- 1)[source]

Remove item from the store

Parameters

item – Index of item to remove

Returns

None

property store

List of object into keyspace

class nosqlapi.kvdb.odm.Subspace(name, sub=None, sep='.')[source]

Bases: nosqlapi.kvdb.odm.Keyspace

Represents subspace of the keyspace

__init__(name, sub=None, sep='.')[source]

Subspace object

Parameters
  • name – Name of keyspace

  • sub – Subname of keyspace

  • sep – Separation character

class nosqlapi.kvdb.odm.Transaction(commands=None)[source]

Bases: object

Represents group of commands in a single step

__init__(commands=None)[source]

Transaction object

Parameters

commands – List of commands

__repr__()[source]

Return repr(self).

__str__()[source]

Return str(self).

__weakref__

list of weak references to the object (if defined)

add(command, index=- 1)[source]

Add command to commands list

Parameters
  • command – Command string

  • index – Index to append command

Returns

None

property commands

Command list

delete(index=- 1)[source]

Remove command to command list

Parameters

index – Index to remove command

Returns

None

odm example

These objects represent the respective key-value in databases.

import nosqlapi

transaction = nosqlapi.kvdb.odm.Transaction()       # in short -> nosqlapi.kvdb.Transaction()
# Add commands
transaction.add('ACL LIST')
transaction.add('ACL DELUSER test')
# Remove commands
transaction.delete(1)

item = nosqlapi.kvdb.Item('key', 'value')            # item key=value