Prefect collection for connecting flows and tasks to Couchbase.
Project description
prefect-couchbase
A Prefect collection for connecting Prefect flows and tasks to Couchbase through the official Couchbase Python SDK.
What you can use it for
- Store Couchbase connection details as a Prefect block and load them safely from flows.
- Read, write, and delete documents from Couchbase buckets/scopes/collections in Prefect tasks.
- Run SQL++ queries from Prefect flows while reusing the same Couchbase SDK connection lifecycle.
This connector does not replace the Couchbase Python SDK. It provides Prefect-native credentials and a small convenience wrapper around the SDK so workflows can manage credentials, lifecycle, and common operations consistently.
End-user quickstart
Install the package:
pip install prefect-couchbase
Create and save a credentials block:
from prefect_couchbase import CouchbaseCredentials
credentials = CouchbaseCredentials(
connection_string="couchbases://cb.example.cloud.couchbase.com",
username="analytics_user",
password="super-secret-password",
)
credentials.save("prod-couchbase", overwrite=True)
Use the block from a flow:
from prefect import flow, task
from prefect_couchbase import CouchbaseCredentials
@task
def upsert_hotel(document_id: str, name: str) -> dict:
credentials = CouchbaseCredentials.load("prod-couchbase")
with credentials.get_connector(
bucket="travel-sample", scope="_default", collection="_default"
) as couchbase:
couchbase.upsert(document_id, {"type": "hotel", "name": name})
return couchbase.get(document_id)
@flow
def demo() -> dict:
return upsert_hotel("prefect::hotel::1", "Prefect Grand Hotel")
if __name__ == "__main__":
print(demo())
Expected output:
{'type': 'hotel', 'name': 'Prefect Grand Hotel'}
Provision Couchbase
Recommended: Couchbase Capella
Use Capella when Prefect Cloud workers or any hosted execution infrastructure need to reach Couchbase over the public internet.
- Create a Capella cluster.
- Create or choose a bucket, scope, and collection.
- Add a database user with access to the bucket.
- Add the worker's outbound IP address to Capella's allowed IP list.
- Use the Capella SDK connection string, which starts with
couchbases://. - Configure the Prefect block with the connection string, username, and password.
Local or self-managed Couchbase
Use local/self-managed Couchbase when your Prefect worker runs on the same machine or private network.
- Start Couchbase Server locally.
- Create a bucket such as
travel-sampleorprefect-demo. - Create a user with bucket read/write permissions.
- Use a connection string such as
couchbase://localhost.
For a quick local evaluation, the Couchbase Python SDK examples and Docker documentation are the best reference for the currently supported server image and initialization flow.
Configuration reference
CouchbaseCredentials fields:
| Field | Description |
|---|---|
connection_string |
Couchbase SDK connection string, such as couchbase://localhost or couchbases://cb.example.cloud.couchbase.com. |
username / password |
Password authentication credentials. Store these as Prefect secrets through the block. |
cert_path |
Optional trusted CA certificate path for password authentication; client certificate path for certificate authentication. |
key_path / trust_store_path |
Required with cert_path when using certificate authentication. |
profile |
Optional SDK config profile, for example wan_development. |
options |
Extra keyword arguments passed to couchbase.options.ClusterOptions. |
CouchbaseConnector methods:
get_bucket(bucket=None)get_scope(bucket=None, scope=None)get_collection(bucket=None, scope=None, collection=None)upsert(key, value, **kwargs)get(key, content_as=dict, **kwargs)remove(key, **kwargs)query(statement, *args, **kwargs)ping(**kwargs)close()
Tutorial: runnable local flow
-
Install dependencies:
pip install prefect-couchbase
-
Export connection settings:
export COUCHBASE_CONNECTION_STRING="couchbase://localhost" export COUCHBASE_USERNAME="Administrator" export COUCHBASE_PASSWORD="password" export COUCHBASE_BUCKET="travel-sample"
-
Save a credentials block once from the current environment:
python examples/save_credentials_block.py -
Run the example flow, which loads the saved block:
python examples/couchbase_flow.py -
Validate by checking that the flow prints:
Stored document: {'type': 'hotel', 'name': 'Prefect Grand Hotel'}
Troubleshooting
Authentication failed: verify username/password and bucket permissions.Unambiguous timeout: verify the worker can reach the cluster and that Capella allowed IPs include the worker.bucket must be provided: passbucket="..."toget_connector()or to the individual operation.- TLS errors with Capella: use a
couchbases://connection string and ensure the cluster endpoint is correct.
Developer documentation
Local development
git clone https://github.com/couchbase-examples/couchbase-prefect.git
cd couchbase-prefect
uv sync --extra dev
Run tests and coverage:
uv run pytest
Run linting:
uv run ruff check .
uv run ruff format --check .
Build the package:
uv run python -m build
Run the example smoke check without a live Couchbase cluster:
uv run python -m py_compile examples/save_credentials_block.py examples/couchbase_flow.py
Run the examples against a live cluster by setting the environment variables from the tutorial, saving the block with uv run python examples/save_credentials_block.py, and then executing uv run python examples/couchbase_flow.py.
Release and publishing path
- Ensure
uv run pytest,uv run ruff check ., anduv run python -m buildpass. - Update the version tag according to the repository release policy.
- Build distributions with
uv run python -m build. - Publish to PyPI or the chosen private package index with
twine upload dist/*after configuring maintainer credentials. - Register the collection with Prefect by installing the package in the worker environment. The package exposes the
prefect.collectionsentry pointprefect_couchbase = prefect_couchbase.
Research and design notes
This implementation follows Prefect's collection pattern from official integrations such as prefect-redis, prefect-snowflake, and prefect-sqlalchemy: typed Prefect blocks hold credentials and user code imports a small package-specific public API. It also mirrors the Couchbase authentication and collection access shape used by the Couchbase Airflow provider: password authentication uses PasswordAuthenticator, certificate authentication uses CertificateAuthenticator, and helper methods resolve bucket/scope/collection objects.
Known limitations
- The unit test suite uses SDK mocks so it can run without a live Couchbase service. Live connectivity should be validated in the environment where the Prefect worker runs.
- The connector intentionally exposes a minimal wrapper. Advanced SDK features should be accessed from
connector.clusteror native SDK objects returned byget_bucket,get_scope, andget_collection.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file prefect_couchbase-1.0.0.tar.gz.
File metadata
- Download URL: prefect_couchbase-1.0.0.tar.gz
- Upload date:
- Size: 203.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e6c200435c5c0e779b997620515abedfe1be324633c704dbad873e57227785a4
|
|
| MD5 |
f278ef9ecb1e80dd6189f9c5789c30b3
|
|
| BLAKE2b-256 |
2612ecfc2a04c18bbf3570ae7b0496db86dc7672d91c5aaa40b8e05faf72ab8f
|
Provenance
The following attestation bundles were made for prefect_couchbase-1.0.0.tar.gz:
Publisher:
release.yml on Couchbase-Ecosystem/prefect-couchbase
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
prefect_couchbase-1.0.0.tar.gz -
Subject digest:
e6c200435c5c0e779b997620515abedfe1be324633c704dbad873e57227785a4 - Sigstore transparency entry: 2287777599
- Sigstore integration time:
-
Permalink:
Couchbase-Ecosystem/prefect-couchbase@a43c648dc80844920becc940dd6ff0a428205dfc -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/Couchbase-Ecosystem
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a43c648dc80844920becc940dd6ff0a428205dfc -
Trigger Event:
push
-
Statement type:
File details
Details for the file prefect_couchbase-1.0.0-py3-none-any.whl.
File metadata
- Download URL: prefect_couchbase-1.0.0-py3-none-any.whl
- Upload date:
- Size: 9.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
95aab164e801ddb4d74046216c9c82b0bd08a84468b9ee4729be0d22bfd79ebf
|
|
| MD5 |
fca6eee302a2b85caf4b57b004842b81
|
|
| BLAKE2b-256 |
b36888c75a49fc6634704759274b5323681e08389cca2ef9b1d76bfd87acb2dc
|
Provenance
The following attestation bundles were made for prefect_couchbase-1.0.0-py3-none-any.whl:
Publisher:
release.yml on Couchbase-Ecosystem/prefect-couchbase
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
prefect_couchbase-1.0.0-py3-none-any.whl -
Subject digest:
95aab164e801ddb4d74046216c9c82b0bd08a84468b9ee4729be0d22bfd79ebf - Sigstore transparency entry: 2287777676
- Sigstore integration time:
-
Permalink:
Couchbase-Ecosystem/prefect-couchbase@a43c648dc80844920becc940dd6ff0a428205dfc -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/Couchbase-Ecosystem
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a43c648dc80844920becc940dd6ff0a428205dfc -
Trigger Event:
push
-
Statement type: