airflow.providers.google.leveldb.hooks.leveldb

Hook for Level DB

Module Contents

Classes

LevelDBHook

Plyvel Wrapper to Interact With LevelDB Database

Attributes

DB_NOT_INITIALIZED_BEFORE

airflow.providers.google.leveldb.hooks.leveldb.DB_NOT_INITIALIZED_BEFORE = The `get_conn` method should be called before![source]
exception airflow.providers.google.leveldb.hooks.leveldb.LevelDBHookException[source]

Bases: airflow.exceptions.AirflowException

Exception specific for LevelDB

class airflow.providers.google.leveldb.hooks.leveldb.LevelDBHook(leveldb_conn_id=default_conn_name)[source]

Bases: airflow.hooks.base.BaseHook

Plyvel Wrapper to Interact With LevelDB Database LevelDB Connection Documentation

conn_name_attr = leveldb_conn_id[source]
default_conn_name = leveldb_default[source]
conn_type = leveldb[source]
hook_name = LevelDB[source]
get_conn(self, name='/tmp/testdb/', create_if_missing=False, **kwargs)[source]

Creates Plyvel DB

Parameters
  • name (str) -- path to create database e.g. /tmp/testdb/)

  • create_if_missing (bool) -- whether a new database should be created if needed

  • kwargs -- other options of creation plyvel.DB. See more in the link above.

Returns

DB

Return type

plyvel.DB

close_conn(self)[source]

Closes connection

run(self, command, key, value=None, keys=None, values=None)[source]

Execute operation with leveldb

Parameters
  • command (str) -- command of plyvel(python wrap for leveldb) for DB object e.g. "put", "get", "delete", "write_batch".

  • key (bytes) -- key for command(put,get,delete) execution(, e.g. b'key', b'another-key')

  • value (Optional[bytes]) -- value for command(put) execution(bytes, e.g. b'value', b'another-value')

  • keys (Optional[List[bytes]]) -- keys for command(write_batch) execution(List[bytes], e.g. [b'key', b'another-key'])

  • values (Optional[List[bytes]]) -- values for command(write_batch) execution e.g. [b'value', b'another-value']

Returns

value from get or None

Return type

Optional[bytes]

put(self, key, value)[source]

Put a single value into a leveldb db by key

Parameters
  • key (bytes) -- key for put execution, e.g. b'key', b'another-key'

  • value (bytes) -- value for put execution e.g. b'value', b'another-value'

get(self, key)[source]

Get a single value into a leveldb db by key

Parameters

key (bytes) -- key for get execution, e.g. b'key', b'another-key'

Returns

value of key from db.get

Return type

bytes

delete(self, key)[source]

Delete a single value in a leveldb db by key.

Parameters

key (bytes) -- key for delete execution, e.g. b'key', b'another-key'

write_batch(self, keys, values)[source]

Write batch of values in a leveldb db by keys

Parameters
  • keys (List[bytes]) -- keys for write_batch execution e.g. [b'key', b'another-key']

  • values (List[bytes]) -- values for write_batch execution e.g. [b'value', b'another-value']

Was this entry helpful?