From e01623c37ae339cd60731758b3b3a8d0271fc62c Mon Sep 17 00:00:00 2001 From: Richard Smedley Date: Fri, 22 May 2026 18:01:52 +0100 Subject: [PATCH] DOC-13802 static method for connect --- modules/devguide/examples/python/acouchbase_analytics_ops.py | 2 +- modules/devguide/examples/python/acouchbase_n1ql_ops.py | 2 +- modules/devguide/examples/python/acouchbase_operations.py | 2 +- modules/devguide/examples/python/acouchbase_search_ops.py | 2 +- modules/devguide/examples/python/caching_fastapi.py | 2 +- modules/devguide/examples/python/caching_flask.py | 2 +- modules/devguide/examples/python/cert-auth.py | 2 +- modules/devguide/examples/python/cloud-delete-this.py | 2 +- modules/devguide/examples/python/connecting-ssl.py | 2 +- modules/devguide/examples/python/encrypting_using_sdk.py | 4 ++-- modules/devguide/examples/python/error_handling.py | 2 +- modules/devguide/examples/python/health_check.py | 2 +- modules/devguide/examples/python/import.py | 2 +- modules/devguide/examples/python/index_hello_world.py | 2 +- modules/devguide/examples/python/kv_bulk_hello_world.py | 2 +- modules/devguide/examples/python/kv_hello_world_scoped.py | 2 +- modules/devguide/examples/python/kv_operations.py | 2 +- modules/devguide/examples/python/logging_example.py | 2 +- modules/devguide/examples/python/managing_connections.py | 4 ++-- modules/devguide/examples/python/migrating.py | 2 +- modules/devguide/examples/python/orphan_logging.py | 2 +- .../examples/python/provisioning_resources_buckets.py | 2 +- .../examples/python/provisioning_resources_collections.py | 4 ++-- .../devguide/examples/python/provisioning_resources_users.py | 4 ++-- modules/devguide/examples/python/query_hello_world.py | 2 +- modules/devguide/examples/python/subdocument_ops.py | 4 ++-- modules/devguide/examples/python/threshold_logging.py | 4 ++-- modules/devguide/examples/python/transcoders.py | 2 +- modules/howtos/pages/observability-metrics.adoc | 2 +- modules/howtos/pages/sdk-authentication.adoc | 4 ++-- modules/project-docs/pages/migrating-sdk-code-to-3.n.adoc | 2 +- 31 files changed, 38 insertions(+), 38 deletions(-) diff --git a/modules/devguide/examples/python/acouchbase_analytics_ops.py b/modules/devguide/examples/python/acouchbase_analytics_ops.py index 6177c205..cbc1db68 100644 --- a/modules/devguide/examples/python/acouchbase_analytics_ops.py +++ b/modules/devguide/examples/python/acouchbase_analytics_ops.py @@ -6,7 +6,7 @@ async def get_couchbase(): - cluster = Cluster( + cluster = AsyncCluster.connect( "couchbase://your-ip", ClusterOptions(PasswordAuthenticator("Administrator", "password"))) bucket = cluster.bucket("travel-sample") diff --git a/modules/devguide/examples/python/acouchbase_n1ql_ops.py b/modules/devguide/examples/python/acouchbase_n1ql_ops.py index b8677b90..e699ac4b 100644 --- a/modules/devguide/examples/python/acouchbase_n1ql_ops.py +++ b/modules/devguide/examples/python/acouchbase_n1ql_ops.py @@ -6,7 +6,7 @@ async def get_couchbase(): - cluster = Cluster( + cluster = AsyncCluster.connect( "couchbase://your-ip", ClusterOptions(PasswordAuthenticator("Administrator", "password"))) bucket = cluster.bucket("travel-sample") diff --git a/modules/devguide/examples/python/acouchbase_operations.py b/modules/devguide/examples/python/acouchbase_operations.py index 41c6a8cf..171c73c7 100644 --- a/modules/devguide/examples/python/acouchbase_operations.py +++ b/modules/devguide/examples/python/acouchbase_operations.py @@ -25,7 +25,7 @@ async def get_couchbase(): - cluster = Cluster( + cluster = AsyncCluster.connect( "couchbase://your-ip", ClusterOptions(PasswordAuthenticator("Administrator", "password"))) bucket = cluster.bucket("travel-sample") diff --git a/modules/devguide/examples/python/acouchbase_search_ops.py b/modules/devguide/examples/python/acouchbase_search_ops.py index ef81ef1d..b7b76194 100644 --- a/modules/devguide/examples/python/acouchbase_search_ops.py +++ b/modules/devguide/examples/python/acouchbase_search_ops.py @@ -7,7 +7,7 @@ async def get_couchbase(): - cluster = Cluster( + cluster = AsyncCluster.connect( "couchbase://your-ip", ClusterOptions(PasswordAuthenticator("Administrator", "password"))) bucket = cluster.bucket("travel-sample") diff --git a/modules/devguide/examples/python/caching_fastapi.py b/modules/devguide/examples/python/caching_fastapi.py index e100400c..de1110f7 100644 --- a/modules/devguide/examples/python/caching_fastapi.py +++ b/modules/devguide/examples/python/caching_fastapi.py @@ -56,7 +56,7 @@ async def connect(self, **kwargs): cluster_opts = ClusterOptions( authenticator=PasswordAuthenticator( self.username, self.password)) - self._cluster = Cluster(conn_str, options=cluster_opts) + self._cluster = Cluster.connect(conn_str, options=cluster_opts) self._bucket = self._cluster.bucket(self.bucket_name) await self._bucket.on_connect() self._collection = self._bucket.default_collection() diff --git a/modules/devguide/examples/python/caching_flask.py b/modules/devguide/examples/python/caching_flask.py index 3432f045..439e5589 100644 --- a/modules/devguide/examples/python/caching_flask.py +++ b/modules/devguide/examples/python/caching_flask.py @@ -56,7 +56,7 @@ def connect(self, **kwargs): cluster_opts = ClusterOptions( authenticator=PasswordAuthenticator( self.username, self.password)) - self._cluster = Cluster(conn_str, options=cluster_opts) + self._cluster = Cluster.connect(conn_str, options=cluster_opts) self._bucket = self._cluster.bucket(self.bucket_name) self._collection = self._bucket.default_collection() except CouchbaseException as error: diff --git a/modules/devguide/examples/python/cert-auth.py b/modules/devguide/examples/python/cert-auth.py index 07ce499b..e825a3b6 100644 --- a/modules/devguide/examples/python/cert-auth.py +++ b/modules/devguide/examples/python/cert-auth.py @@ -16,5 +16,5 @@ key_path=os.path.join(clientdir, "client.key")) opts = ClusterOptions(CertificateAuthenticator(**options)) -cluster = Cluster('couchbase://your-ip', opts) +cluster = Cluster.connect('couchbase://your-ip', opts) # end::auth[] diff --git a/modules/devguide/examples/python/cloud-delete-this.py b/modules/devguide/examples/python/cloud-delete-this.py index c077b33d..22a2e9de 100644 --- a/modules/devguide/examples/python/cloud-delete-this.py +++ b/modules/devguide/examples/python/cloud-delete-this.py @@ -12,7 +12,7 @@ # User Input ends here. # Initialize the Connection -cluster = Cluster("couchbases://{}".format(endpoint), ClusterOptions( +cluster = Cluster.connect("couchbases://{}".format(endpoint), ClusterOptions( PasswordAuthenticator(username, password, cert_path=cert_path))) cb = cluster.bucket(bucket_name) cb_coll = cb.default_collection() diff --git a/modules/devguide/examples/python/connecting-ssl.py b/modules/devguide/examples/python/connecting-ssl.py index 65c2c1ed..dfa88569 100644 --- a/modules/devguide/examples/python/connecting-ssl.py +++ b/modules/devguide/examples/python/connecting-ssl.py @@ -24,7 +24,7 @@ # create a Cluster object -cb_cluster = Cluster("http://{}/".format(hostname)) +cb_cluster = Cluster.connect("http://{}/".format(hostname)) # create an SSL-based Authenticator authenticator = CertAuthenticator(cluster_username="admin", diff --git a/modules/devguide/examples/python/encrypting_using_sdk.py b/modules/devguide/examples/python/encrypting_using_sdk.py index 5e56279f..e434f16d 100644 --- a/modules/devguide/examples/python/encrypting_using_sdk.py +++ b/modules/devguide/examples/python/encrypting_using_sdk.py @@ -155,7 +155,7 @@ def decrypt_doc( # end::legacy_support[] # Create a configuration to connect to your cluster -cluster = Cluster( +cluster = Cluster.connect( "couchbase://your-ip", ClusterOptions(PasswordAuthenticator("Administrator", "password")), ) @@ -195,4 +195,4 @@ def decrypt_doc( # tag::decrypt_doc[] decrypted_user = decrypt_doc(crypto_mgr, result.content_as[dict], field_specs) print("Decrypted doc:\n{}".format(decrypted_user)) -# end::decrypt_doc[] \ No newline at end of file +# end::decrypt_doc[] diff --git a/modules/devguide/examples/python/error_handling.py b/modules/devguide/examples/python/error_handling.py index ee4eaf61..2a144b94 100644 --- a/modules/devguide/examples/python/error_handling.py +++ b/modules/devguide/examples/python/error_handling.py @@ -18,7 +18,7 @@ # ErrorContext is still uncommited in the Python SDK, ignore the runtime warnings for the example warnings.filterwarnings("ignore") -cluster = Cluster( +cluster = Cluster.connect( "couchbase://your-ip", authenticator=PasswordAuthenticator( "Administrator", diff --git a/modules/devguide/examples/python/health_check.py b/modules/devguide/examples/python/health_check.py index 70bc39f5..468185c5 100644 --- a/modules/devguide/examples/python/health_check.py +++ b/modules/devguide/examples/python/health_check.py @@ -14,7 +14,7 @@ def ok(cluster): # end::check_connection[] -cluster = Cluster( +cluster = Cluster.connect( "couchbase://your-ip", authenticator=PasswordAuthenticator( "Administrator", diff --git a/modules/devguide/examples/python/import.py b/modules/devguide/examples/python/import.py index b3cf4bc3..7b395de6 100644 --- a/modules/devguide/examples/python/import.py +++ b/modules/devguide/examples/python/import.py @@ -13,7 +13,7 @@ # tag::connect[] -cluster = Cluster( +cluster = Cluster.connect( "couchbase://localhost", authenticator=PasswordAuthenticator( "Administrator", "password")) diff --git a/modules/devguide/examples/python/index_hello_world.py b/modules/devguide/examples/python/index_hello_world.py index 7eabf75f..c33fcb1a 100644 --- a/modules/devguide/examples/python/index_hello_world.py +++ b/modules/devguide/examples/python/index_hello_world.py @@ -7,7 +7,7 @@ DropPrimaryQueryIndexOptions, WatchQueryIndexOptions) -cluster = Cluster('couchbase://localhost', ClusterOptions( +cluster = Cluster.connect('couchbase://localhost', ClusterOptions( PasswordAuthenticator('Administrator', 'password')) ) diff --git a/modules/devguide/examples/python/kv_bulk_hello_world.py b/modules/devguide/examples/python/kv_bulk_hello_world.py index 4b25b960..a1e04c04 100644 --- a/modules/devguide/examples/python/kv_bulk_hello_world.py +++ b/modules/devguide/examples/python/kv_bulk_hello_world.py @@ -1,6 +1,6 @@ from couchbase.cluster import Cluster, PasswordAuthenticator -cluster = Cluster("couchbase://localhost", +cluster = Cluster.connect("couchbase://localhost", authenticator=PasswordAuthenticator("Administrator", "password")) bucket = cluster.bucket("travel-sample") users_collection = bucket.scope("tenant_agent_00").collection("users") diff --git a/modules/devguide/examples/python/kv_hello_world_scoped.py b/modules/devguide/examples/python/kv_hello_world_scoped.py index 76c98c77..d3f01bbe 100644 --- a/modules/devguide/examples/python/kv_hello_world_scoped.py +++ b/modules/devguide/examples/python/kv_hello_world_scoped.py @@ -4,7 +4,7 @@ from couchbase.collection import GetOptions, InsertOptions, ReplaceOptions from couchbase_core import subdocument -cluster = Cluster("couchbase://localhost", +cluster = Cluster.connect("couchbase://localhost", authenticator=PasswordAuthenticator("Administrator", "password")) bucket = cluster.bucket("travel-sample") hotel_collection = bucket.scope("inventory").collection("hotel") diff --git a/modules/devguide/examples/python/kv_operations.py b/modules/devguide/examples/python/kv_operations.py index 274a840a..b54a4290 100644 --- a/modules/devguide/examples/python/kv_operations.py +++ b/modules/devguide/examples/python/kv_operations.py @@ -15,7 +15,7 @@ DecrementOptions) from couchbase.collection import DeltaValue, SignedInt64 -cluster = Cluster( +cluster = Cluster.connect( "couchbase://your-ip", authenticator=PasswordAuthenticator( "Administrator", diff --git a/modules/devguide/examples/python/logging_example.py b/modules/devguide/examples/python/logging_example.py index 19aaf171..102222e8 100644 --- a/modules/devguide/examples/python/logging_example.py +++ b/modules/devguide/examples/python/logging_example.py @@ -21,7 +21,7 @@ logger = logging.getLogger() couchbase.configure_logging(logger.name, level=logger.level) -cluster = Cluster('couchbase://your-ip', +cluster = Cluster.connect('couchbase://your-ip', ClusterOptions(PasswordAuthenticator("Administrator", "password"))) cluster.wait_until_ready(timedelta(seconds=3), diff --git a/modules/devguide/examples/python/managing_connections.py b/modules/devguide/examples/python/managing_connections.py index 491604aa..9104ed75 100644 --- a/modules/devguide/examples/python/managing_connections.py +++ b/modules/devguide/examples/python/managing_connections.py @@ -121,7 +121,7 @@ def test_async(self): print("reactivecluster") #tag::reactivecluster[] from acouchbase.bucket import Bucket - cluster = Cluster("couchbase://your-ip", ClusterOptions(PasswordAuthenticator("Administrator", "password")),bucket_class=Bucket) + cluster = AsyncCluster.connect("couchbase://your-ip", ClusterOptions(PasswordAuthenticator("Administrator", "password")),bucket_class=Bucket) bucket = cluster.bucket("travel-sample") # A reactive cluster's disconnect methods returns a Mono. @@ -143,7 +143,7 @@ def test_async(self): print("tls") #tag::tls[] - cluster = Cluster("couchbases://your-ip",ClusterOptions(PasswordAuthenticator("Administrator","password",cert_path="/path/to/cluster.crt"))) + cluster = Cluster.connect("couchbases://your-ip",ClusterOptions(PasswordAuthenticator("Administrator","password",cert_path="/path/to/cluster.crt"))) #end::tls[] print("dnssrv") diff --git a/modules/devguide/examples/python/migrating.py b/modules/devguide/examples/python/migrating.py index f3f16ea2..3b392f75 100644 --- a/modules/devguide/examples/python/migrating.py +++ b/modules/devguide/examples/python/migrating.py @@ -6,7 +6,7 @@ class Migrating(object): #tag::timeoutbuilder[] # SDK 3 equivalent -cluster=Cluster("couchbases://10.192.1.104") +cluster=Cluster.connect("couchbases://10.192.1.104") collection=cluster.bucket("default").default_collection() collection.timeout=5 #end::timeoutbuilder[] diff --git a/modules/devguide/examples/python/orphan_logging.py b/modules/devguide/examples/python/orphan_logging.py index 3a99b22d..a75ccd3e 100644 --- a/modules/devguide/examples/python/orphan_logging.py +++ b/modules/devguide/examples/python/orphan_logging.py @@ -29,7 +29,7 @@ authenticator = PasswordAuthenticator("Administrator", "password") cluster_opts = ClusterOptions(authenticator, orphan_reporting_options=orphan_opts) -cluster = Cluster("couchbase://your-ip", cluster_opts) +cluster = Cluster.connect("couchbase://your-ip", cluster_opts) # end::orphan_logging_config[] collection = cluster.bucket("beer-sample").default_collection() diff --git a/modules/devguide/examples/python/provisioning_resources_buckets.py b/modules/devguide/examples/python/provisioning_resources_buckets.py index 9ae8227d..f06a4d4f 100644 --- a/modules/devguide/examples/python/provisioning_resources_buckets.py +++ b/modules/devguide/examples/python/provisioning_resources_buckets.py @@ -24,7 +24,7 @@ def retry(func, *args, back_off=0.5, limit=5, **kwargs): # tag::create_bucket_mgr[] -cluster = Cluster( +cluster = Cluster.connect( "couchbase://your-ip", authenticator=PasswordAuthenticator( "Administrator", diff --git a/modules/devguide/examples/python/provisioning_resources_collections.py b/modules/devguide/examples/python/provisioning_resources_collections.py index eaccbea3..7a1d2b4f 100644 --- a/modules/devguide/examples/python/provisioning_resources_collections.py +++ b/modules/devguide/examples/python/provisioning_resources_collections.py @@ -38,7 +38,7 @@ def get_collection(collection_mgr, scope_name, coll_name): return None # end::listing-scope-collection[] -cluster = Cluster( +cluster = Cluster.connect( "couchbase://your-ip", authenticator=PasswordAuthenticator( "Administrator", @@ -57,7 +57,7 @@ def get_collection(collection_mgr, scope_name, coll_name): users.upsert_user(user) # end::scopeAdmin[] -cluster = Cluster( +cluster = Cluster.connect( "couchbase://your-ip", authenticator=PasswordAuthenticator( "scopeAdmin", diff --git a/modules/devguide/examples/python/provisioning_resources_users.py b/modules/devguide/examples/python/provisioning_resources_users.py index ec9a4f82..bb456d7c 100644 --- a/modules/devguide/examples/python/provisioning_resources_users.py +++ b/modules/devguide/examples/python/provisioning_resources_users.py @@ -8,7 +8,7 @@ username = "test-user" pw = "test-passw0rd!" -adm_cluster = Cluster( +adm_cluster = Cluster.connect( "couchbase://your-ip", authenticator=PasswordAuthenticator( "Administrator", @@ -46,7 +46,7 @@ # end::get_all_users[] # tag::user_operations[] -user_cluster = Cluster( +user_cluster = Cluster.connect( "couchbase://your-ip", authenticator=PasswordAuthenticator(username, pw)) diff --git a/modules/devguide/examples/python/query_hello_world.py b/modules/devguide/examples/python/query_hello_world.py index 5a299dfc..5942ffc9 100644 --- a/modules/devguide/examples/python/query_hello_world.py +++ b/modules/devguide/examples/python/query_hello_world.py @@ -1,7 +1,7 @@ from couchbase.cluster import Cluster, PasswordAuthenticator from couchbase.exceptions import CouchbaseException -cluster = Cluster("couchbase://localhost", +cluster = Cluster.connect("couchbase://localhost", authenticator=PasswordAuthenticator("Administrator", "password")) try: diff --git a/modules/devguide/examples/python/subdocument_ops.py b/modules/devguide/examples/python/subdocument_ops.py index 046b86a6..337fac5f 100644 --- a/modules/devguide/examples/python/subdocument_ops.py +++ b/modules/devguide/examples/python/subdocument_ops.py @@ -16,7 +16,7 @@ import couchbase.subdocument as SD from couchbase.options import ClusterOptions, MutateInOptions -cluster = Cluster('couchbase://your-ip', +cluster = Cluster.connect('couchbase://your-ip', ClusterOptions(PasswordAuthenticator('Administrator', 'password'))) bucket = cluster.bucket('travel-sample') @@ -295,4 +295,4 @@ print(('The version of the document on one of the server nodes ' 'did not have the requested field.')) print(f'Exception={ex}') -# end::lookup_in_all_replicas[] \ No newline at end of file +# end::lookup_in_all_replicas[] diff --git a/modules/devguide/examples/python/threshold_logging.py b/modules/devguide/examples/python/threshold_logging.py index 9b17d2b8..6d1ad125 100644 --- a/modules/devguide/examples/python/threshold_logging.py +++ b/modules/devguide/examples/python/threshold_logging.py @@ -28,7 +28,7 @@ auth = PasswordAuthenticator("Administrator", "password") cluster_opts = ClusterOptions(authenticator=auth, tracing_options=tracing_opts) -cluster = Cluster("couchbase://your-ip", cluster_opts) +cluster = Cluster.connect("couchbase://your-ip", cluster_opts) # end::threshold_logging_config[] collection = cluster.bucket("beer-sample").default_collection() @@ -37,4 +37,4 @@ try: collection.get("21st_amendment_brewery_cafe") except CouchbaseException: - logger.error(traceback.format_exc()) \ No newline at end of file + logger.error(traceback.format_exc()) diff --git a/modules/devguide/examples/python/transcoders.py b/modules/devguide/examples/python/transcoders.py index 3a812631..bf533270 100644 --- a/modules/devguide/examples/python/transcoders.py +++ b/modules/devguide/examples/python/transcoders.py @@ -17,7 +17,7 @@ from couchbase.exceptions import CouchbaseException, ValueFormatException from couchbase.transcoder import RawJSONTranscoder, RawStringTranscoder, RawBinaryTranscoder, Transcoder -cluster = Cluster("couchbase://your-ip", ClusterOptions( +cluster = Cluster.connect("couchbase://your-ip", ClusterOptions( PasswordAuthenticator("Administrator", "password"))) bucket = cluster.bucket("travel-sample") collection = bucket.default_collection() diff --git a/modules/howtos/pages/observability-metrics.adoc b/modules/howtos/pages/observability-metrics.adoc index 5a3a7183..54ebd364 100644 --- a/modules/howtos/pages/observability-metrics.adoc +++ b/modules/howtos/pages/observability-metrics.adoc @@ -30,7 +30,7 @@ metrics_opts = ClusterMetricsOptions(emit_interval=timedelta(minutes=5)) authenticator = PasswordAuthenticator("Administrator", "password") cluster_opts = ClusterOptions(authenticator=auth, metrics_options=metrics_opts) -cluster = Cluster("couchbase://your-ip", cluster_opts) +cluster = Cluster.connect("couchbases://your-ip", cluster_opts) ---- Once enabled, there is no further configuration needed. The `LoggingMeter` will emit the collected request statistics every interval. diff --git a/modules/howtos/pages/sdk-authentication.adoc b/modules/howtos/pages/sdk-authentication.adoc index 67119b48..eb4a964c 100644 --- a/modules/howtos/pages/sdk-authentication.adoc +++ b/modules/howtos/pages/sdk-authentication.adoc @@ -24,7 +24,7 @@ from couchbase.cluster import Cluster from couchbase.options import ClusterOptions -cluster = Cluster('couchbase://your-ip', +cluster = Cluster.connect('couchbases://your-ip', ClusterOptions(PasswordAuthenticator('username', 'password'))) ---- @@ -53,5 +53,5 @@ include::{version-common}@sdk:shared:partial$auth-overview.adoc[tag=ldap] # Use over TLS for production opts = ClusterOptions(PasswordAuthenticator('einstein', 'password')) connection_str = "couchbases://10.143.205.101?sasl_mech_force=PLAIN&certpath=cert.ca" -cluster = Cluster(connection_str, opts) +cluster = Cluster.connect(connection_str, opts) ---- diff --git a/modules/project-docs/pages/migrating-sdk-code-to-3.n.adoc b/modules/project-docs/pages/migrating-sdk-code-to-3.n.adoc index 678ccbc5..f09e66a1 100644 --- a/modules/project-docs/pages/migrating-sdk-code-to-3.n.adoc +++ b/modules/project-docs/pages/migrating-sdk-code-to-3.n.adoc @@ -38,7 +38,7 @@ As an example here is a KeyValue document fetch: from datetime import timedelta from couchbase.cluster import Cluster from couchbase.collection import GetOptions -cluster=Cluster("couchbases://10.192.1.104") +cluster=Cluster.connect("couchbases://10.192.1.104") collection=cluster.default_collection() get_result = collection.get("key", GetOptions(timeout=timedelta(seconds=3))) ----