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(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()[source]

Closes connection.

run(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 (bytes | None) – value for command(put) execution(bytes, e.g. b'value', b'another-value')

  • keys (list[bytes] | None) – keys for command(write_batch) execution(list[bytes], e.g. [b'key', b'another-key'])

  • values (list[bytes] | None) – values for command(write_batch) execution e.g. [b'value', b'another-value']

Returns

value from get or None

Return type

bytes | None

put(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(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(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(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?