Async Python wrapper for the Cassandra Python driver
Project description
Async Python Cassandra© Client
📢 Early Release: This is an early release of async-cassandra. While it has been tested extensively, you may encounter edge cases. We welcome your feedback and contributions! Please report any issues on our GitHub Issues page.
🎯 Overview
A Python library that enables true async/await support for Cassandra database operations. This package wraps the official DataStax™ Cassandra driver to make it compatible with async frameworks like FastAPI, aiohttp, and Quart.
When using the standard Cassandra driver in async applications, blocking operations can freeze your entire service. This wrapper solves that critical issue by bridging Cassandra's thread-based operations with Python's async ecosystem.
✨ Key Features
- 🚀 True async/await interface for all Cassandra operations
- 🛡️ Prevents event loop blocking in async applications
- ✅ 100% compatible with the official cassandra-driver types
- 📊 Streaming support for memory-efficient processing of large datasets
- 🔄 Automatic retry logic for failed queries
- 📡 Connection monitoring and health checking
- 📈 Metrics collection with Prometheus support
- 🎯 Type hints throughout the codebase
📋 Requirements
- Python 3.12 or higher
- Apache Cassandra 4.0+ (or compatible distributions)
- Requires CQL protocol v5 or higher
📦 Installation
pip install async-cassandra
🚀 Quick Start
import asyncio
from async_cassandra import AsyncCluster
async def main():
# Connect to Cassandra
cluster = AsyncCluster(['localhost'])
session = await cluster.connect()
# Execute queries
result = await session.execute("SELECT * FROM system.local")
print(f"Connected to: {result.one().cluster_name}")
# Clean up
await session.close()
await cluster.shutdown()
if __name__ == "__main__":
asyncio.run(main())
🌐 FastAPI Integration
from fastapi import FastAPI
from async_cassandra import AsyncCluster
from contextlib import asynccontextmanager
@asynccontextmanager
async def lifespan(app: FastAPI):
# Startup
cluster = AsyncCluster(['localhost'])
app.state.session = await cluster.connect()
yield
# Shutdown
await app.state.session.close()
await cluster.shutdown()
app = FastAPI(lifespan=lifespan)
@app.get("/users/{user_id}")
async def get_user(user_id: str):
query = "SELECT * FROM users WHERE id = ?"
result = await app.state.session.execute(query, [user_id])
return result.one()
🤔 Why Use This Library?
The official cassandra-driver uses a thread pool for I/O operations, which can cause problems in async applications:
- 🚫 Event Loop Blocking: Synchronous operations block the event loop, freezing your entire application
- 🐌 Poor Concurrency: Thread pool limits prevent efficient handling of many concurrent requests
- ⚡ Framework Incompatibility: Doesn't integrate naturally with async frameworks
This library provides true async/await support while maintaining full compatibility with the official driver.
⚠️ Important Limitations
This wrapper makes the cassandra-driver compatible with async Python, but it's important to understand what it does and doesn't do:
What it DOES:
- ✅ Prevents blocking the event loop in async applications
- ✅ Provides async/await syntax for all operations
- ✅ Enables use with FastAPI, aiohttp, and other async frameworks
- ✅ Allows concurrent operations via the event loop
What it DOESN'T do:
- ❌ Make the underlying I/O truly asynchronous (still uses threads internally)
- ❌ Provide performance improvements over the sync driver
- ❌ Remove thread pool limitations (concurrency still bounded by driver's thread pool size)
- ❌ Eliminate thread overhead - there's still a context switch cost
Key Understanding: The official cassandra-driver uses blocking sockets and a thread pool for all I/O operations. This wrapper provides an async interface by running those blocking operations in a thread pool and coordinating with your event loop. This is a compatibility layer, not a reimplementation.
For a detailed technical explanation, see What This Wrapper Actually Solves (And What It Doesn't) in our documentation.
📚 Documentation
For comprehensive documentation, examples, and advanced usage, please visit our GitHub repository:
🔗 Full Documentation on GitHub
Key documentation sections:
- 📖 Getting Started Guide
- 🔧 API Reference
- 🚀 FastAPI Integration Example
- ⚡ Performance Guide
- 🔍 Troubleshooting
📄 License
This project is licensed under the Apache License 2.0. See the LICENSE file for details.
🏢 About
Developed and maintained by AxonOps. We're committed to providing high-quality tools for the Cassandra community.
🤝 Contributing
We welcome contributions! Please see our Contributing Guide on GitHub.
💬 Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
🙏 Acknowledgments
- DataStax™ for the Python Driver for Apache Cassandra
- The Python asyncio community for inspiration and best practices
- All contributors who help make this project better
⚖️ Legal Notices
This project may contain trademarks or logos for projects, products, or services. Any use of third-party trademarks or logos are subject to those third-party's policies.
Important: This project is not affiliated with, endorsed by, or sponsored by the Apache Software Foundation or the Apache Cassandra project. It is an independent framework developed by AxonOps.
- AxonOps is a registered trademark of AxonOps Limited.
- Apache, Apache Cassandra, Cassandra, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries.
- DataStax is a registered trademark of DataStax, Inc. and its subsidiaries in the United States and/or other countries.
Made with ❤️ by the AxonOps Team
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 async_cassandra-0.0.1.tar.gz.
File metadata
- Download URL: async_cassandra-0.0.1.tar.gz
- Upload date:
- Size: 427.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3a98a1dad4cd140b039b5276455bd0a7b6bb39654db25412d140c0060c7d009b
|
|
| MD5 |
cfb732c2f40d205f28fa869054121e68
|
|
| BLAKE2b-256 |
bb6c02bb7d98b44a008e3cd76c7a383b5dde414c14380e94bf9d0b7f204fad88
|
Provenance
The following attestation bundles were made for async_cassandra-0.0.1.tar.gz:
Publisher:
release.yml on axonops/async-python-cassandra-client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
async_cassandra-0.0.1.tar.gz -
Subject digest:
3a98a1dad4cd140b039b5276455bd0a7b6bb39654db25412d140c0060c7d009b - Sigstore transparency entry: 258148625
- Sigstore integration time:
-
Permalink:
axonops/async-python-cassandra-client@fb708aa145ce456b7eec4c8d5b2f3c4e68e0f9ea -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/axonops
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@fb708aa145ce456b7eec4c8d5b2f3c4e68e0f9ea -
Trigger Event:
push
-
Statement type:
File details
Details for the file async_cassandra-0.0.1-py3-none-any.whl.
File metadata
- Download URL: async_cassandra-0.0.1-py3-none-any.whl
- Upload date:
- Size: 32.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
117e646ef07357675ca1b0c3fd39a23c44bba296548a96b5b2aecd77e5f48ca8
|
|
| MD5 |
7948d63d142de15f2f960db7eef47c87
|
|
| BLAKE2b-256 |
3e5acb44015df3edf1b601a5f410c86d7da3bfecca1d3375525ad566ef0117e9
|
Provenance
The following attestation bundles were made for async_cassandra-0.0.1-py3-none-any.whl:
Publisher:
release.yml on axonops/async-python-cassandra-client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
async_cassandra-0.0.1-py3-none-any.whl -
Subject digest:
117e646ef07357675ca1b0c3fd39a23c44bba296548a96b5b2aecd77e5f48ca8 - Sigstore transparency entry: 258148633
- Sigstore integration time:
-
Permalink:
axonops/async-python-cassandra-client@fb708aa145ce456b7eec4c8d5b2f3c4e68e0f9ea -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/axonops
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@fb708aa145ce456b7eec4c8d5b2f3c4e68e0f9ea -
Trigger Event:
push
-
Statement type: