couchbase


Namecouchbase JSON
Version 3.2.0 PyPI version JSON
download
home_pagehttps://github.com/couchbase/couchbase-python-client
SummaryPython Client for Couchbase
upload_time2021-07-27 00:20:47
maintainer
docs_urlhttps://pythonhosted.org/couchbase/
authorCouchbase, Inc.
requires_python>=3.5
licenseApache License 2.0
keywords couchbase nosql pycouchbase libcouchbase
VCS
bugtrack_url
requirements typing-extensions mypy_extensions pip pyrsistent six attrs attrs wrapt durationpy
Travis-CI
coveralls test coverage
            # Couchbase Python Client
Python client for [Couchbase](https://couchbase.com)
>**NOTE:** This is the documentation for the 3.x version of the client. This is mostly compatible with the older version. Please refer to the *release25* branch for the older version.

# Contents<a id="contents"></a>
- [Prerequisites](#prerequisites)
- [Installing](#installing)
- [Building](#building)
- [Using the SDK](#using-the-sdk)
- [Building Documentation](#building-documentation)
- [Testing](#testing)
- [Contributing](#contributing)
- [Support & Additional Resources](#support-additional-resources)
- [License](#license)
- [Appendix](#appendix)

# Prerequisites<a id="prerequisites"></a>

- [Couchbase Server](http://couchbase.com/download)
- You may need a C compiler and Python development files, unless a
  binary wheel is available for your platform. Currently, wheels are only available on Windows for Python 3.7, 3.8 and 3.9. We will endeavor to add more.
- Git, if a binary wheel is not available.

## Debian and Ubuntu<a id="pre-deb-ubuntu"></a>

First-time setup:
```console
$ sudo apt install git-all python3-dev python3-pip python3-setuptools cmake build-essential
```

For TLS/SSL support:
```console
$ sudo apt install libssl-dev
```

See [Debian and Ubuntu](#install-deb-ubuntu) install section to install SDK.

## RHEL and CentOS<a id="pre-rhel-centos"></a>

First-time setup:
```console
$ sudo yum install git-all gcc gcc-c++ python3-devel python3-pip python3-setuptools cmake
```

>**NOTE:** The minimum version of CMake support is 3.5.1.  Check out the steps [here](https://idroot.us/install-cmake-centos-8/) to update CMake.

For TLS/SSL support:
```console
$ sudo yum install openssl-devel
```

See [RHEL and Centos](#install-rhel-centos) install section to install SDK.

## Mac OS<a id="pre-macos"></a>

It is not recommended to use the vendor-supplied Python that ships with OS X. Best practice is to use a Python virtual environment such as pyenv or venv (after another version of Python that is not vendor-supplied has been installed) to manage multiple versions of Python.

>:exclamation:**IMPORTANT**:exclamation:<br>There can be a problem when using the Python (3.8.2) that ships with Xcode on Catalina.    It is advised to install Python with one of the following:
>- [pyenv](#macos-pyenv)
>- [Homebrew](#macos-homebrew)
>- Install Python via [python.org](https://www.python.org/downloads)

### pyenv<a id="macos-pyenv"></a>

See detailed walk through in [Appendix](#appendix-pyenv).  Also, see pyenv install [docs](https://github.com/pyenv/pyenv#homebrew-on-macos) for further details.

### Homebrew<a id="macos-homebrew"></a>

See Homebrew install [docs](https://brew.sh/) for further details.

Get the latest packages:
```console
$ brew update
```

Install Python:
```console
$ brew install python
```

Update path:

- **zsh:**
    ```console
    $ echo 'export PATH="/usr/local/bin:"$PATH' >> ~/.zshrc
    ```
- **bash:**
    ```console
    $ echo 'export PATH="/usr/local/bin:"$PATH' >> ~/.bash_profile
    ```

For TLS/SSL support:
```console
$ brew install openssl
```

See [Mac OS](#install-macos) install section to install SDK.

## Windows<a id="pre-windows"></a>

Wheels are available on Windows for Python 3.7, 3.8 and 3.9.
>**NOTE:** Python 3.9 wheel was released with v 3.1.2 of the SDK  

Best practice is to use a Python virtual environment such as venv or pyenv (checkout the [pyenv-win](https://github.com/pyenv-win/pyenv-win) project) to manage multiple versions of Python.

If wanting to install from source, see the [Windows building](#building-windows) section for details.

See [Windows install](#install-windows) section to install SDK.

# Installing<a id="installing"></a>
[Back to Contents](#contents)

You can always get the latest supported release version from [pypi](https://pypi.org/project/couchbase/).

>**NOTE:** If you have a recent version of *pip*, you may use the latest development version by issuing the following incantation:
>```console
>pip install git+git://github.com/couchbase/couchbase-python-client
>```

>**NOTE:** Currently the Python Client source distribution requires the OpenSSL headers and libraries that the Python client itself was built against to be installed prior to the client itself for TLS support to be provided. Additionally the installer relies on PEP517 which older versions of PIP do not support. If you experience issues installing it is advised to upgrade your PIP/setuptools installation as follows:<br>
>```console
>python3 -m pip install --upgrade pip setuptools wheel
>```


## Debian and Ubuntu<a id="install-deb-ubuntu"></a>

First, make sure the [prerequisites](#pre-deb-ubuntu) have been installed.

Install the SDK:
```console
$ python3 -m pip install couchbase
```

## RHEL and CentOS<a id="install-rhel-centos"></a>

First, make sure the [prerequisites](#pre-rhel-centos) have been installed.

Install the SDK:
```console
$ python3 -m pip install couchbase
```

## Mac OS<a id="install-macos"></a>

First, make sure the [prerequisites](#pre-macos) have been installed.

Install the SDK:
```console
$ python -m pip install couchbase
```


## Windows<a id="install-windows"></a>

First, make sure the [prerequisites](#pre-windows) have been installed.

>**NOTE:** Commands assume user is working within a virtual environment.  For example, the following commands have been executed after downloading and installing Python from [python.org](https://www.python.org/downloads/):<br>
>-```C:\Users\Administrator\AppData\Local\Programs\Python\Python39\python -m venv C:\python\python39```<br>
>-```C:\python\python39\Scripts\activate```

Install the SDK (if using Python 3.7, 3.8 or 3.9):
```console
python -m pip install couchbase
```

### Alternative Installation Methods<a id="install-windows-alt"></a>

In order to successfully install with the following methods, ensure a proper build system is in place (see the [Windows building](#building-windows) section for details).

#### Source Install (i.e. no wheel)

First, ensure all the [requirements](#building-windows) for a build system are met. 

Install the SDK:
```console
python -m pip install couchbase --no-binary couchbase
```

#### Local Install

First, ensure all the [requirements](#building-windows) for a build system are met.

Clone this Python SDK repository:
```console
git clone --depth 1 --branch <tag_name> https://github.com/couchbase/couchbase-python-client.git
```

>Where tag_name is equal to the latest release.<br>
Example: ```git clone --depth 1 --branch 3.1.2 https://github.com/couchbase/couchbase-python-client.git```

Move into the directory created after cloning the Python SDK repository:
```console
cd couchbase-python-client
```

Install the SDK from source:
```console
python -m pip install .
```

## Anaconda/Miniconda<a id="install-anaconda"></a>

To use the SDK within the Anaconda/Miniconda platform, make sure the prerequisites for the desired Operating System are met:
- [Debian and Ubuntu](#pre-deb-ubuntu)
- [RHEL and Centos](#pre-rhel-centos)
- [Mac OS](#pre-macos)
- [Windows](#pre-windows)

In the *Anaconda Prompt*, create a new environment:
```console
(base) C:\Users\user1>conda create -n test_env python=3.9
```

Activate the environment
```console
(base) C:\Users\user1>conda activate test_env
```

Install the SDK:
```console
(test_env) C:\Users\user1>python -m pip install couchbase
```

>**NOTE:** If using Windows, and no wheel is available, see the [Alternative Install Methods Windows](#install-windows-alt) section.  The same process should work within the Anaconda/Miniconda platform.

# Building<a id="building"></a>
[Back to Contents](#contents)

>**NOTE:** This section only applies to building from source.

## Build System Setup
### Linux<a id="building-linux"></a>

Make sure the prerequisites have been installed:
- [Debian and Ubuntu](#pre-deb-ubuntu)
- [RHEL and Centos](#pre-rhel-centos)

### Mac OS<a id="building-macos"></a>
First, make sure the [prerequisites](#pre-macos) have been installed.

Install cmake:
```console
$ brew install cmake
```

Install command line developer tools:
```
$ xcode-select --install
```

>**NOTE:** It is possible that installing or updating to the the latest version of [Xcode](https://developer.apple.com/download) is needed.

If setuptools is not installed:
```console
$ python -m pip install setuptools
```

### Windows<a id="building-windows"></a>
#### Requirements
- Download and install [Git](https://git-scm.com/downloads)
- Download and install [Visual Studio 2019](https://visualstudio.microsoft.com/downloads/)
    + Check *Desktop development with C++* prior to installing
- Download and install [CMake](https://cmake.org/download/) >= v 3.5.1
- Download and install [Python](https://www.python.org/downloads/)

#### VS2019 Notes

If seeing issues when trying to build (steps in [](#)), some things to check/try:
- Try running the build commands within the *Developer Command Prompt for VS2019*
- Make sure *MSBuild* can find the correct *VCTargetsPath*
    + It is possible the *VCTargetsPath* environment variable needs to be set.  The below example is based on a typical path, but the actual setting should match that of your current environment setup.
        * ```set VCTargetsPath=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160```
- Make sure *CMake* is picking up the correct generator
    + It is possible the *CMAKE_GENERATOR* environment variable needs to be set
        * ```set CMAKE_GENERATOR=Visual Studio 16 2019```

#### VS2015 & VS2017 Notes

While it is possible to use VS2015 or VS2017 build tools, it is recommended to use the VS2019 path.  Some things to note if using the VS2015 or VS2017:
- Make sure *CMake* is picking up the correct generator
    + It is possible the *CMAKE_GENERATOR* environment variable needs to be set
        * VS2015 example:  ```set CMAKE_GENERATOR=Visual Studio 14 2015```
- Make sure *MSBuild* can be found
    + It is possible an environment variable needs to be set
- Make sure the correct [Windows SDK](https://developer.microsoft.com/en-us/windows/downloads/sdk-archive/) is installed
- Make sure *MSBuild* can find the correct *VCTargetsPath*
    + It is possible the *VCTargetsPath* environment variable needs to be set.  The below example is based on a typical path, but the actual setting should match that of your current environment setup.
        * ```set VCTargetsPath=C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\v140```
- MSBuild can run into [issues with MAX_PATH limits](https://github.com/dotnet/msbuild/issues/53#issuecomment-459062618) when using ```python -m pip install couchbase```.  This isn't fixed until MSBuild 16.0 so it is recommended to move to VS2019 (comes with MSBuild 16.0).

## Build the Python SDK
Clone this Python SDK repository:
```console
git clone https://github.com/couchbase/couchbase-python-client.git
```

Move into the directory created after cloning the Python SDK repository:
```console
cd couchbase-python-client
```

The following will compile the module locally:
```console
python setup.py build_ext --inplace
```

If you have a libcouchbase install already (in, for example, /opt/local/libcouchbase), you may build using it by setting PYCBC_BUILD=DISTUTILS and some add extra directives, like so:
```console
$ export PYCBC_BUILD=DISTUTILS
$ python setup.py build_ext --inplace \
    --library-dir /opt/local/libcouchbase/lib \
    --include-dir /opt/local/libcouchbase/include
```

You can also modify the environment ```CFLAGS``` and ```LDFLAGS``` variables.

>:exclamation:**WARNING:** If you do not intend to install this module, ensure you set the ```PYTHONPATH``` environment variable to this directory before running any scripts depending on it. Failing to do so may result in your script running against an older version of this module (if installed), or throwing an exception stating that the ```couchbase``` module could not be found.

## Install
```console
pip install .
```

>:exclamation:**WARNING:** If you are on Linux/Mac OS you may need to remove the build directory: ```rm -rf ./build``` before installing with pip: ```pip3 install .```.

# Using the SDK<a id="using-the-sdk"></a>
[Back to Contents](#contents)

## Connecting<a id="sdk-connecting"></a>

See [official documentation](https://docs.couchbase.com/python-sdk/current/howtos/managing-connections.html) for further details on connecting.

```python
# needed for any cluster connection
from couchbase.cluster import Cluster, ClusterOptions
from couchbase.auth import PasswordAuthenticator

# needed to support SQL++ (N1QL) query
from couchbase.cluster import QueryOptions

# get a reference to our cluster
cluster = Cluster('couchbase://localhost', ClusterOptions(
  PasswordAuthenticator('Administrator', 'password')))
```

>**NOTE:** Authentication is handled differently depending on what version of Couchbase Server you are using.  In Couchbase Server >= 5.0, Role-Based Access Control (RBAC) provides discrete username and passwords for an application that allow fine-grained control. The authenticator is always required.

## Basic Operations<a id="sdk-basic-ops"></a>

See official documentation for further details on [Working with Data](https://docs.couchbase.com/python-sdk/current/howtos/kv-operations.html).

Building upon the example code in the [Connecting](#sdk-connecting) section:

```python
# get a reference to our bucket
cb = cluster.bucket('travel-sample')

# get a reference to the default collection
cb_coll = cb.default_collection()

# get a document
result = cb_coll.get('airline_10')
print(result.content_as[dict])

# using SQL++ (a.k.a N1QL)
call_sign = 'CBS'
sql_query = 'SELECT VALUE name FROM `travel-sample` WHERE type = "airline" AND callsign = $1'
row_iter = cluster.query(sql_query, QueryOptions(positional_parameters=[call_sign]))
for row in row_iter: 
    print(row)
```

## Async Operations<a id="sdk-async-ops"></a>
The Python Couchbase SDK supports asynchronous I/O through the use of the asyncio (Python standard library) or the Twisted async framework.

>**NOTE:** Currently, the gcouchbase API is not available in the 3.x version of the Python SDK.

### Asyncio

To use asyncio, import ```acouchbase.cluster``` instead of ```couchbase.cluster```.  The ```acouchbase``` API offers an API similar to the ```couchbase``` API.

```python
from acouchbase.cluster import Cluster, get_event_loop
from couchbase.cluster import ClusterOptions
from couchbase.auth import PasswordAuthenticator


async def write_and_read(key, value):
    cluster = Cluster('couchbase://localhost',
                      ClusterOptions(PasswordAuthenticator('Administrator', 'password')))
    cb = cluster.bucket('default')
    await cb.on_connect()
    cb_coll = cb.default_collection()
    await cb_coll.upsert(key, value)
    result = await cb_coll.get(key)
    cluster.disconnect()
    return result

loop = get_event_loop()
rv = loop.run_until_complete(write_and_read('foo', 'bar'))
print(rv.content_as[str])
```
### Twisted

To use with Twisted, import ```txcouchbase.cluster``` instead of ```couchbase.cluster```.  The ```txcouchbase``` API offers an API similar to the ```couchbase``` API.

```python
from twisted.internet import reactor, defer

from txcouchbase.cluster import TxCluster
from couchbase.cluster import ClusterOptions
from couchbase.auth import PasswordAuthenticator


def after_upsert(res, key, d):
    print('Set key.  Result CAS: ', res.cas)
    # trigger get_document callback
    d.callback(key)

def upsert_document(key, doc):
    d = defer.Deferred()
    res = cb.upsert(key, doc)
    res.addCallback(after_upsert, key, d)
    return d

def on_get(res, _type=str):
    print('Got res: \n', res.content_as[_type])
    reactor.stop()

def get_document(key):
    res = cb.get(key)
    res.addCallback(on_get)


# create a cluster object
cluster = TxCluster('couchbase://localhost',
                    ClusterOptions(PasswordAuthenticator('Administrator', 'password')))

# create a bucket object
bucket = cluster.bucket('default')
# create a collection object
cb = bucket.default_collection()

d = upsert_document('testDoc_1', {'id': 1, 'type': 'testDoc', 'info': 'fake document'})
d.addCallback(get_document)

reactor.run()
```
# Building Documentation<a id="building-documentation"></a>
[Back to Contents](#contents)

The documentation is using Sphinx and also needs the numpydoc Sphinx extension. In order for the documentation to build properly, the C extension must have been built, since there are embedded docstrings in there as well.

To build the documentation, go into the docs directory and run:
```console
make html
```
The HTML output can be found in docs/build/html/.

Alternatively, you can also build the documentation (after building the module itself) from the top-level directory:
```console
python setup.py build_sphinx
```

Once built, the docs will be in in build/sphinx/html.

# Testing<a id="testing"></a>
[Back to Contents](#contents)

For running the tests, you need the standard unittest module, shipped with Python. Additionally, the testresources package is required.

To run them, use either py.test, unittest or trial.

The tests need a running Couchbase instance. For this, a tests.ini file must be present, containing various connection parameters. An example of this file may be found in tests.ini.sample. You may copy this file to tests.ini and modify the values as needed.

To run the tests:
```console
nosetests
```

# Contributing<a id="contributing"></a>
[Back to Contents](#contents)

We welcome contributions from the community!  Please see follow the steps outlined [here](https://github.com/couchbase/couchbase-python-client/blob/master/CONTRIBUTING.md) to get started.

# License
[Back to Contents](#contents)

The Couchbase Python SDK is licensed under the Apache License 2.0.

# Support & Additional Resources<a id="support-additional-resources"></a>
[Back to Contents](#contents)

If you found an issue, please file it in our [JIRA](http://couchbase.com/issues/browse/pycbc). You can ask questions in our [forums](https://forums.couchbase.com/).

The [official documentation](https://docs.couchbase.com/python-sdk/current/hello-world/start-using-sdk.html) can be consulted as well for general Couchbase concepts and offers a more didactic approach to using the SDK.

# Appendix<a id="appendix"></a>
[Back to Contents](#contents)

### Mac OS pyenv Install<a id="appendix-pyenv"></a>
See pyenv install [docs](https://github.com/pyenv/pyenv#homebrew-on-macos) for further details.

Get the latest packages:
```console
$ brew update
```

For TLS/SSL support:
```console
$ brew install openssl
```

Install pyenv:
```console
$ brew install pyenv
```

>**NOTE:** It is possible that Xcode might need to be reinstalled.  Try **one** of the following:<br>
>- Use command ```xcode-select --install```
>- Install the latest version of [Xcode](https://developer.apple.com/download)

For *Zsh*, run the following commands to update *.zprofile* and *.zshrc*.  See pyenv install [docs](https://github.com/pyenv/pyenv#homebrew-on-macos) for further details on other shells.

```console
$ echo 'eval "$(pyenv init --path)"' >> ~/.zprofile
```

```console
$ echo 'eval "$(pyenv init -)"' >> ~/.zshrc
```

>**NOTE:** You need to restart your login session for changes to take affect.  On MacOS, restarting terminal windows should suffice.

Install Python version:
```console
$ pyenv install 3.9.4
```

Set local shell to installed Python version:
```console
$  pyenv local 3.9.4
```

To use virtualenvwrapper with pyenv, install pyenv-virtualenvwrapper:
```console
$ brew install pyenv-virtualenvwrapper
```

To setup a virtualenvwrapper in your pyenv shell, run either ```pyenv virtualenvwrapper``` or ```pyenv virtualenvwrapper_lazy```

>**NOTE:** If issues with ```pyenv virtualenvwrapper```, using ```python -m pip install virtualenvwrapper``` should accomplish the same goal.

Make a virtualenv:
```console
$ mkvirtualenv python-3.9.4-test
```

Install the SDK:
```console
$ python -m pip install couchbase
```


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/couchbase/couchbase-python-client",
    "name": "couchbase",
    "maintainer": "",
    "docs_url": "https://pythonhosted.org/couchbase/",
    "requires_python": ">=3.5",
    "maintainer_email": "",
    "keywords": "couchbase,nosql,pycouchbase,libcouchbase",
    "author": "Couchbase, Inc.",
    "author_email": "PythonPackage@couchbase.com",
    "download_url": "https://files.pythonhosted.org/packages/ea/6e/5bda2ba94e0173f69026631df9e73eed42885ba0c9e5e183bb6a8f1bc3f9/couchbase-3.2.0.tar.gz",
    "platform": "",
    "description": "# Couchbase Python Client\nPython client for [Couchbase](https://couchbase.com)\n>**NOTE:** This is the documentation for the 3.x version of the client. This is mostly compatible with the older version. Please refer to the *release25* branch for the older version.\n\n# Contents<a id=\"contents\"></a>\n- [Prerequisites](#prerequisites)\n- [Installing](#installing)\n- [Building](#building)\n- [Using the SDK](#using-the-sdk)\n- [Building Documentation](#building-documentation)\n- [Testing](#testing)\n- [Contributing](#contributing)\n- [Support & Additional Resources](#support-additional-resources)\n- [License](#license)\n- [Appendix](#appendix)\n\n# Prerequisites<a id=\"prerequisites\"></a>\n\n- [Couchbase Server](http://couchbase.com/download)\n- You may need a C compiler and Python development files, unless a\n  binary wheel is available for your platform. Currently, wheels are only available on Windows for Python 3.7, 3.8 and 3.9. We will endeavor to add more.\n- Git, if a binary wheel is not available.\n\n## Debian and Ubuntu<a id=\"pre-deb-ubuntu\"></a>\n\nFirst-time setup:\n```console\n$ sudo apt install git-all python3-dev python3-pip python3-setuptools cmake build-essential\n```\n\nFor TLS/SSL support:\n```console\n$ sudo apt install libssl-dev\n```\n\nSee [Debian and Ubuntu](#install-deb-ubuntu) install section to install SDK.\n\n## RHEL and CentOS<a id=\"pre-rhel-centos\"></a>\n\nFirst-time setup:\n```console\n$ sudo yum install git-all gcc gcc-c++ python3-devel python3-pip python3-setuptools cmake\n```\n\n>**NOTE:** The minimum version of CMake support is 3.5.1.  Check out the steps [here](https://idroot.us/install-cmake-centos-8/) to update CMake.\n\nFor TLS/SSL support:\n```console\n$ sudo yum install openssl-devel\n```\n\nSee [RHEL and Centos](#install-rhel-centos) install section to install SDK.\n\n## Mac OS<a id=\"pre-macos\"></a>\n\nIt is not recommended to use the vendor-supplied Python that ships with OS X. Best practice is to use a Python virtual environment such as pyenv or venv (after another version of Python that is not vendor-supplied has been installed) to manage multiple versions of Python.\n\n>:exclamation:**IMPORTANT**:exclamation:<br>There can be a problem when using the Python (3.8.2) that ships with Xcode on Catalina.    It is advised to install Python with one of the following:\n>- [pyenv](#macos-pyenv)\n>- [Homebrew](#macos-homebrew)\n>- Install Python via [python.org](https://www.python.org/downloads)\n\n### pyenv<a id=\"macos-pyenv\"></a>\n\nSee detailed walk through in [Appendix](#appendix-pyenv).  Also, see pyenv install [docs](https://github.com/pyenv/pyenv#homebrew-on-macos) for further details.\n\n### Homebrew<a id=\"macos-homebrew\"></a>\n\nSee Homebrew install [docs](https://brew.sh/) for further details.\n\nGet the latest packages:\n```console\n$ brew update\n```\n\nInstall Python:\n```console\n$ brew install python\n```\n\nUpdate path:\n\n- **zsh:**\n    ```console\n    $ echo 'export PATH=\"/usr/local/bin:\"$PATH' >> ~/.zshrc\n    ```\n- **bash:**\n    ```console\n    $ echo 'export PATH=\"/usr/local/bin:\"$PATH' >> ~/.bash_profile\n    ```\n\nFor TLS/SSL support:\n```console\n$ brew install openssl\n```\n\nSee [Mac OS](#install-macos) install section to install SDK.\n\n## Windows<a id=\"pre-windows\"></a>\n\nWheels are available on Windows for Python 3.7, 3.8 and 3.9.\n>**NOTE:** Python 3.9 wheel was released with v 3.1.2 of the SDK  \n\nBest practice is to use a Python virtual environment such as venv or pyenv (checkout the [pyenv-win](https://github.com/pyenv-win/pyenv-win) project) to manage multiple versions of Python.\n\nIf wanting to install from source, see the [Windows building](#building-windows) section for details.\n\nSee [Windows install](#install-windows) section to install SDK.\n\n# Installing<a id=\"installing\"></a>\n[Back to Contents](#contents)\n\nYou can always get the latest supported release version from [pypi](https://pypi.org/project/couchbase/).\n\n>**NOTE:** If you have a recent version of *pip*, you may use the latest development version by issuing the following incantation:\n>```console\n>pip install git+git://github.com/couchbase/couchbase-python-client\n>```\n\n>**NOTE:** Currently the Python Client source distribution requires the OpenSSL headers and libraries that the Python client itself was built against to be installed prior to the client itself for TLS support to be provided. Additionally the installer relies on PEP517 which older versions of PIP do not support. If you experience issues installing it is advised to upgrade your PIP/setuptools installation as follows:<br>\n>```console\n>python3 -m pip install --upgrade pip setuptools wheel\n>```\n\n\n## Debian and Ubuntu<a id=\"install-deb-ubuntu\"></a>\n\nFirst, make sure the [prerequisites](#pre-deb-ubuntu) have been installed.\n\nInstall the SDK:\n```console\n$ python3 -m pip install couchbase\n```\n\n## RHEL and CentOS<a id=\"install-rhel-centos\"></a>\n\nFirst, make sure the [prerequisites](#pre-rhel-centos) have been installed.\n\nInstall the SDK:\n```console\n$ python3 -m pip install couchbase\n```\n\n## Mac OS<a id=\"install-macos\"></a>\n\nFirst, make sure the [prerequisites](#pre-macos) have been installed.\n\nInstall the SDK:\n```console\n$ python -m pip install couchbase\n```\n\n\n## Windows<a id=\"install-windows\"></a>\n\nFirst, make sure the [prerequisites](#pre-windows) have been installed.\n\n>**NOTE:** Commands assume user is working within a virtual environment.  For example, the following commands have been executed after downloading and installing Python from [python.org](https://www.python.org/downloads/):<br>\n>-```C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python39\\python -m venv C:\\python\\python39```<br>\n>-```C:\\python\\python39\\Scripts\\activate```\n\nInstall the SDK (if using Python 3.7, 3.8 or 3.9):\n```console\npython -m pip install couchbase\n```\n\n### Alternative Installation Methods<a id=\"install-windows-alt\"></a>\n\nIn order to successfully install with the following methods, ensure a proper build system is in place (see the [Windows building](#building-windows) section for details).\n\n#### Source Install (i.e. no wheel)\n\nFirst, ensure all the [requirements](#building-windows) for a build system are met. \n\nInstall the SDK:\n```console\npython -m pip install couchbase --no-binary couchbase\n```\n\n#### Local Install\n\nFirst, ensure all the [requirements](#building-windows) for a build system are met.\n\nClone this Python SDK repository:\n```console\ngit clone --depth 1 --branch <tag_name> https://github.com/couchbase/couchbase-python-client.git\n```\n\n>Where tag_name is equal to the latest release.<br>\nExample: ```git clone --depth 1 --branch 3.1.2 https://github.com/couchbase/couchbase-python-client.git```\n\nMove into the directory created after cloning the Python SDK repository:\n```console\ncd couchbase-python-client\n```\n\nInstall the SDK from source:\n```console\npython -m pip install .\n```\n\n## Anaconda/Miniconda<a id=\"install-anaconda\"></a>\n\nTo use the SDK within the Anaconda/Miniconda platform, make sure the prerequisites for the desired Operating System are met:\n- [Debian and Ubuntu](#pre-deb-ubuntu)\n- [RHEL and Centos](#pre-rhel-centos)\n- [Mac OS](#pre-macos)\n- [Windows](#pre-windows)\n\nIn the *Anaconda Prompt*, create a new environment:\n```console\n(base) C:\\Users\\user1>conda create -n test_env python=3.9\n```\n\nActivate the environment\n```console\n(base) C:\\Users\\user1>conda activate test_env\n```\n\nInstall the SDK:\n```console\n(test_env) C:\\Users\\user1>python -m pip install couchbase\n```\n\n>**NOTE:** If using Windows, and no wheel is available, see the [Alternative Install Methods Windows](#install-windows-alt) section.  The same process should work within the Anaconda/Miniconda platform.\n\n# Building<a id=\"building\"></a>\n[Back to Contents](#contents)\n\n>**NOTE:** This section only applies to building from source.\n\n## Build System Setup\n### Linux<a id=\"building-linux\"></a>\n\nMake sure the prerequisites have been installed:\n- [Debian and Ubuntu](#pre-deb-ubuntu)\n- [RHEL and Centos](#pre-rhel-centos)\n\n### Mac OS<a id=\"building-macos\"></a>\nFirst, make sure the [prerequisites](#pre-macos) have been installed.\n\nInstall cmake:\n```console\n$ brew install cmake\n```\n\nInstall command line developer tools:\n```\n$ xcode-select --install\n```\n\n>**NOTE:** It is possible that installing or updating to the the latest version of [Xcode](https://developer.apple.com/download) is needed.\n\nIf setuptools is not installed:\n```console\n$ python -m pip install setuptools\n```\n\n### Windows<a id=\"building-windows\"></a>\n#### Requirements\n- Download and install [Git](https://git-scm.com/downloads)\n- Download and install [Visual Studio 2019](https://visualstudio.microsoft.com/downloads/)\n    + Check *Desktop development with C++* prior to installing\n- Download and install [CMake](https://cmake.org/download/) >= v 3.5.1\n- Download and install [Python](https://www.python.org/downloads/)\n\n#### VS2019 Notes\n\nIf seeing issues when trying to build (steps in [](#)), some things to check/try:\n- Try running the build commands within the *Developer Command Prompt for VS2019*\n- Make sure *MSBuild* can find the correct *VCTargetsPath*\n    + It is possible the *VCTargetsPath* environment variable needs to be set.  The below example is based on a typical path, but the actual setting should match that of your current environment setup.\n        * ```set VCTargetsPath=C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\MSBuild\\Microsoft\\VC\\v160```\n- Make sure *CMake* is picking up the correct generator\n    + It is possible the *CMAKE_GENERATOR* environment variable needs to be set\n        * ```set CMAKE_GENERATOR=Visual Studio 16 2019```\n\n#### VS2015 & VS2017 Notes\n\nWhile it is possible to use VS2015 or VS2017 build tools, it is recommended to use the VS2019 path.  Some things to note if using the VS2015 or VS2017:\n- Make sure *CMake* is picking up the correct generator\n    + It is possible the *CMAKE_GENERATOR* environment variable needs to be set\n        * VS2015 example:  ```set CMAKE_GENERATOR=Visual Studio 14 2015```\n- Make sure *MSBuild* can be found\n    + It is possible an environment variable needs to be set\n- Make sure the correct [Windows SDK](https://developer.microsoft.com/en-us/windows/downloads/sdk-archive/) is installed\n- Make sure *MSBuild* can find the correct *VCTargetsPath*\n    + It is possible the *VCTargetsPath* environment variable needs to be set.  The below example is based on a typical path, but the actual setting should match that of your current environment setup.\n        * ```set VCTargetsPath=C:\\Program Files (x86)\\MSBuild\\Microsoft.Cpp\\v4.0\\v140```\n- MSBuild can run into [issues with MAX_PATH limits](https://github.com/dotnet/msbuild/issues/53#issuecomment-459062618) when using ```python -m pip install couchbase```.  This isn't fixed until MSBuild 16.0 so it is recommended to move to VS2019 (comes with MSBuild 16.0).\n\n## Build the Python SDK\nClone this Python SDK repository:\n```console\ngit clone https://github.com/couchbase/couchbase-python-client.git\n```\n\nMove into the directory created after cloning the Python SDK repository:\n```console\ncd couchbase-python-client\n```\n\nThe following will compile the module locally:\n```console\npython setup.py build_ext --inplace\n```\n\nIf you have a libcouchbase install already (in, for example, /opt/local/libcouchbase), you may build using it by setting PYCBC_BUILD=DISTUTILS and some add extra directives, like so:\n```console\n$ export PYCBC_BUILD=DISTUTILS\n$ python setup.py build_ext --inplace \\\n    --library-dir /opt/local/libcouchbase/lib \\\n    --include-dir /opt/local/libcouchbase/include\n```\n\nYou can also modify the environment ```CFLAGS``` and ```LDFLAGS``` variables.\n\n>:exclamation:**WARNING:** If you do not intend to install this module, ensure you set the ```PYTHONPATH``` environment variable to this directory before running any scripts depending on it. Failing to do so may result in your script running against an older version of this module (if installed), or throwing an exception stating that the ```couchbase``` module could not be found.\n\n## Install\n```console\npip install .\n```\n\n>:exclamation:**WARNING:** If you are on Linux/Mac OS you may need to remove the build directory: ```rm -rf ./build``` before installing with pip: ```pip3 install .```.\n\n# Using the SDK<a id=\"using-the-sdk\"></a>\n[Back to Contents](#contents)\n\n## Connecting<a id=\"sdk-connecting\"></a>\n\nSee [official documentation](https://docs.couchbase.com/python-sdk/current/howtos/managing-connections.html) for further details on connecting.\n\n```python\n# needed for any cluster connection\nfrom couchbase.cluster import Cluster, ClusterOptions\nfrom couchbase.auth import PasswordAuthenticator\n\n# needed to support SQL++ (N1QL) query\nfrom couchbase.cluster import QueryOptions\n\n# get a reference to our cluster\ncluster = Cluster('couchbase://localhost', ClusterOptions(\n  PasswordAuthenticator('Administrator', 'password')))\n```\n\n>**NOTE:** Authentication is handled differently depending on what version of Couchbase Server you are using.  In Couchbase Server >= 5.0, Role-Based Access Control (RBAC) provides discrete username and passwords for an application that allow fine-grained control. The authenticator is always required.\n\n## Basic Operations<a id=\"sdk-basic-ops\"></a>\n\nSee official documentation for further details on [Working with Data](https://docs.couchbase.com/python-sdk/current/howtos/kv-operations.html).\n\nBuilding upon the example code in the [Connecting](#sdk-connecting) section:\n\n```python\n# get a reference to our bucket\ncb = cluster.bucket('travel-sample')\n\n# get a reference to the default collection\ncb_coll = cb.default_collection()\n\n# get a document\nresult = cb_coll.get('airline_10')\nprint(result.content_as[dict])\n\n# using SQL++ (a.k.a N1QL)\ncall_sign = 'CBS'\nsql_query = 'SELECT VALUE name FROM `travel-sample` WHERE type = \"airline\" AND callsign = $1'\nrow_iter = cluster.query(sql_query, QueryOptions(positional_parameters=[call_sign]))\nfor row in row_iter: \n    print(row)\n```\n\n## Async Operations<a id=\"sdk-async-ops\"></a>\nThe Python Couchbase SDK supports asynchronous I/O through the use of the asyncio (Python standard library) or the Twisted async framework.\n\n>**NOTE:** Currently, the gcouchbase API is not available in the 3.x version of the Python SDK.\n\n### Asyncio\n\nTo use asyncio, import ```acouchbase.cluster``` instead of ```couchbase.cluster```.  The ```acouchbase``` API offers an API similar to the ```couchbase``` API.\n\n```python\nfrom acouchbase.cluster import Cluster, get_event_loop\nfrom couchbase.cluster import ClusterOptions\nfrom couchbase.auth import PasswordAuthenticator\n\n\nasync def write_and_read(key, value):\n    cluster = Cluster('couchbase://localhost',\n                      ClusterOptions(PasswordAuthenticator('Administrator', 'password')))\n    cb = cluster.bucket('default')\n    await cb.on_connect()\n    cb_coll = cb.default_collection()\n    await cb_coll.upsert(key, value)\n    result = await cb_coll.get(key)\n    cluster.disconnect()\n    return result\n\nloop = get_event_loop()\nrv = loop.run_until_complete(write_and_read('foo', 'bar'))\nprint(rv.content_as[str])\n```\n### Twisted\n\nTo use with Twisted, import ```txcouchbase.cluster``` instead of ```couchbase.cluster```.  The ```txcouchbase``` API offers an API similar to the ```couchbase``` API.\n\n```python\nfrom twisted.internet import reactor, defer\n\nfrom txcouchbase.cluster import TxCluster\nfrom couchbase.cluster import ClusterOptions\nfrom couchbase.auth import PasswordAuthenticator\n\n\ndef after_upsert(res, key, d):\n    print('Set key.  Result CAS: ', res.cas)\n    # trigger get_document callback\n    d.callback(key)\n\ndef upsert_document(key, doc):\n    d = defer.Deferred()\n    res = cb.upsert(key, doc)\n    res.addCallback(after_upsert, key, d)\n    return d\n\ndef on_get(res, _type=str):\n    print('Got res: \\n', res.content_as[_type])\n    reactor.stop()\n\ndef get_document(key):\n    res = cb.get(key)\n    res.addCallback(on_get)\n\n\n# create a cluster object\ncluster = TxCluster('couchbase://localhost',\n                    ClusterOptions(PasswordAuthenticator('Administrator', 'password')))\n\n# create a bucket object\nbucket = cluster.bucket('default')\n# create a collection object\ncb = bucket.default_collection()\n\nd = upsert_document('testDoc_1', {'id': 1, 'type': 'testDoc', 'info': 'fake document'})\nd.addCallback(get_document)\n\nreactor.run()\n```\n# Building Documentation<a id=\"building-documentation\"></a>\n[Back to Contents](#contents)\n\nThe documentation is using Sphinx and also needs the numpydoc Sphinx extension. In order for the documentation to build properly, the C extension must have been built, since there are embedded docstrings in there as well.\n\nTo build the documentation, go into the docs directory and run:\n```console\nmake html\n```\nThe HTML output can be found in docs/build/html/.\n\nAlternatively, you can also build the documentation (after building the module itself) from the top-level directory:\n```console\npython setup.py build_sphinx\n```\n\nOnce built, the docs will be in in build/sphinx/html.\n\n# Testing<a id=\"testing\"></a>\n[Back to Contents](#contents)\n\nFor running the tests, you need the standard unittest module, shipped with Python. Additionally, the testresources package is required.\n\nTo run them, use either py.test, unittest or trial.\n\nThe tests need a running Couchbase instance. For this, a tests.ini file must be present, containing various connection parameters. An example of this file may be found in tests.ini.sample. You may copy this file to tests.ini and modify the values as needed.\n\nTo run the tests:\n```console\nnosetests\n```\n\n# Contributing<a id=\"contributing\"></a>\n[Back to Contents](#contents)\n\nWe welcome contributions from the community!  Please see follow the steps outlined [here](https://github.com/couchbase/couchbase-python-client/blob/master/CONTRIBUTING.md) to get started.\n\n# License\n[Back to Contents](#contents)\n\nThe Couchbase Python SDK is licensed under the Apache License 2.0.\n\n# Support & Additional Resources<a id=\"support-additional-resources\"></a>\n[Back to Contents](#contents)\n\nIf you found an issue, please file it in our [JIRA](http://couchbase.com/issues/browse/pycbc). You can ask questions in our [forums](https://forums.couchbase.com/).\n\nThe [official documentation](https://docs.couchbase.com/python-sdk/current/hello-world/start-using-sdk.html) can be consulted as well for general Couchbase concepts and offers a more didactic approach to using the SDK.\n\n# Appendix<a id=\"appendix\"></a>\n[Back to Contents](#contents)\n\n### Mac OS pyenv Install<a id=\"appendix-pyenv\"></a>\nSee pyenv install [docs](https://github.com/pyenv/pyenv#homebrew-on-macos) for further details.\n\nGet the latest packages:\n```console\n$ brew update\n```\n\nFor TLS/SSL support:\n```console\n$ brew install openssl\n```\n\nInstall pyenv:\n```console\n$ brew install pyenv\n```\n\n>**NOTE:** It is possible that Xcode might need to be reinstalled.  Try **one** of the following:<br>\n>- Use command ```xcode-select --install```\n>- Install the latest version of [Xcode](https://developer.apple.com/download)\n\nFor *Zsh*, run the following commands to update *.zprofile* and *.zshrc*.  See pyenv install [docs](https://github.com/pyenv/pyenv#homebrew-on-macos) for further details on other shells.\n\n```console\n$ echo 'eval \"$(pyenv init --path)\"' >> ~/.zprofile\n```\n\n```console\n$ echo 'eval \"$(pyenv init -)\"' >> ~/.zshrc\n```\n\n>**NOTE:** You need to restart your login session for changes to take affect.  On MacOS, restarting terminal windows should suffice.\n\nInstall Python version:\n```console\n$ pyenv install 3.9.4\n```\n\nSet local shell to installed Python version:\n```console\n$  pyenv local 3.9.4\n```\n\nTo use virtualenvwrapper with pyenv, install pyenv-virtualenvwrapper:\n```console\n$ brew install pyenv-virtualenvwrapper\n```\n\nTo setup a virtualenvwrapper in your pyenv shell, run either ```pyenv virtualenvwrapper``` or ```pyenv virtualenvwrapper_lazy```\n\n>**NOTE:** If issues with ```pyenv virtualenvwrapper```, using ```python -m pip install virtualenvwrapper``` should accomplish the same goal.\n\nMake a virtualenv:\n```console\n$ mkvirtualenv python-3.9.4-test\n```\n\nInstall the SDK:\n```console\n$ python -m pip install couchbase\n```\n\n",
    "bugtrack_url": null,
    "license": "Apache License 2.0",
    "summary": "Python Client for Couchbase",
    "version": "3.2.0",
    "split_keywords": [
        "couchbase",
        "nosql",
        "pycouchbase",
        "libcouchbase"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "facb8d90e914941c3f90e1075845a3ce",
                "sha256": "b813d5f011d718ccfadaa09e67db5f4e0e3f4eaa5a8f849d0a5dde73aab5ede6"
            },
            "downloads": -1,
            "filename": "couchbase-3.2.0-cp37-cp37m-win_amd64.whl",
            "has_sig": false,
            "md5_digest": "facb8d90e914941c3f90e1075845a3ce",
            "packagetype": "bdist_wheel",
            "python_version": "cp37",
            "requires_python": ">=3.5",
            "size": 1948047,
            "upload_time": "2021-07-27T00:20:40",
            "upload_time_iso_8601": "2021-07-27T00:20:40.357743Z",
            "url": "https://files.pythonhosted.org/packages/cf/a1/ad7b8810d978b7a1af2f37deb30891a9046c8f63d1d11ef574daed271d4c/couchbase-3.2.0-cp37-cp37m-win_amd64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "cd483d2c71c780e7c3170f9deef80ab5",
                "sha256": "8a8e1a967eebd265bdb3a012973ae34d6cfdf42c2e9a72e78eb9b142a6cd5ebb"
            },
            "downloads": -1,
            "filename": "couchbase-3.2.0-cp38-cp38-win_amd64.whl",
            "has_sig": false,
            "md5_digest": "cd483d2c71c780e7c3170f9deef80ab5",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": ">=3.5",
            "size": 1969322,
            "upload_time": "2021-07-27T00:20:42",
            "upload_time_iso_8601": "2021-07-27T00:20:42.488307Z",
            "url": "https://files.pythonhosted.org/packages/6a/05/4dafe48444efa7f7b54cc35399212930dd6407ca3f44842736f7ff7c7c29/couchbase-3.2.0-cp38-cp38-win_amd64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "64b78eb44d8599e795036145867d8028",
                "sha256": "7acefeaeb9aff8b830dcdf892444b6a3b29013f63db42c0c36442c6e2db0d3d6"
            },
            "downloads": -1,
            "filename": "couchbase-3.2.0-cp39-cp39-win_amd64.whl",
            "has_sig": false,
            "md5_digest": "64b78eb44d8599e795036145867d8028",
            "packagetype": "bdist_wheel",
            "python_version": "cp39",
            "requires_python": ">=3.5",
            "size": 1970138,
            "upload_time": "2021-07-27T00:20:44",
            "upload_time_iso_8601": "2021-07-27T00:20:44.958051Z",
            "url": "https://files.pythonhosted.org/packages/cb/07/ec0977e45a2e4f50c276d4458a35f4ad2df1f4185f572f350f9b2843f611/couchbase-3.2.0-cp39-cp39-win_amd64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "9a41c486d720d99f873aacbaeebd554a",
                "sha256": "c90ced177430c60255a41a838c985b331aa22debdb48b8e77a3f6eb14d29c1b9"
            },
            "downloads": -1,
            "filename": "couchbase-3.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "9a41c486d720d99f873aacbaeebd554a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.5",
            "size": 1702425,
            "upload_time": "2021-07-27T00:20:47",
            "upload_time_iso_8601": "2021-07-27T00:20:47.227849Z",
            "url": "https://files.pythonhosted.org/packages/ea/6e/5bda2ba94e0173f69026631df9e73eed42885ba0c9e5e183bb6a8f1bc3f9/couchbase-3.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-07-27 00:20:47",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "couchbase",
    "github_project": "couchbase-python-client",
    "travis_ci": true,
    "coveralls": true,
    "github_actions": false,
    "requirements": [
        {
            "name": "typing-extensions",
            "specs": [
                [
                    "==",
                    "3.7.4.3"
                ]
            ]
        },
        {
            "name": "mypy_extensions",
            "specs": []
        },
        {
            "name": "pip",
            "specs": [
                [
                    ">=",
                    "20.0"
                ]
            ]
        },
        {
            "name": "pyrsistent",
            "specs": [
                [
                    ">=",
                    "0.15.2"
                ]
            ]
        },
        {
            "name": "six",
            "specs": [
                [
                    "==",
                    "1.15.0"
                ]
            ]
        },
        {
            "name": "attrs",
            "specs": [
                [
                    ">=",
                    "19.1.0"
                ]
            ]
        },
        {
            "name": "attrs",
            "specs": [
                [
                    "==",
                    "19.1.0"
                ]
            ]
        },
        {
            "name": "wrapt",
            "specs": [
                [
                    ">=",
                    "1.11.2"
                ]
            ]
        },
        {
            "name": "durationpy",
            "specs": [
                [
                    "==",
                    "0.5"
                ]
            ]
        }
    ],
    "lcname": "couchbase"
}
        
Elapsed time: 0.30974s