Skip to main content

CouchDB client built on top of aiohttp (asyncio)

Project description

aiocouchdb

CouchDB client built on top of aiohttp.

Current status: beta. aiocouchdb has all CouchDB API implements up to 1.6 release. However, it may lack of some usability and stability bits, but work is in progress. Feel free to send pull request or open issue if you find something that should be fixed.

Also don’t miss the docs: http://aiocouchdb.readthedocs.org/en/latest/

Example

import sys
import asyncio
from aiocouchdb import Server


@asyncio.coroutine
def go(url):
    server = Server(url)

    # multi-session workflow
    admin = yield from server.session.open('admin', 's3cr1t')
    user = yield from server.session.open('user', 'pass')

    admin_info = yield from server.session.info(auth=admin)
    user_info = yield from server.session.info(auth=user)
    print('admin:', admin_info)
    print('user:', user_info)

    # db_updates is admin only resource
    feed = yield from server.db_updates(feed='continuous', auth=admin,
                                        heartbeat=False, timeout=10000)
    while True:
        event = yield from feed.next()
        if event is None:  # feed exhausted
            break
        dbname = event['db_name']

        # want to use raw queries? that's easy
        resp = yield from server.resource.get(dbname, auth=user)
        if resp.status == 403:
            # ignore Forbidden errors
            continue
        # but respect everyone else
        yield from resp.maybe_raise_error()
        dbinfo = yield from resp.json()
        print(dbinfo)

    # close sessions
    assert {'ok': True} == (yield from server.session.close(auth=admin))
    assert {'ok': True} == (yield from server.session.close(auth=user))


if __name__ == '__main__':
    if '--iocp' in sys.argv:
        from asyncio import events, windows_events
        sys.argv.remove('--iocp')
        el = windows_events.ProactorEventLoop()
        events.set_event_loop(el)

    loop = asyncio.get_event_loop()
    loop.run_until_complete(go('http://localhost:5984'))

Requirements

License

BSD

Changes

0.5.0 (2014-09-26)

  • Last checkpoint release. It’s in beta now!

  • Implements CouchDB Design Documents HTTP API

  • Views refactoring and implementation consolidation

0.4.0 (2014-09-17)

  • Another checkpoint release

  • Implements CouchDB Attachment HTTP API

  • Minimal requirements for aiohttp raised up to 0.9.1 version

  • Minor fixes for Document API

0.3.0 (2014-08-18)

  • Third checkpoint release

  • Implements CouchDB Document HTTP API

  • Support document`s multipart API (but not doc update due to COUCHDB-2295)

  • Minimal requirements for aiohttp raised up to 0.9.0 version

  • Better documentation

0.2.0 (2014-07-08)

  • Second checkpoint release

  • Implements CouchDB Database HTTP API

  • Bulk docs accepts generator as an argument and streams request doc by doc

  • Views are processed as stream

  • Unified output for various changes feed types

  • Basic Auth accepts non-ASCII credentials

  • Minimal requirements for aiohttp raised up to 0.8.4 version

0.1.0 (2014-07-01)

  • Initial checkpoint release

  • Implements CouchDB Server HTTP API

  • BasicAuth, Cookie, OAuth authentication providers

  • Multi-session workflow

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

aiocouchdb-0.5.0.tar.gz (48.8 kB view hashes)

Uploaded Source

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