| name | analytics-python |
| summary | Couchbase Analytics Service (CBAS) for Python — run OLAP queries, window functions, and external data links without impacting operational workloads (Server 6.x–7.x; use columnar-analytics for Server 8+) |
| description | Couchbase Analytics Service (CBAS) for Python — run OLAP queries, window functions, and external data links without impacting operational workloads (Server 6.x–7.x; use columnar-analytics for Server 8+) |
| compatibility | Python SDK 4.x. Requires couchbase>=4.0. |
| metadata | {"last_verified":"2026-05","min_server_version":"6.0","deprecated_by":"columnar-analytics","deprecated_since":"8.0","max_server_version":"7.6","handoff":[{"condition":"user is upgrading to Server 8.x and wants the columnar engine","skill":"columnar-analytics"},{"condition":"user asks about SQL++ queries","skill":"server-querying-python"},{"condition":"user wants to write results back to operational collections transactionally","type":"variant","skill":"transactions-python"}]} |
Couchbase Analytics — Python
Version disambiguation: This skill covers Couchbase Server 6.x–7.x (legacy CBAS). If the user mentions Server 8, Couchbase 8, or the columnar engine, route to columnar-analytics instead. If the server version is unknown, ask before proceeding.
Analytics runs OLAP queries on a shadow copy of your data, isolated from KV and Query Service workloads. Use it for aggregations, reports, and joins across large datasets.
Setup — Create an Analytics Collection
CREATE DATAVERSE myapp IF NOT EXISTS;
USE myapp;
CREATE ANALYTICS COLLECTION orders ON `myapp`.`_default`.`orders` IF NOT EXISTS;
SDK Query
from datetime import timedelta
from couchbase.options import AnalyticsOptions
result = cluster.analytics_query(
"SELECT country, COUNT(*) AS cnt FROM airlines GROUP BY country ORDER BY cnt DESC",
AnalyticsOptions(timeout=timedelta(minutes=5))
)
for row in result:
print(row)
Parameterized Query
result = cluster.analytics_query(
"SELECT * FROM orders WHERE status = $status AND total > $min_total",
AnalyticsOptions(named_parameters={"status": "pending", "min_total": 100})
)
Window Functions
SELECT name, country, stars,
RANK() OVER (PARTITION BY country ORDER BY stars DESC) AS rank_in_country
FROM hotels
WHERE stars IS NOT MISSING;
Analytics vs Query Service: See shared/server/analytics-vs-query.md for the full comparison, setup steps, and common errors.
Writing Results Back
Use transactions for atomic write-back, or individual KV upserts for non-atomic bulk writes.
result = cluster.analytics_query('SELECT id, total FROM orders WHERE status = "complete"')
collection = cluster.bucket('myapp').scope('_default').collection('summaries')
for row in result.rows():
collection.upsert(f"summary::{row['id']}", {'total': row['total']})
For atomic multi-document write-back, wrap in a transaction — see transactions-python.
When to Use Analytics vs Query Service
| Scenario | Use |
|---|
| Full collection scan + complex aggregation | Analytics |
| OLTP — point lookups, small result sets | Query Service |
| Report that would need many GSI indexes | Analytics |
| Real-time data (< 1s staleness) | Query Service |
Analytics data lags the operational store by seconds to minutes depending on ingestion rate.