Which Cassandra Python driver works with aiohttp?
Asked Answered
K

2

6

The question is which Cassandra Python driver is better to use with aiohttp web framework.

Currently, there are two possible candidates:

  1. cassandra-driver by DataStax
  2. aiocassandra

The thing is, cassandra-driver seems to be more popular and has more support. But on the other side it does not support asyncio (experimental unstable implementation), while asyncio is critical for running aiohttp web server.

aiocassandra is not as popular, and maintanance+support is questionable.

So, does aiocassandra perform way better than cassandra-driver, and which should we choose in terms of uptime and performance and support?

Kerguelen answered 17/5, 2018 at 15:7 Comment(0)
S
2

cassandra-driver is used in the project (cqlsh) and the tests for cassandra are written using it (dtests) so will always be maintained, well tested and up to date with all versions of Cassandra.

aiocassandra is a wrapper around cassandra-driver so its performance probably wont be any different.

Senior answered 17/5, 2018 at 15:16 Comment(0)
F
1

aiocassandra is now not an option.

The project on Github has been archived since 2020:
https://github.com/aio-libs/aiocassandra/issues/122

aiocqlengine is another option.

It is basically a wrapper around Datastax's Cassandra Python driver's cassandra.cqlengine.model's.
But it has async/await support:

import asyncio
import uuid import os

from aiocqlengine.models import AioModel
from aiocqlengine.query import AioBatchQuery
from aiocqlengine.session import aiosession_for_cqlengine 
from cassandra.cluster import Cluster 
from cassandra.cqlengine import columns, connection, management


class User(AioModel):
    user_id = columns.UUID(primary_key=True)
    username = columns.Text()

async def run_aiocqlengine_example():
    ...
    # Model.objects.all() and Model.all() in async way:
    print(list(await User.async_all()))
    print(list(await User.objects.filter(user_id=user_id).async_all()))

    # Model.object.update() in async way:
    await User.objects(user_id=user_id).async_update(username='updated-user1')

    # Model.objects.get() and Model.get() in async way:
    user = await User.objects.async_get(user_id=user_id)
    await User.async_get(user_id=user_id)
    print(user, user.username)

    # Model.save() in async way:
    user.username = 'saved-user1'
    await user.async_save()

    # Model.delete() in async way:
    await user.async_delete()
    ... 

It seems to still be maintained.

Fenner answered 10/7, 2023 at 6:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.