Skip to content

[14350] Added ScyllaDB and Cassandra docs and tests#14352

Closed
andrii-kysylevskyi wants to merge 6 commits intofastapi:masterfrom
andrii-kysylevskyi:14350-add-no-sql-docs
Closed

[14350] Added ScyllaDB and Cassandra docs and tests#14352
andrii-kysylevskyi wants to merge 6 commits intofastapi:masterfrom
andrii-kysylevskyi:14350-add-no-sql-docs

Conversation

@andrii-kysylevskyi
Copy link

@andrii-kysylevskyi andrii-kysylevskyi commented Nov 14, 2025

NoSQL Databases Tutorial (Cassandra/ScyllaDB)

Adds a tutorial demonstrating FastAPI integration with NoSQL databases, specifically Apache Cassandra and ScyllaDB.

What's Included

  • Tutorial documentation with examples (docs/en/docs/tutorial/nosql-databases.md)
  • Two tutorial files: tutorial001.py (Cassandra) and tutorial001_scylla.py (ScyllaDB)
  • Docker Compose setup instructions
  • Tests validating tutorial structure

Compatibility

  • Python 3.8+ (uses typing.List for older versions)
  • Pydantic v1 and v2 (uses explicit field assignment)
  • Python 3.14+ (mocks cassandra module to avoid asyncore dependency)

Key Features

  • Demonstrates CRUD operations with Cassandra/ScyllaDB
  • Shows ScyllaDB as Cassandra-compatible alternative (same driver, same CQL)
  • Uses modern FastAPI lifespan pattern
  • Covers connection management, schema creation, and CQL queries
  • Includes production considerations

Why This Tutorial?

FastAPI documentation currently covers SQL databases but doesn't mention NoSQL options. Community articles already demonstrate FastAPI + Cassandra integration (e.g., DataStax Astra DB docs), showing there's demand for this content.

Testing Approach

Tests use mocked database operations (via conftest.py) to:

  • Avoid Docker dependencies in CI
  • Handle Python 3.14+ compatibility (cassandra-driver requires gevent or libev)
  • Keep tests fast

What tests validate:

  • FastAPI endpoint structure and routing
  • Tutorial code runs without errors
  • Both Cassandra and ScyllaDB tutorials work

What tests don't validate:

  • Actual database connections and operations
  • CQL query correctness

This differs from SQL tutorials which use real SQLite. The tutorial code has been manually tested against real Cassandra and ScyllaDB containers via Docker Compose.

Future Improvements

Integration tests with real databases (using testcontainers-python) could be added to validate actual database operations. This could be done in this PR or as a follow-up, depending on maintainer preference.

Files Changed

  • docs/en/docs/tutorial/nosql-databases.md - Tutorial documentation
  • docs/en/mkdocs.yml - Added tutorial to navigation
  • docs_src/nosql_databases/tutorial001.py - Cassandra example
  • docs_src/nosql_databases/tutorial001_scylla.py - ScyllaDB example
  • tests/test_tutorial/test_nosql_databases/ - Tests with mocked database
  • requirements-tests.txt - Removed cassandra-driver (tests use mocks)

Questions for Reviewers

  1. Is the mocked testing approach acceptable, or should integration tests with real databases be required before merging?
  2. Is the Python 3.14 conftest.py mocking approach acceptable?

@github-actions github-actions bot added the docs Documentation about how to use FastAPI label Nov 14, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Nov 14, 2025

@tiangolo
Copy link
Member

Thanks for the interest! I'm currently not using Cassandra, I wouldn't have the bandwidth to maintain this extra tutorial. So I'll pass on this one for now. Thanks! ☕

@tiangolo tiangolo closed this Feb 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation about how to use FastAPI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants