# cb-util 2.2.40
## Couchbase Utilities
Couchbase connection manager. Simplifies connecting to a Couchbase cluster and performing data and management operations.
## Installing
```
$ pip install cbcmgr
```
## API Usage
Original syntax (package is backwards compatible):
```
>>> from cbcmgr.cb_connect import CBConnect
>>> from cbcmgr.cb_management import CBManager
>>> bucket = scope = collection = "test"
>>> dbm = CBManager("127.0.0.1", "Administrator", "password", ssl=False).connect()
>>> dbm.create_bucket(bucket)
>>> dbm.create_scope(scope)
>>> dbm.create_collection(collection)
>>> dbc = CBConnect("127.0.0.1", "Administrator", "password", ssl=False).connect(bucket, scope, collection)
>>> result = dbc.cb_upsert("test::1", {"data": 1})
>>> result = dbc.cb_get("test::1")
>>> print(result)
{'data': 1}
```
New Operator syntax:
```
keyspace = "test.test.test"
db = CBOperation(hostname, "Administrator", "password", ssl=False, quota=128, create=True).connect(keyspace)
db.put_doc(col_a.collection, "test::1", document)
d = db.get_doc(col_a.collection, "test::1")
assert d == document
db.index_by_query("select data from test.test.test")
r = db.run_query(col_a.cluster, "select data from test.test.test")
assert r[0]['data'] == 'data'
```
Thread Pool Syntax:
```
pool = CBPool(hostname, "Administrator", "password", ssl=False, quota=128, create=True)
pool.connect(keyspace)
pool.dispatch(keyspace, Operation.WRITE, f"test::1", document)
pool.join()
```
Async Pool Syntax
```
pool = CBPoolAsync(hostname, "Administrator", "password", ssl=False, quota=128, create=True)
await pool.connect(keyspace)
await pool.join()
```
## CLI Utilities
## cbcutil
Load 1,000 records of data using the default schema:
````
$ cbcutil load --host couchbase.example.com --count 1000 --schema default
````
Load data from a test file:
````
$ cat data/data_file.txt | cbcutil load --host couchbase.example.com -b bucket
````
Export data from a bucket to CSV (default output file location is $HOME)
````
$ cbcutil export csv --host couchbase.example.com -i -b sample_app
````
Export data as JSON and load that data into another cluster
````
$ cbcutil export json --host source -i -O -q -b bucket | cbcutil load --host destination -b bucket
````
Get a document from a bucket using the key:
````
$ cbcutil get --host couchbase.example.com -b employees -k employees:1
````
List information about a Couchbase cluster:
````
$ cbcutil list --host couchbase.example.com -u developer -p password
````
List detailed information about a Couchbase cluster including health information:
````
$ cbcutil list --host couchbase.example.com --ping -u developer -p password
````
Replicate buckets, indexes and users from self-managed cluster to Capella (and filter buckets beginning with "test" and users with usernames beginning with "dev"):
```
cbcutil replicate source --host 1.2.3.4 --filter 'bucket:test.*' --filter 'user:dev.*' | cbcutil replicate target --host cb.abcdefg.cloud.couchbase.com -p "Password123#" --project dev-project --db testdb
```
List available schemas:
````
$ cbcutil schema
````
# Randomizer tokens
Note: Except for the US States the random data generated may not be valid. For example the first four digits of the random credit card may not represent a valid financial institution. The intent is to simulate real data. Any similarities to real data is purely coincidental.
| Token | Description |
|------------------|---------------------------------------------------------------|
| date_time | Data/time string in form %Y-%m-%d %H:%M:%S |
| rand_credit_card | Random credit card format number |
| rand_ssn | Random US Social Security format number |
| rand_four | Random four digits |
| rand_account | Random 10 digit number |
| rand_id | Random 16 digit number |
| rand_zip_code | Random US Zip Code format number |
| rand_dollar | Random dollar amount |
| rand_hash | Random 16 character alphanumeric string |
| rand_address | Random street address |
| rand_city | Random city name |
| rand_state | Random US State name |
| rand_first | Random first name |
| rand_last | Random last name |
| rand_nickname | Random string with a concatenated first initial and last name |
| rand_email | Random email address |
| rand_username | Random username created from a name and numbers |
| rand_phone | Random US style phone number |
| rand_bool | Random boolean value |
| rand_year | Random year from 1920 to present |
| rand_month | Random month number |
| rand_day | Random day number |
| rand_date_1 | Near term random date with slash notation |
| rand_date_2 | Near term random date with dash notation |
| rand_date_3 | Near term random date with spaces |
| rand_dob_1 | Date of Birth with slash notation |
| rand_dob_2 | Date of Birth with dash notation |
| rand_dob_3 | Date of Birth with spaces |
| rand_image | Random 128x128 pixel JPEG image |
# Options
Usage: cbcutil command options
| Command | Description |
|----------|---------------------------|
| load | Load data |
| get | Get data |
| list | List cluster information |
| export | Export data |
| import | Import via plugin |
| clean | Remove buckets |
| schema | Schema management options |
| replicate| Replicate configuration |
| Option | Description |
|----------------------------------------|----------------------------------------------------------------|
| -u USER, --user USER | User Name |
| -p PASSWORD, --password PASSWORD | User Password |
| -h HOST, --host HOST | Cluster Node or Domain Name |
| -b BUCKET, --bucket BUCKET | Bucket name |
| -s SCOPE, --scope SCOPE | Scope name |
| -c COLLECTION, --collection COLLECTION | Collection name |
| -k KEY, --key KEY | Key name or pattern |
| -d DATA, --data DATA | Data to import |
| -F FILTER, --filter FILTER | Filter expression (i.e. bucket:regex, user:regex, etc.) |
| --project PROJECT | Capella project name |
| --db DATABASE | Capella database name |
| -q, --quiet | Quiet mode (only necessary output) |
| -O, --stdout | Output exported data to the terminal |
| -i, --index | Create a primary index for export operations (if not present) |
| --tls | Enable SSL (default) |
| -e, --external | Use external network for clusters with an external network |
| --schema SCHEMA | Schema name |
| --count COUNT | Record Count |
| --file FILE | File mode schema JSON file |
| --id ID | ID field (for file mode) |
| --directory DIRECTORY | Directory for export operations |
| --defer | Creates an index as deferred |
| -P PLUGIN | Import plugin |
| -V PLUGIN_VARIABLE | Pass variable in form key=value to plugin |
## sgwutil
Database Commands:
| Command | Description |
|---------|---------------------------------------------|
| create | Create SGW database (connect to CBS Bucket) |
| delete | Delete a database |
| sync | Manage Sync Function for database |
| resync | Reprocess documents with sync function |
| list | List database |
| dump | Dump synced document details |
User Commands:
| Command | Description |
|---------|--------------------------------------|
| create | Create users |
| delete | Delete user |
| list | List users |
| map | Create users based on document field |
Database parameters:
| Parameter | Description |
|----------------|-------------------------------|
| -b, --bucket | Bucket |
| -n, --name | Database name |
| -f, --function | Sync Function file |
| -r, --replicas | Number of replicas |
| -g, --get | Display current Sync Function |
User parameters:
| Parameter | Description |
|----------------|-------------------------------------------------------|
| -n, --name | Database name |
| -U, --sguser | Sync Gateway user name |
| -P, --sgpass | Sync Gateway user password |
| -d, --dbhost | Couchbase server connect name or IP (for map command) |
| -l, --dblogin | Couchbase server credentials in form user:password |
| -f, --field | Document field to map |
| -k, --keyspace | Keyspace with documents for map |
| -a, --all | List all users |
Examples:
Create Sync Gateway database "sgwdb" that is connected to bucket "demo":
```
sgwutil database create -h hostname -n sgwdb -b demo
```
Get information about database "sgwdb":
```
sgwutil database list -h hostname -n sgwdb
```
Display information about documents in the database including the latest channel assignment:
```
sgwutil database dump -h hostname -n sgwdb
```
Create a Sync Gateway database user:
```
sgwutil user create -h hostname -n sgwdb --sguser sgwuser --sgpass "password"
```
Display user details:
```
sgwutil user list -h hostname -n sgwdb --sguser sgwuser
```
List all database users:
```
sgwutil user list -h hostname -n sgwdb -a
```
Create users in database "sgwdb" based on the unique values for document value "field_name" in keyspace "demo":
```
sgwutil user map -h sgwhost -d cbshost -f field_name -k demo -n sgwdb
```
Add Sync Function:
```
sgwutil database sync -h hostname -n sgwdb -f /home/user/demo.js
```
Display Sync Function:
```
sgwutil database sync -h hostname -n sgwdb -g
```
Delete user:
```
sgwutil user delete -h hostname -n sgwdb --sguser sgwuser
```
Delete database "sgwdb":
```
sgwutil database delete -h hostname -n sgwdb
```
## caputil
Note: Save Capella v4 token file as $HOME/.capella/default-api-key-token.txt\
Create Capella cluster:
```
caputil cluster create --project project-name --name testdb --region us-east-1
```
Update Capella cluster (to add services):
```
caputil cluster update --project pytest-name --name testdb --services search,analytics,eventing
```
Delete Capella cluster:
```
caputil cluster delete --project project-name --name testdb --region us-east-1
```
Create bucket:
````
caputil bucket create --project project-name --db testdb --name test-bucket
````
Change database user password:
```
caputil user password --project pytest-name --db testdb --name Administrator
```
Raw data
{
"_id": null,
"home_page": "https://github.com/mminichino/cb-util",
"name": "cbcmgr",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "couchbase, nosql, pycouchbase, database",
"author": "Michael Minichino",
"author_email": "info@unix.us.com",
"download_url": "https://files.pythonhosted.org/packages/c2/b2/5abd2e6acd34a6ce95f33c7bf55c4b3e1ca03dbbaca141af6fd2d7e78fee/cbcmgr-2.2.40.tar.gz",
"platform": null,
"description": "# cb-util 2.2.40\n\n## Couchbase Utilities\nCouchbase connection manager. Simplifies connecting to a Couchbase cluster and performing data and management operations.\n\n## Installing\n```\n$ pip install cbcmgr\n```\n\n## API Usage\nOriginal syntax (package is backwards compatible):\n```\n>>> from cbcmgr.cb_connect import CBConnect\n>>> from cbcmgr.cb_management import CBManager\n>>> bucket = scope = collection = \"test\"\n>>> dbm = CBManager(\"127.0.0.1\", \"Administrator\", \"password\", ssl=False).connect()\n>>> dbm.create_bucket(bucket)\n>>> dbm.create_scope(scope)\n>>> dbm.create_collection(collection)\n>>> dbc = CBConnect(\"127.0.0.1\", \"Administrator\", \"password\", ssl=False).connect(bucket, scope, collection)\n>>> result = dbc.cb_upsert(\"test::1\", {\"data\": 1})\n>>> result = dbc.cb_get(\"test::1\")\n>>> print(result)\n{'data': 1}\n```\nNew Operator syntax:\n```\nkeyspace = \"test.test.test\"\ndb = CBOperation(hostname, \"Administrator\", \"password\", ssl=False, quota=128, create=True).connect(keyspace)\ndb.put_doc(col_a.collection, \"test::1\", document)\nd = db.get_doc(col_a.collection, \"test::1\")\nassert d == document\ndb.index_by_query(\"select data from test.test.test\")\nr = db.run_query(col_a.cluster, \"select data from test.test.test\")\nassert r[0]['data'] == 'data'\n```\nThread Pool Syntax:\n```\npool = CBPool(hostname, \"Administrator\", \"password\", ssl=False, quota=128, create=True)\npool.connect(keyspace)\npool.dispatch(keyspace, Operation.WRITE, f\"test::1\", document)\npool.join()\n```\nAsync Pool Syntax\n```\npool = CBPoolAsync(hostname, \"Administrator\", \"password\", ssl=False, quota=128, create=True)\nawait pool.connect(keyspace)\nawait pool.join()\n```\n## CLI Utilities\n## cbcutil\nLoad 1,000 records of data using the default schema:\n````\n$ cbcutil load --host couchbase.example.com --count 1000 --schema default\n````\nLoad data from a test file:\n````\n$ cat data/data_file.txt | cbcutil load --host couchbase.example.com -b bucket\n````\nExport data from a bucket to CSV (default output file location is $HOME)\n````\n$ cbcutil export csv --host couchbase.example.com -i -b sample_app\n````\nExport data as JSON and load that data into another cluster\n````\n$ cbcutil export json --host source -i -O -q -b bucket | cbcutil load --host destination -b bucket\n````\nGet a document from a bucket using the key:\n````\n$ cbcutil get --host couchbase.example.com -b employees -k employees:1\n````\nList information about a Couchbase cluster:\n````\n$ cbcutil list --host couchbase.example.com -u developer -p password\n````\nList detailed information about a Couchbase cluster including health information:\n````\n$ cbcutil list --host couchbase.example.com --ping -u developer -p password\n````\nReplicate buckets, indexes and users from self-managed cluster to Capella (and filter buckets beginning with \"test\" and users with usernames beginning with \"dev\"):\n```\ncbcutil replicate source --host 1.2.3.4 --filter 'bucket:test.*' --filter 'user:dev.*' | cbcutil replicate target --host cb.abcdefg.cloud.couchbase.com -p \"Password123#\" --project dev-project --db testdb\n```\nList available schemas:\n````\n$ cbcutil schema\n````\n# Randomizer tokens\nNote: Except for the US States the random data generated may not be valid. For example the first four digits of the random credit card may not represent a valid financial institution. The intent is to simulate real data. Any similarities to real data is purely coincidental. \n\n| Token | Description |\n|------------------|---------------------------------------------------------------|\n| date_time | Data/time string in form %Y-%m-%d %H:%M:%S |\n| rand_credit_card | Random credit card format number |\n| rand_ssn | Random US Social Security format number |\n| rand_four | Random four digits |\n| rand_account | Random 10 digit number |\n| rand_id | Random 16 digit number |\n| rand_zip_code | Random US Zip Code format number |\n| rand_dollar | Random dollar amount |\n| rand_hash | Random 16 character alphanumeric string |\n| rand_address | Random street address |\n| rand_city | Random city name |\n| rand_state | Random US State name |\n| rand_first | Random first name |\n| rand_last | Random last name |\n| rand_nickname | Random string with a concatenated first initial and last name |\n| rand_email | Random email address |\n| rand_username | Random username created from a name and numbers |\n| rand_phone | Random US style phone number |\n| rand_bool | Random boolean value |\n| rand_year | Random year from 1920 to present |\n| rand_month | Random month number |\n| rand_day | Random day number |\n| rand_date_1 | Near term random date with slash notation |\n| rand_date_2 | Near term random date with dash notation |\n| rand_date_3 | Near term random date with spaces |\n| rand_dob_1 | Date of Birth with slash notation |\n| rand_dob_2 | Date of Birth with dash notation |\n| rand_dob_3 | Date of Birth with spaces |\n| rand_image | Random 128x128 pixel JPEG image |\n# Options\nUsage: cbcutil command options\n\n| Command | Description |\n|----------|---------------------------|\n| load | Load data |\n| get | Get data |\n| list | List cluster information |\n| export | Export data |\n| import | Import via plugin |\n| clean | Remove buckets |\n| schema | Schema management options |\n| replicate| Replicate configuration |\n\n| Option | Description |\n|----------------------------------------|----------------------------------------------------------------|\n| -u USER, --user USER | User Name |\n| -p PASSWORD, --password PASSWORD | User Password |\n| -h HOST, --host HOST | Cluster Node or Domain Name |\n| -b BUCKET, --bucket BUCKET | Bucket name |\n| -s SCOPE, --scope SCOPE | Scope name |\n| -c COLLECTION, --collection COLLECTION | Collection name |\n| -k KEY, --key KEY | Key name or pattern |\n| -d DATA, --data DATA | Data to import |\n| -F FILTER, --filter FILTER | Filter expression (i.e. bucket:regex, user:regex, etc.) |\n| --project PROJECT | Capella project name |\n| --db DATABASE | Capella database name |\n| -q, --quiet | Quiet mode (only necessary output) |\n| -O, --stdout | Output exported data to the terminal |\n| -i, --index | Create a primary index for export operations (if not present) |\n| --tls | Enable SSL (default) |\n| -e, --external | Use external network for clusters with an external network |\n| --schema SCHEMA | Schema name |\n| --count COUNT | Record Count |\n| --file FILE | File mode schema JSON file |\n| --id ID | ID field (for file mode) |\n| --directory DIRECTORY | Directory for export operations |\n| --defer | Creates an index as deferred |\n| -P PLUGIN | Import plugin |\n| -V PLUGIN_VARIABLE | Pass variable in form key=value to plugin |\n\n## sgwutil\nDatabase Commands:\n\n| Command | Description |\n|---------|---------------------------------------------|\n| create | Create SGW database (connect to CBS Bucket) |\n| delete | Delete a database |\n| sync | Manage Sync Function for database |\n| resync | Reprocess documents with sync function |\n| list | List database |\n| dump | Dump synced document details |\n\nUser Commands:\n\n| Command | Description |\n|---------|--------------------------------------|\n| create | Create users |\n| delete | Delete user |\n| list | List users |\n| map | Create users based on document field |\n\nDatabase parameters:\n\n| Parameter | Description |\n|----------------|-------------------------------|\n| -b, --bucket | Bucket |\n| -n, --name | Database name |\n| -f, --function | Sync Function file |\n| -r, --replicas | Number of replicas |\n| -g, --get | Display current Sync Function |\n\nUser parameters:\n\n| Parameter | Description |\n|----------------|-------------------------------------------------------|\n| -n, --name | Database name |\n| -U, --sguser | Sync Gateway user name |\n| -P, --sgpass | Sync Gateway user password |\n| -d, --dbhost | Couchbase server connect name or IP (for map command) |\n| -l, --dblogin | Couchbase server credentials in form user:password |\n| -f, --field | Document field to map |\n| -k, --keyspace | Keyspace with documents for map |\n| -a, --all | List all users |\n\nExamples:\n\nCreate Sync Gateway database \"sgwdb\" that is connected to bucket \"demo\":\n```\nsgwutil database create -h hostname -n sgwdb -b demo\n```\n\nGet information about database \"sgwdb\":\n```\nsgwutil database list -h hostname -n sgwdb\n```\n\nDisplay information about documents in the database including the latest channel assignment:\n```\nsgwutil database dump -h hostname -n sgwdb\n```\n\nCreate a Sync Gateway database user:\n```\nsgwutil user create -h hostname -n sgwdb --sguser sgwuser --sgpass \"password\"\n```\n\nDisplay user details:\n```\nsgwutil user list -h hostname -n sgwdb --sguser sgwuser\n```\n\nList all database users:\n```\nsgwutil user list -h hostname -n sgwdb -a\n```\n\nCreate users in database \"sgwdb\" based on the unique values for document value \"field_name\" in keyspace \"demo\":\n```\nsgwutil user map -h sgwhost -d cbshost -f field_name -k demo -n sgwdb\n```\n\nAdd Sync Function:\n```\nsgwutil database sync -h hostname -n sgwdb -f /home/user/demo.js\n```\n\nDisplay Sync Function:\n```\nsgwutil database sync -h hostname -n sgwdb -g\n```\n\nDelete user:\n```\nsgwutil user delete -h hostname -n sgwdb --sguser sgwuser\n```\n\nDelete database \"sgwdb\":\n```\nsgwutil database delete -h hostname -n sgwdb\n```\n## caputil\nNote: Save Capella v4 token file as $HOME/.capella/default-api-key-token.txt\\\nCreate Capella cluster:\n```\ncaputil cluster create --project project-name --name testdb --region us-east-1\n```\nUpdate Capella cluster (to add services):\n```\ncaputil cluster update --project pytest-name --name testdb --services search,analytics,eventing\n```\nDelete Capella cluster:\n```\ncaputil cluster delete --project project-name --name testdb --region us-east-1\n```\nCreate bucket:\n````\ncaputil bucket create --project project-name --db testdb --name test-bucket\n````\nChange database user password:\n```\ncaputil user password --project pytest-name --db testdb --name Administrator\n```\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "Couchbase connection manager",
"version": "2.2.40",
"project_urls": {
"Homepage": "https://github.com/mminichino/cb-util"
},
"split_keywords": [
"couchbase",
" nosql",
" pycouchbase",
" database"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "c2b25abd2e6acd34a6ce95f33c7bf55c4b3e1ca03dbbaca141af6fd2d7e78fee",
"md5": "42d403a536ba9e2935362f21ee3ad9e4",
"sha256": "a6a68f5e8bd453a9f0ff839359bc36329fd370c24c7daed80c1b2c850e498087"
},
"downloads": -1,
"filename": "cbcmgr-2.2.40.tar.gz",
"has_sig": false,
"md5_digest": "42d403a536ba9e2935362f21ee3ad9e4",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 139207,
"upload_time": "2024-05-07T00:48:26",
"upload_time_iso_8601": "2024-05-07T00:48:26.336173Z",
"url": "https://files.pythonhosted.org/packages/c2/b2/5abd2e6acd34a6ce95f33c7bf55c4b3e1ca03dbbaca141af6fd2d7e78fee/cbcmgr-2.2.40.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-07 00:48:26",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "mminichino",
"github_project": "cb-util",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "attrs",
"specs": [
[
">=",
"23.1.0"
]
]
},
{
"name": "couchbase",
"specs": [
[
">=",
"4.2.1"
]
]
},
{
"name": "dnspython",
"specs": [
[
">=",
"2.3.0"
]
]
},
{
"name": "docker",
"specs": [
[
">=",
"6.1.3"
]
]
},
{
"name": "pytest",
"specs": [
[
">=",
"8.1.1"
]
]
},
{
"name": "pytest-asyncio",
"specs": [
[
">=",
"0.23.6"
]
]
},
{
"name": "requests",
"specs": [
[
">=",
"2.31.0"
]
]
},
{
"name": "urllib3",
"specs": [
[
">=",
"1.26.16"
]
]
},
{
"name": "xmltodict",
"specs": [
[
">=",
"0.13.0"
]
]
},
{
"name": "bumpversion",
"specs": [
[
">=",
"0.6.0"
]
]
},
{
"name": "overrides",
"specs": [
[
">=",
"7.4.0"
]
]
},
{
"name": "Jinja2",
"specs": [
[
">=",
"3.0.0"
]
]
},
{
"name": "pandas",
"specs": [
[
">=",
"1.5.3"
]
]
},
{
"name": "numpy",
"specs": [
[
">=",
"1.24.3"
]
]
},
{
"name": "pillow",
"specs": [
[
">=",
"8.4.0"
]
]
},
{
"name": "aiohttp",
"specs": [
[
">=",
"3.9.3"
]
]
},
{
"name": "python-certifi-win32",
"specs": [
[
">=",
"1.6.1"
]
]
},
{
"name": "certifi",
"specs": [
[
">=",
"2023.5.7"
]
]
},
{
"name": "setuptools",
"specs": [
[
">=",
"65.5.1"
]
]
}
],
"lcname": "cbcmgr"
}