Couchbase Python SDK 4.6
The Couchbase Python SDK allows Python applications to access a Couchbase cluster — Capella or self-managed.
What’s the point of a fast and scalable database if it’s not easy to develop for? Couchbase gives you the Python APIs to work with Capella, our managed solution, or self-managed options in your private Cloud or datacenter.
-
Data Ops (CRUD)
-
SQL++ Query (OLTP)
-
Vector Search
# Upsert with Durability level Majority
document = dict(foo="bar", bar="foo")
opts = UpsertOptions(durability=ServerDurability(Durability.MAJORITY))
result = collection.upsert("document-key", document, opts)
result = cluster.query(
"SELECT ts.* FROM `travel-sample`.inventory.airport WHERE city=$city",
QueryOptions(named_parameters={"city": "San Jose"}))
result = cluster.query(
"SELECT d.id, d.question, d.wanted_similar_color_from_search, " +
" ARRAY_CONCAT( " +
"d.couchbase_search_query.knn[0].vector[0:4], " +
"['...'] " +
") AS vector " +
"FROM `vector-sample`.`color`.`rgb-questions` AS d " +
"WHERE d.id = $id;",
QueryOptions(named_parameters={'id': '#87CEEB'})
for row in result.rows():
print(f"Found match: {row}")
Couchbase is a large platform — covering many services — and Couchbase SDKs are not thin wrappers generated around a REST API, but well thought out interfaces to the platform that make it easier to design and maintain your client code, and work with Couchbase in more natural ways for your platform. Install the SDK, and explore in the way that works best for you.
$ python3 -m pip install couchbase
The Couchbase Python SDK integrates into the Python ecosystem through a number of extensions and connectors, including:
Exploring the Python SDK
The links in the sections below will take you where you want to go — as will the navigation on the left-hand side of this page. But if you don’t know exactly where you need to go, try one of the following:
-
Our Quickstart Guide introduces the SDK with a quick install, and CRUD examples against the Data Service.
-
Couchbase’s familiar SQL-family query language and fuzzy search options (including vector search) are introduced on the Querying Your Data page.
-
The Python SDK docs are, necessarily, just a sub-set Python SDK API Reference — and a complete listing of all APIs can be found in the reference.
-
For a fuller orientation, there is a guide to the Python SDK docs
Using Your Database
How-to guides to help you start your development journey with Couchbase and the Python SDK.
-
For real-time analytics, see our Enterprise Analytics Python SDK
Resources
Useful resources to help support your development experience with Couchbase and the Python SDK.
Couchbase Operational Cluster Feature Compatibility
All of the SDKs have API compatibility with most of the features in Couchbase Operational Clusters — whether self-managed, or Capella. The following table covers possible exceptions, and gives the version of the Python SDK and Couchbase Server with which some features were introduced.
| Server 7.2 | Server 7.6.x | Server 8.0 | |
|---|---|---|---|
KV Range Scan |
N/A |
From 4.2.0 |
|
Zone aware replica reads |
N/A |
From 4.4.0 |
|
Vector Search with Search Vector Index |
N/A |
From 4.2.0 |
|
Vector Query using Hyperscale Vector Index |
N/A |
From SDK 4.5.0 ① |
|
Vector Query using Composite (GSI & vector) index |
N/A |
From SDK 4.5.0 ① |
|
Distributed ACID Transactions |
From 4.0.0 |
||
DNS SRV refresh for serverless environments (AWS Lambda, Azure Functions, and GCP Functions) |
From 4.1.5 |
||
Circuit Breakers |
From 3.0.0 |
||
OTel |
From 4.6.0 |
||
Field Level Encryption |
From 3.2.0 |
||
Cloud Native Gateway |
Unsupported |
||
| 1 | As part of the standard SDK SQL++ API, it should be compatible with all earlier versions of the SDK — but it has not been tested. |
|
Analytics SDKs
SDKs for Enterprise Analytics — Couchbase’s analytical database for real time apps and operational intelligence (RT-OLAP) — are available for the .NET, Go, Java, Node.js, and Python platforms. See the Enterprise Analytics SDK pages for more information. Currently, different SDKs are needed to connect to Capella Analytics — as this service does not have Enterprise Analytics' load balancer, and uses a different connection protocol. Capella Analytics SDKs (also known as Columnar SDKs) are available for the Go, Java, Node.js, and Python platforms. See the Capella Analytics SDK pages for more information. |