Skip to main content

Wrapper for cassandra-driver that makes queries awaitable using asyncio

Project description

Cassandra AsyncIO Driver

Wrapper for cassandra-driver that makes blocking calls awaitable using asyncio

Installation

$ pip install cassandra-asyncio-driver

Usage

To adapt existing code to use the asyncio driver, replace:

from cassandra.cluster import Cluster

with:

from cassandra_asyncio.cluster import Cluster

Queries can be executed asynchronously using await session.aexecute().

For synchronous queries, session.execute() can still be used as normal.

All other Cassandra classes should continue to be imported from the usual paths.

For example:

import csv
import asyncio
from cassandra_asyncio.cluster import Cluster
from cassandra.auth import PlainTextAuthProvider
from cassandra.query import dict_factory

async def main():
    with open('movies.csv', 'w', newline='') as output_file:
        # Prepare CSV writer
        fieldnames = ['genre', 'name', 'rating', 'seen']
        writer = csv.DictWriter(output_file, fieldnames=fieldnames, dialect='excel')
        writer.writeheader()

        # Connect to Cassandra using `cassandra_asyncio.cluster.Cluster`
        auth_provider = PlainTextAuthProvider(username='cassandra', password='cassandra')
        cluster = Cluster(auth_provider=auth_provider)
        session = cluster.connect('lists')
        session.row_factory = dict_factory

        # Execute query asynchronously using `session.aexecute()`
        rows = await session.aexecute('SELECT genre, name, rating, seen FROM movies_to_watch')

        # Write rows to output file
        for row in rows:
            writer.writerow(row)

if __name__ == '__main__':
    asyncio.run(main())

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

cassandra_asyncio_driver-0.1.3.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

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

cassandra_asyncio_driver-0.1.3-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file cassandra_asyncio_driver-0.1.3.tar.gz.

File metadata

File hashes

Hashes for cassandra_asyncio_driver-0.1.3.tar.gz
Algorithm Hash digest
SHA256 6dbe1dd5204f205bbe93229b8d78c3bdc2dc1eca37cddb56deb1258ad0c5eb22
MD5 f1096688c15a2f14607565f1647cc439
BLAKE2b-256 337b33a9f85fbfdd690a9bbfc946bd3a173d8668de4cf2ac7b48e9a25ebe9da7

See more details on using hashes here.

Provenance

The following attestation bundles were made for cassandra_asyncio_driver-0.1.3.tar.gz:

Publisher: build-and-publish.yaml on U-238/cassandra-asyncio-driver

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cassandra_asyncio_driver-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for cassandra_asyncio_driver-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d8c384d6aa267c771179ca95c2e3bd82bdbfb49b02fb27771c890adfe3393297
MD5 7aa3f056fb93b1674a3f9f99405fb519
BLAKE2b-256 b6cd524a43e0ede353e0b1bcae06bf9981bca602d221f6ecdd0a22cdee454109

See more details on using hashes here.

Provenance

The following attestation bundles were made for cassandra_asyncio_driver-0.1.3-py3-none-any.whl:

Publisher: build-and-publish.yaml on U-238/cassandra-asyncio-driver

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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