Coder Social home page Coder Social logo

aiodbm's Introduction

aiodbm: DBM for AsyncIO

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 aiodbm?

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.

In our measurements we see that aiodbm is hundreds or times faster for writes and more then three faster for reads compared to aiosqlite [3]:

Throughput measurements for aiodbm vs. aiosqlite

So if you are on a Linux system and need a fast and an easy to use embedded key-value store for asyncio, aiodbm can be a good solution.

Caveats

On non Linux-like systems DBM is usually not available and Python will fall back on it's "dumb" DBM implementation. While DBM's core functionality still works, that implementation is be much slower.

Python's DBM library 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

[1]See also Python's DBM module: https://docs.python.org/3/library/dbm.html
[2]The newer DBM variants GDBM or NDBM are preinstalled on most Linux/Unix systems: https://en.wikipedia.org/wiki/DBM_(computing)#Availability
[3]We compared asyncio compatible key/value stores on Linux with GDBM. See also measurements folder for more details.

aiodbm's People

Contributors

erikkalkoken avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.