# Couchbase Python Analytics Client
Python client for [Couchbase](https://couchbase.com) Analytics.
Currently Python 3.9 - Python 3.13 is supported.
The Analytics SDK supports static typing. Currently only [mypy](https://github.com/python/mypy) is supported. You mileage may vary (YMMV) with the use of other static type checkers (e.g. [pyright](https://github.com/microsoft/pyright)).
# Installing the SDK<a id="installing-the-sdk"></a>
>Note: It is strongly recommended to update pip, setuptools and wheel prior to installing the SDK: `python3 -m pip install --upgrade pip setuptools wheel`
Install the SDK via `pip`:
```console
python3 -m pip install couchbase-analytics
```
# Installing the SDK from source
The SDK can be installed from source via pip with the following command.
Install the SDK via `pip`:
```console
python3 -m pip install git+https://github.com/couchbase/analytics-python-client.git
```
# Using the SDK<a id="using-the-sdk"></a>
Some more examples are provided in the [examples directory](https://github.com/couchbase/analytics-python-client/tree/main/examples).
**Connecting and executing a query**
```python
from couchbase_analytics.cluster import Cluster
from couchbase_analytics.credential import Credential
from couchbase_analytics.options import QueryOptions
def main() -> None:
# Update this to your cluster
# IMPORTANT: The appropriate port needs to be specified. The SDK's default ports are 80 (http) and 443 (https).
# If attempting to connect to Capella, the correct ports are most likely to be 8095 (http) and 18095 (https).
# Capella example: https://cb.2xg3vwszqgqcrsix.cloud.couchbase.com:18095
endpoint = 'https://--your-instance--'
username = 'username'
pw = 'password'
# User Input ends here.
cred = Credential.from_username_and_password(username, pw)
cluster = Cluster.create_instance(endpoint, cred)
# Execute a query and buffer all result rows in client memory.
statement = 'SELECT * FROM `travel-sample`.inventory.airline LIMIT 10;'
res = cluster.execute_query(statement)
all_rows = res.get_all_rows()
for row in all_rows:
print(f'Found row: {row}')
print(f'metadata={res.metadata()}')
# Execute a query and process rows as they arrive from server.
statement = 'SELECT * FROM `travel-sample`.inventory.airline WHERE country="United States" LIMIT 10;'
res = cluster.execute_query(statement)
for row in res.rows():
print(f'Found row: {row}')
print(f'metadata={res.metadata()}')
# Execute a streaming query with positional arguments.
statement = 'SELECT * FROM `travel-sample`.inventory.airline WHERE country=$1 LIMIT $2;'
res = cluster.execute_query(statement, QueryOptions(positional_parameters=['United States', 10]))
for row in res:
print(f'Found row: {row}')
print(f'metadata={res.metadata()}')
# Execute a streaming query with named arguments.
statement = 'SELECT * FROM `travel-sample`.inventory.airline WHERE country=$country LIMIT $limit;'
res = cluster.execute_query(statement, QueryOptions(named_parameters={'country': 'United States',
'limit': 10}))
for row in res.rows():
print(f'Found row: {row}')
print(f'metadata={res.metadata()}')
if __name__ == '__main__':
main()
```
## Using the async API
```python
import asyncio
from acouchbase_analytics.cluster import AsyncCluster
from acouchbase_analytics.credential import Credential
from acouchbase_analytics.options import QueryOptions
async def main() -> None:
# Update this to your cluster
# IMPORTANT: The appropriate port needs to be specified. The SDK's default ports are 80 (http) and 443 (https).
# If attempting to connect to Capella, the correct ports are most likely to be 8095 (http) and 18095 (https).
# Capella example: https://cb.2xg3vwszqgqcrsix.cloud.couchbase.com:18095
endpoint = 'https://--your-instance--'
username = 'username'
pw = 'password'
# User Input ends here.
cred = Credential.from_username_and_password(username, pw)
cluster = AsyncCluster.create_instance(endpoint, cred)
# Execute a query and buffer all result rows in client memory.
statement = 'SELECT * FROM `travel-sample`.inventory.airline LIMIT 10;'
res = await cluster.execute_query(statement)
all_rows = await res.get_all_rows()
# NOTE: all_rows is a list, _do not_ use `async for`
for row in all_rows:
print(f'Found row: {row}')
print(f'metadata={res.metadata()}')
# Execute a query and process rows as they arrive from server.
statement = 'SELECT * FROM `travel-sample`.inventory.airline WHERE country="United States" LIMIT 10;'
res = await cluster.execute_query(statement)
async for row in res.rows():
print(f'Found row: {row}')
print(f'metadata={res.metadata()}')
# Execute a streaming query with positional arguments.
statement = 'SELECT * FROM `travel-sample`.inventory.airline WHERE country=$1 LIMIT $2;'
res = await cluster.execute_query(statement, QueryOptions(positional_parameters=['United States', 10]))
async for row in res:
print(f'Found row: {row}')
print(f'metadata={res.metadata()}')
# Execute a streaming query with named arguments.
statement = 'SELECT * FROM `travel-sample`.inventory.airline WHERE country=$country LIMIT $limit;'
res = await cluster.execute_query(statement, QueryOptions(named_parameters={'country': 'United States',
'limit': 10}))
async for row in res.rows():
print(f'Found row: {row}')
print(f'metadata={res.metadata()}')
if __name__ == '__main__':
asyncio.run(main())
```
Raw data
{
"_id": null,
"home_page": null,
"name": "couchbase-analytics",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": "\"Couchbase, Inc.\" <PythonPackage@couchbase.com>",
"keywords": "couchbase, nosql, pycouchbase, couchbase++, analytics",
"author": null,
"author_email": "\"Couchbase, Inc.\" <PythonPackage@couchbase.com>",
"download_url": "https://files.pythonhosted.org/packages/e0/18/f1fb70fbc3fc4ac3200aa6336485312ef8e61e02ec9c618cd80ce7fa0302/couchbase_analytics-1.0.0.tar.gz",
"platform": null,
"description": "# Couchbase Python Analytics Client\nPython client for [Couchbase](https://couchbase.com) Analytics.\n\nCurrently Python 3.9 - Python 3.13 is supported.\n\nThe Analytics SDK supports static typing. Currently only [mypy](https://github.com/python/mypy) is supported. You mileage may vary (YMMV) with the use of other static type checkers (e.g. [pyright](https://github.com/microsoft/pyright)).\n\n# Installing the SDK<a id=\"installing-the-sdk\"></a>\n\n>Note: It is strongly recommended to update pip, setuptools and wheel prior to installing the SDK: `python3 -m pip install --upgrade pip setuptools wheel`\n\nInstall the SDK via `pip`:\n```console\npython3 -m pip install couchbase-analytics\n```\n\n# Installing the SDK from source\n\nThe SDK can be installed from source via pip with the following command.\n\nInstall the SDK via `pip`:\n```console\npython3 -m pip install git+https://github.com/couchbase/analytics-python-client.git\n```\n\n# Using the SDK<a id=\"using-the-sdk\"></a>\n\nSome more examples are provided in the [examples directory](https://github.com/couchbase/analytics-python-client/tree/main/examples).\n\n**Connecting and executing a query**\n```python\nfrom couchbase_analytics.cluster import Cluster\nfrom couchbase_analytics.credential import Credential\nfrom couchbase_analytics.options import QueryOptions\n\n\ndef main() -> None:\n # Update this to your cluster\n # IMPORTANT: The appropriate port needs to be specified. The SDK's default ports are 80 (http) and 443 (https).\n # If attempting to connect to Capella, the correct ports are most likely to be 8095 (http) and 18095 (https).\n # Capella example: https://cb.2xg3vwszqgqcrsix.cloud.couchbase.com:18095\n endpoint = 'https://--your-instance--'\n username = 'username'\n pw = 'password'\n # User Input ends here.\n\n cred = Credential.from_username_and_password(username, pw)\n cluster = Cluster.create_instance(endpoint, cred)\n\n # Execute a query and buffer all result rows in client memory.\n statement = 'SELECT * FROM `travel-sample`.inventory.airline LIMIT 10;'\n res = cluster.execute_query(statement)\n all_rows = res.get_all_rows()\n for row in all_rows:\n print(f'Found row: {row}')\n print(f'metadata={res.metadata()}')\n\n # Execute a query and process rows as they arrive from server.\n statement = 'SELECT * FROM `travel-sample`.inventory.airline WHERE country=\"United States\" LIMIT 10;'\n res = cluster.execute_query(statement)\n for row in res.rows():\n print(f'Found row: {row}')\n print(f'metadata={res.metadata()}')\n\n # Execute a streaming query with positional arguments.\n statement = 'SELECT * FROM `travel-sample`.inventory.airline WHERE country=$1 LIMIT $2;'\n res = cluster.execute_query(statement, QueryOptions(positional_parameters=['United States', 10]))\n for row in res:\n print(f'Found row: {row}')\n print(f'metadata={res.metadata()}')\n\n # Execute a streaming query with named arguments.\n statement = 'SELECT * FROM `travel-sample`.inventory.airline WHERE country=$country LIMIT $limit;'\n res = cluster.execute_query(statement, QueryOptions(named_parameters={'country': 'United States',\n 'limit': 10}))\n for row in res.rows():\n print(f'Found row: {row}')\n print(f'metadata={res.metadata()}')\n\n\nif __name__ == '__main__':\n main()\n\n```\n\n## Using the async API\n```python\nimport asyncio\n\nfrom acouchbase_analytics.cluster import AsyncCluster\nfrom acouchbase_analytics.credential import Credential\nfrom acouchbase_analytics.options import QueryOptions\n\n\nasync def main() -> None:\n # Update this to your cluster\n # IMPORTANT: The appropriate port needs to be specified. The SDK's default ports are 80 (http) and 443 (https).\n # If attempting to connect to Capella, the correct ports are most likely to be 8095 (http) and 18095 (https).\n # Capella example: https://cb.2xg3vwszqgqcrsix.cloud.couchbase.com:18095\n endpoint = 'https://--your-instance--'\n username = 'username'\n pw = 'password'\n # User Input ends here.\n\n cred = Credential.from_username_and_password(username, pw)\n cluster = AsyncCluster.create_instance(endpoint, cred)\n\n # Execute a query and buffer all result rows in client memory.\n statement = 'SELECT * FROM `travel-sample`.inventory.airline LIMIT 10;'\n res = await cluster.execute_query(statement)\n all_rows = await res.get_all_rows()\n # NOTE: all_rows is a list, _do not_ use `async for`\n for row in all_rows:\n print(f'Found row: {row}')\n print(f'metadata={res.metadata()}')\n\n # Execute a query and process rows as they arrive from server.\n statement = 'SELECT * FROM `travel-sample`.inventory.airline WHERE country=\"United States\" LIMIT 10;'\n res = await cluster.execute_query(statement)\n async for row in res.rows():\n print(f'Found row: {row}')\n print(f'metadata={res.metadata()}')\n\n # Execute a streaming query with positional arguments.\n statement = 'SELECT * FROM `travel-sample`.inventory.airline WHERE country=$1 LIMIT $2;'\n res = await cluster.execute_query(statement, QueryOptions(positional_parameters=['United States', 10]))\n async for row in res:\n print(f'Found row: {row}')\n print(f'metadata={res.metadata()}')\n\n # Execute a streaming query with named arguments.\n statement = 'SELECT * FROM `travel-sample`.inventory.airline WHERE country=$country LIMIT $limit;'\n res = await cluster.execute_query(statement, QueryOptions(named_parameters={'country': 'United States',\n 'limit': 10}))\n async for row in res.rows():\n print(f'Found row: {row}')\n print(f'metadata={res.metadata()}')\n\nif __name__ == '__main__':\n asyncio.run(main())\n\n```\n",
"bugtrack_url": null,
"license": null,
"summary": "Python Client for Couchbase Analytics",
"version": "1.0.0",
"project_urls": {
"API Reference": "https://docs.couchbase.com/sdk-api/analytics-python-client/",
"Bug Tracker": "https://issues.couchbase.com/projects/PYCO/issues/",
"Documentation": "https://docs.couchbase.com/python-analytics-sdk/current/hello-world/overview.html",
"Homepage": "https://couchbase.com",
"Release Notes": "https://docs.couchbase.com/python-analytics-sdk/current/project-docs/analytics-sdk-release-notes.html",
"Repository": "https://github.com/couchbase/analytics-python-client"
},
"split_keywords": [
"couchbase",
" nosql",
" pycouchbase",
" couchbase++",
" analytics"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "51ec22aadf226de1b007dfbe72d6f531cf07070c7dd1d6dbb854b91d0b0c1aef",
"md5": "470599e325272cd31a48bee22cb660e8",
"sha256": "8e57f63fe95d7ccba0caba07957d12c799d05e08fb62dbb5850b72dd2b519c51"
},
"downloads": -1,
"filename": "couchbase_analytics-1.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "470599e325272cd31a48bee22cb660e8",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 126288,
"upload_time": "2025-08-08T15:25:14",
"upload_time_iso_8601": "2025-08-08T15:25:14.931241Z",
"url": "https://files.pythonhosted.org/packages/51/ec/22aadf226de1b007dfbe72d6f531cf07070c7dd1d6dbb854b91d0b0c1aef/couchbase_analytics-1.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "e018f1fb70fbc3fc4ac3200aa6336485312ef8e61e02ec9c618cd80ce7fa0302",
"md5": "a23519a1f9b7fea0ce7a5525eba66087",
"sha256": "31dafbf761371f82da9d1ad52fe3e33bcd85c6592513defc01fc0b55d4877723"
},
"downloads": -1,
"filename": "couchbase_analytics-1.0.0.tar.gz",
"has_sig": false,
"md5_digest": "a23519a1f9b7fea0ce7a5525eba66087",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 69094,
"upload_time": "2025-08-08T15:25:17",
"upload_time_iso_8601": "2025-08-08T15:25:17.203844Z",
"url": "https://files.pythonhosted.org/packages/e0/18/f1fb70fbc3fc4ac3200aa6336485312ef8e61e02ec9c618cd80ce7fa0302/couchbase_analytics-1.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-08 15:25:17",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "couchbase",
"github_project": "analytics-python-client",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "anyio",
"specs": [
[
"==",
"4.9.0"
]
]
},
{
"name": "certifi",
"specs": [
[
"==",
"2025.6.15"
]
]
},
{
"name": "exceptiongroup",
"specs": [
[
"==",
"1.3.0"
]
]
},
{
"name": "h11",
"specs": [
[
"==",
"0.16.0"
]
]
},
{
"name": "httpcore",
"specs": [
[
"==",
"1.0.9"
]
]
},
{
"name": "httpx",
"specs": [
[
"==",
"0.28.1"
]
]
},
{
"name": "idna",
"specs": [
[
"==",
"3.10"
]
]
},
{
"name": "ijson",
"specs": [
[
"==",
"3.4.0"
]
]
},
{
"name": "sniffio",
"specs": [
[
"==",
"1.3.1"
]
]
},
{
"name": "typing-extensions",
"specs": [
[
"==",
"4.14.0"
]
]
}
],
"lcname": "couchbase-analytics"
}