zlmdb._lmdb_vendor.aio¶
Async wrappers for py-lmdb via asyncio.loop.run_in_executor().
Usage:
import lmdb
import lmdb.aio
env = lmdb.open('/tmp/mydb')
aenv = lmdb.aio.wrap(env)
async with aenv.begin(write=True) as txn:
await txn.put(b'key', b'value')
val = await txn.get(b'key')
Classes¶
Async wrapper for |
|
Async wrapper for |
|
Async wrapper for |
|
Wraps a coroutine so it can be used as both |
Functions¶
|
Return a coroutine method that calls sync in the executor. |
|
Like |
|
Like |
|
Return a method that calls sync directly, without an executor. |
|
Wrap an |
Module Contents¶
- class AsyncCursor(cursor, executor=None, lock=None)[source]¶
Async wrapper for
lmdb.Cursor.All methods of the underlying
Cursorare available. Most are dispatched to an executor;key(),value(), anditem()are called directly.Iterator methods (
iternext(),iterprev(), etc.) are consumed in the executor and returned as a list.Shares the parent transaction’s
asyncio.Lock.Supports
async with— the cursor is closed on exit.
- class AsyncEnvironment(env, executor=None)[source]¶
Async wrapper for
lmdb.Environment.Created by
wrap(). All methods of the underlyingEnvironmentare available and are dispatched to an executor, except for the low-overhead accessorspath(),max_key_size(),max_readers(), andflags(), which are called directly.Supports
async withfor lifetime management — the environment is closed on exit.- begin(*args, **kwargs)[source]¶
Start a new transaction, returning an
AsyncTransaction.Accepts the same arguments as
lmdb.Environment.begin(). Can be used withawaitorasync with:async with aenv.begin(write=True) as txn: await txn.put(b'key', b'value')
- class AsyncTransaction(txn, executor=None)[source]¶
Async wrapper for
lmdb.Transaction.All methods of the underlying
Transactionare available. Most are dispatched to an executor;id()is called directly.An
asyncio.Lockserializes all operations dispatched through this transaction, including operations on its cursors. This makesasyncio.gather()safe on the same transaction.Supports
async with— write transactions are committed on clean exit and aborted on exception.- cursor(*args, **kwargs)[source]¶
Open a cursor, returning an
AsyncCursor.Accepts the same arguments as
lmdb.Transaction.cursor(). Can be used withawaitorasync with:async with txn.cursor() as cur: await cur.first() items = await cur.iternext()
- class _AsyncContextWrapper(coro)[source]¶
Wraps a coroutine so it can be used as both
awaitandasync with.Supports:
txn = await aenv.begin(write=True) # just await async with aenv.begin(write=True) as txn: # context manager
- _async_method_locked(sync)[source]¶
Like
_async_method(), but acquiresself._lockfirst.
- _collect_locked(sync)[source]¶
Like
_async_method_locked(), but sync returns an iterator consumed in the executor and returned as a list.