Giter Site home page Giter Site logo

aiotinydb

PyPI PyPI PyPI Build Status Say Thanks!

asyncio compatibility shim for TinyDB

Enables usage of TinyDB in asyncio-aware contexts without slow syncronous IO.

See documentation on compatible version of TinyDB.

Basically all API calls from TinyDB are supported in AIOTinyDB. With the following exceptions: you should not use basic with syntax and close functions. Instead, you should use async with.

import asyncio
from aiotinydb import AIOTinyDB

async def test():
    async with AIOTinyDB('test.json') as db:
        db.insert(dict(counter=1))

loop = asyncio.new_event_loop()
loop.run_until_complete(test())
loop.close()

CPU-bound operations like db.search(), db.update() etc. are executed synchronously and may block the event loop under heavy load. Use multiprocessing if that's an issue (see #6 and examples/processpool.py for an example).

Middleware

Any middlewares you use should be async-aware. See example:

from tinydb.middlewares import CachingMiddleware as VanillaCachingMiddleware
from aiotinydb.middleware import AIOMiddleware

class CachingMiddleware(VanillaCachingMiddleware, AIOMiddlewareMixin):
    """
        Async-aware CachingMiddleware. For more info read
        docstring for `tinydb.middlewares.CachingMiddleware`
    """
    pass

If middleware requires some special handling on entry and exit, override __aenter__ and __aexit__.

Concurrent database access

Instances of AIOTinyDB support database access from multiple coroutines.

On unix-like systems, it's also possible to access one database concurrently from multiple processes when using AIOJSONStorage (the default) or AIOImmutableJSONStorage.

Installation

pip install aiotinydb

aiotinydb's Projects

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.