Skip to main content

Simple threaded cassandra wrapper for asyncio

Project description

info:

Simple threaded cassandra wrapper for asyncio

https://travis-ci.org/aio-libs/aiocassandra.svg?branch=master https://img.shields.io/pypi/v/aiocassandra.svg https://codecov.io/gh/aio-libs/aiocassandra/branch/master/graph/badge.svg

Installation

pip install aiocassandra

Usage

import asyncio

from aiocassandra import aiosession
from cassandra.cluster import Cluster
from cassandra.query import SimpleStatement

# connection is blocking call
cluster = Cluster()
# aiocassandra uses executor_threads to talk to cassndra driver
# https://datastax.github.io/python-driver/api/cassandra/cluster.html?highlight=executor_threads
session = cluster.connect()


async def main():
    # patches and adds `execute_future`, `execute_futures` and `prepare_future`
    # to `cassandra.cluster.Session`
    aiosession(session)

    # best way is to use cassandra prepared statements
    # https://cassandra-zone.com/prepared-statements/
    # https://datastax.github.io/python-driver/api/cassandra/cluster.html#cassandra.cluster.Session.prepare
    # try to create them once on application init
    query = session.prepare('SELECT now() FROM system.local;')

    # if non-blocking prepared statements is really needed:
    query = await session.prepare_future('SELECT now() FROM system.local;')

    print(await session.execute_future(query))

    # pagination is also supported
    query = 'SELECT * FROM system.size_estimates;'
    statement = SimpleStatement(query, fetch_size=100)

    # don't miss *s* (execute_futureS)
    async with session.execute_futures(statement) as paginator:
        async for row in paginator:
            print(row)


loop = asyncio.get_event_loop()
loop.run_until_complete(main())
cluster.shutdown()
loop.close()

Python 3.5+ is required

Thanks

The library was donated by Ocean S.A.

Thanks to the company for contribution.

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

aiocassandra-2.0.0.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aiocassandra-2.0.0-py2.py3-none-any.whl (6.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file aiocassandra-2.0.0.tar.gz.

File metadata

  • Download URL: aiocassandra-2.0.0.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for aiocassandra-2.0.0.tar.gz
Algorithm Hash digest
SHA256 7cd08b869c0e81e4ef1e94b80f795a1c0bddf3e24aad8960c39e1ae3946a6142
MD5 e0c15a67d8938d9dc4eeca1572f4f9bd
BLAKE2b-256 c8fe44ae1094f623d4fa5d4c1b61d64673d67240256ce895296f00de5e4aa3fa

See more details on using hashes here.

File details

Details for the file aiocassandra-2.0.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for aiocassandra-2.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d44b927e82cc76fd400cbf60cf5133aa182eea19e45aa6144c0728b426d9415f
MD5 15005dca5778e23ba526e370929ec589
BLAKE2b-256 8a539e43df0a21dc6a3910f9b7dcb4bc71105ab36102a7183f8e4a6dd0888d65

See more details on using hashes here.

Supported by

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