Skip to main content

Simple threaded cassandra wrapper for asyncio

Project description

info:

Simple threaded cassandra wrapper for asyncio

https://img.shields.io/travis/wikibusiness/aiocassandra.svg https://img.shields.io/pypi/v/aiocassandra.svg

Installation

pip install aiocassandra

Usage

import asyncio

from aiocassandra import aiosession
from cassandra.cluster import Cluster

cluster = Cluster()
session = cluster.connect()

# best way is to use cassandra prepared statements
cql = session.prepare('SELECT now() FROM system.local;')

@asyncio.coroutine
def main(*, loop):
    # patches and adds `execute_future` to `cassandra.cluster.Session`
    aiosession(session, loop=loop)
    return (yield from session.execute_future(cql))

loop = asyncio.get_event_loop()

try:
    response = loop.run_until_complete(main(loop=loop))
    print(response)
finally:
    cluster.shutdown()
    loop.close()

Python 2.7(trollius), 3.3+ and PyPy are supported.

Supported by

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