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.4.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.4-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for cassandra_asyncio_driver-0.1.4.tar.gz
Algorithm Hash digest
SHA256 495706a8d01ff8e64bcd579acf3ef65cfc177b0b04227cd608c9823c172f25dd
MD5 fcbb5ad3e1584ed3dac6bc4ff668febc
BLAKE2b-256 3dbd93224e93a6c5511d68c19b94fdcc096a2e2031f61d44b126348c8ffb7566

See more details on using hashes here.

Provenance

The following attestation bundles were made for cassandra_asyncio_driver-0.1.4.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.4-py3-none-any.whl.

File metadata

File hashes

Hashes for cassandra_asyncio_driver-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 82fb8beb3e74cb35eb8f367f743a9518f70d74547f82b768a70bbc1c05dd3a1b
MD5 b88483a774f9079be1b066ea96ea93a6
BLAKE2b-256 ca5ddd76178a8bc4cf4a54a545b302ba259229dba9c15a8fb706c484d2537c31

See more details on using hashes here.

Provenance

The following attestation bundles were made for cassandra_asyncio_driver-0.1.4-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