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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cassandra_asyncio_driver-0.1.4.tar.gz.
File metadata
- Download URL: cassandra_asyncio_driver-0.1.4.tar.gz
- Upload date:
- Size: 3.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
495706a8d01ff8e64bcd579acf3ef65cfc177b0b04227cd608c9823c172f25dd
|
|
| MD5 |
fcbb5ad3e1584ed3dac6bc4ff668febc
|
|
| BLAKE2b-256 |
3dbd93224e93a6c5511d68c19b94fdcc096a2e2031f61d44b126348c8ffb7566
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cassandra_asyncio_driver-0.1.4.tar.gz -
Subject digest:
495706a8d01ff8e64bcd579acf3ef65cfc177b0b04227cd608c9823c172f25dd - Sigstore transparency entry: 153757736
- Sigstore integration time:
-
Permalink:
U-238/cassandra-asyncio-driver@29dc330c0ffb070e44bdcb2215b390dc9ef88f11 -
Branch / Tag:
refs/tags/0.1.4 - Owner: https://github.com/U-238
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-and-publish.yaml@29dc330c0ffb070e44bdcb2215b390dc9ef88f11 -
Trigger Event:
push
-
Statement type:
File details
Details for the file cassandra_asyncio_driver-0.1.4-py3-none-any.whl.
File metadata
- Download URL: cassandra_asyncio_driver-0.1.4-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
82fb8beb3e74cb35eb8f367f743a9518f70d74547f82b768a70bbc1c05dd3a1b
|
|
| MD5 |
b88483a774f9079be1b066ea96ea93a6
|
|
| BLAKE2b-256 |
ca5ddd76178a8bc4cf4a54a545b302ba259229dba9c15a8fb706c484d2537c31
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cassandra_asyncio_driver-0.1.4-py3-none-any.whl -
Subject digest:
82fb8beb3e74cb35eb8f367f743a9518f70d74547f82b768a70bbc1c05dd3a1b - Sigstore transparency entry: 153757737
- Sigstore integration time:
-
Permalink:
U-238/cassandra-asyncio-driver@29dc330c0ffb070e44bdcb2215b390dc9ef88f11 -
Branch / Tag:
refs/tags/0.1.4 - Owner: https://github.com/U-238
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-and-publish.yaml@29dc330c0ffb070e44bdcb2215b390dc9ef88f11 -
Trigger Event:
push
-
Statement type: