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
Metadata
Release files for async-cassandra 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| async_cassandra-0.0.1.tar.gz | 427.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| async_cassandra-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 459.3 kB
Release files / async_cassandra-0.0.1.tar.gz
| Download URL | async_cassandra-0.0.1.tar.gz |
|---|---|
| Size | 427.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3a98a1dad4cd140b039b5276455bd0a7b6bb39654db25412d140c0060c7d009b
|
|
BLAKE2b-256 checksum How to use checksums |
bb6c02bb7d98b44a008e3cd76c7a383b5dde414c14380e94bf9d0b7f204fad88
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 1, 2025.
Transparency logRelease files / async_cassandra-0.0.1-py3-none-any.whl
| Download URL | async_cassandra-0.0.1-py3-none-any.whl |
|---|---|
| Size | 32.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
117e646ef07357675ca1b0c3fd39a23c44bba296548a96b5b2aecd77e5f48ca8
|
|
BLAKE2b-256 checksum How to use checksums |
3e5acb44015df3edf1b601a5f410c86d7da3bfecca1d3375525ad566ef0117e9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 1, 2025.
Transparency log