Skip to main content

Simple Couchbase helper for Python 3.8+ adding basic functionality

Project description

couchbase-helper: A simple helper package for Couchbase operations

pypi package downloads versions Tests coverage licence


Intro

While the Couchbase packages is easy enough to use, sometimes it also just requires some boilerplate code which becomes tiring to duplicate every time you need to perform simple document operations. At least, that's what I thought. So, I started creating a simple re-usable script which later became a class and ... well, here's Couchbase Helper!

Couchbase Helper is currently rather basic and mostly/only support the following operations fully:

  • insert
  • insert_multi
  • upsert
  • upsert_multi
  • replace
  • replace_multi
  • get
  • get_multi
  • remove
  • remove_multi

It currently also has very basic functionality for view queries (view_query) which isn't all that fancy. Follow issue #18 for updates on this.

An N1ql (SQL++) helper class is also available, which provides chainable methods to create SQL++ queries to select from indexes.

Installation

Installation is as you're used to, using your favorite package manager:

$ pip install couchbase-helper
... or
$ uv add couchbase-helper
... or
$ poetry add couchbase-helper
... and so on

Examples

Basic operations

from couchbase_helper import CouchbaseHelper, Session

# Connect to Couchbase server/cluster
session = Session(
    hostname="localhost",
    username="username",
    password="password",
    bucket="bucket",
    timeout=10,
)
cb = CouchbaseHelper(
    session=session,
)

# Insert document
document = {
    "foo": "bar"
}
cb.insert("foo1", document)

# Get document
document = cb.get("foo1")
print(document["foo"])  # bar

# Update document
document["hello"] = "world"
cb.upsert("foo1", document)

# Replace a document
new_document = {
    "bar": "baz"
}
cb.replace("foo1", new_document)

SQL++/N1QL examples

from couchbase_helper import Session
from couchbase_helper.n1ql import N1ql

# Connect to Couchbase server/cluster
session = Session(
    hostname="localhost",
    username="username",
    password="password",
    bucket="bucket",
    timeout=10,
)
session.connect()
n1ql = N1ql(session=session)

# Select documents where foo=bar
rows = n1ql.where("foo=", "bar").rows()
for row in rows:
    ...

# You can also select specific columns, from a different bucket , scope, or even collection than the session's:
rows = n1ql.select("callsign").from_("travel-sample", "inventory", "airport").where("city=", "San Jose").or_where("city=", "New York").rows()
for row in rows:
    ...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

couchbase_helper-0.1.2.tar.gz (17.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

couchbase_helper-0.1.2-py3-none-any.whl (16.9 kB view details)

Uploaded Python 3

File details

Details for the file couchbase_helper-0.1.2.tar.gz.

File metadata

  • Download URL: couchbase_helper-0.1.2.tar.gz
  • Upload date:
  • Size: 17.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.9

File hashes

Hashes for couchbase_helper-0.1.2.tar.gz
Algorithm Hash digest
SHA256 2c7214aec12def084728041d1fec8b8227ad3d3d227a405e0c85b2ff079d03e0
MD5 256a83ba5cce96c3faed4b95387badb7
BLAKE2b-256 658807d56c48981208c3e2988f6f5da0c45796301001e9badb6eeee411b1757b

See more details on using hashes here.

File details

Details for the file couchbase_helper-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for couchbase_helper-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 35c92abe2f7f5d4d41bc86eedfadea096644e058e44c13b9300d72b3c314838b
MD5 4b610ac64be978c0ea4c266c916e23bf
BLAKE2b-256 7afaee274e894cfe2322c0b6e76b8fd90b6a040923456b7ec444a5d5eef1c289

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page