Skip to main content

An AsyncIO bridge for DBM.

Project description

An AsyncIO bridge for Python’s DBM library.

release python tests codecov docs pre-commit Code style: black

Description

aiodbm is a library that allows you to use DBM in asyncio code.

  • Full coverage of Python’s DBM and GDBM API

  • Typing support

  • Docstrings and documentation

  • Fully tested

Why use DBM?

DBM is a fast and easy to use, embedded key-value store. It is supported by Python’s standard library [1] and can be used on most systems without requiring additional dependencies [2].

Compared to Sqlite - the other embedded database supported by Python’s standard library - it is significantly faster when used as key/value store.

According to our measurement we see that aiodbm is about 140x faster on writes and about 3.5x faster on reads [3] on Linux:

Throughput measurements for aiodbm vs. aiosqlite

So if you are looking for a fast and an easy to use key-value store (e.g. for caching) on Linux systems, DBM can be a good solution. And aiodbm allows you use DBM in your asyncio programs.

Caveats

On non Linux-like systems Python might use it’s “dumb” DBM implementation, which will be much slower.

DBM is not process safe. If you need a key-value store in a multi process context (e.g. a web server running with gunicorn) we’d recommend to use Redis or something similar instead.

Usage

Here is a basic example on how to use the library:

import asyncio

import aiodbm


async def main():
   # opening/creating database
   async with aiodbm.open("example.dbm", "c") as db:

      # creating new key alpha with value green
      await db.set("alpha", "green")

      # fetching value for key alpha
      value = await db.get("alpha")
      print(value)

      # delete key alpha
      await db.delete("alpha")


asyncio.run(main())

Installation

You can install this library directly from PyPI with the following command:

pip install aiodbm

Reference

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiodbm-0.4.1.tar.gz (6.0 kB view hashes)

Uploaded Source

Built Distribution

aiodbm-0.4.1-py3-none-any.whl (7.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page