{ "info": { "author": "Per Kraulis", "author_email": "per.kraulis@scilifelab.se", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.6", "Topic :: Database :: Front-Ends" ], "description": "# CouchDB2\n\nCouchDB v2.x Python interface in a single module.\nAlso a command line tool; [see below](#command-line-tool).\n\nMost, but not all, features of this module work with CouchDB version < 2.0.\n\n## Installation\n\n```\n$ pip install couchdb2\n```\n\nThis module relies on `requests`: http://docs.python-requests.org/en/master/\n\n## Example code\n\n```python\nimport couchdb2\n\nserver = couchdb2.Server() # Arguments required according to local setup\ndb = server.create('test')\n\ndoc1 = {'_id': 'myid', 'name': 'mydoc', 'level': 4}\ndb.put(doc1)\ndoc = db['myid']\nassert doc == doc1\n\ndoc2 = {'name': 'another', 'level': 0}\ndb.put(doc2)\nprint(doc2)\n# {'_id': '66b5...', '_rev': '1-f3ac...', 'name': 'another', 'level': 0}\n\ndb.put_design('mydesign', \n {\"views\":\n {\"name\": {\"map\": \"function (doc) {emit(doc.name, null);}\"}\n }\n })\nresult = db.view('mydesign', 'name', key='another', include_docs=True)\nassert len(result) == 1\nprint(result[0].doc) # Same printout as above, using OrderedDict\n\ndb.destroy()\n```\n\n## Server\n```python\nserver = Server(href='http://localhost:5984/', username=None, password=None, use_session=True)\n```\nConnection to the CouchDB server.\n\nIf `use_session` is true, then an authenticated session is used\ntransparently. Otherwise, username and password is sent with each request.\n\n### version\n```python\nserver.version\n```\nProperty attribute providing the version of the CouchDB server software.\n\n### user_context\n```python\nserver.user_context\n```\nProperty attribute providing the user context of the connection.\n\n### \\_\\_str\\_\\_\n```python\nstr(server)\n```\nReturn a simple string representation of the server interface.\n\n### \\_\\_len\\_\\_\n```python\nlen(server)\n```\nReturn the number of user-defined databases.\n\n### \\_\\_iter\\_\\_\n```python\nfor db in server: ...\n```\nReturn an iterator over all user-defined databases on the server.\n\n### \\_\\_getitem\\_\\_\n```python\ndb = server[name]\n```\nGet the named database.\n\n### \\_\\_contains\\_\\_\n```python\nif name in server: ...\n```\nDoes the named database exist?\n\n### \\_\\_call\\_\\_\n```python\ndata = server()\n```\nReturn meta information about the server.\n\n### up\n```python\nif server.up(): ...\n```\nIs the server up and running, ready to respond to requests?\n\nCouchDB version >= 2.0.\n\n### get\n```python\ndb = server.get(name, check=True)\n```\nGet the named database. If `check` is true, then raise NotFoundError\nif the the database does not exist.\n\n### create\n```python\ndb = server.create(name)\n```\nCreate the named database.\n\n### get_config\n```python\ndata = server.get_config(nodename='_local')\n```\nGet the named node's configuration.\n\n### get_active_tasks\n```python\ndata = server.get_active_tasks()\n```\nReturn a list of running tasks.\n\n### get_cluster_setup\n```python\ndata = server.get_cluster_setup(config)\n```\nReturn the status of the node or cluster.\n\nCouchDB version >= 2.0.\n\n### set_cluster_setup\n```python\nserver.cluster_setup(doc)\n```\nConfigure a node as a single node, as part of a cluster, or finalize a cluster.\n\nCouchDB version >= 2.0.\n\n### get_membership\n```python\ndata = server.get_membership()\n```\nReturn data about the nodes that are part of the cluster.\n\nCouchDB version >= 2.0.\n\n### set_replicate\n```python\ndata = server.set_replicate(doc)\n```\nRequest, configure, or stop, a replication operation.\n\n### get_scheduler_jobs\n```python\ndata = server.get_scheduler_jobs(limit=None, skip=None)\n```\nGet a list of replication jobs.\n\nCouchDB version >= 2.0.\n\n### get_scheduler_docs\n```python\ndata = server.get_scheduler_docs(limit=None, skip=None,\n replicator_db=None, docid=None)\n```\nGet information about replication document(s).\n\nCouchDB version >= 2.0.\n\n### get_node_stats\n```python\ndata = server.get_node_stats(nodename='_local')\n```\nReturn statistics for the running server.\n\nCouchDB version >= 2.0.\n\n### get_node_system\n```python\ndata = server.get_node_system(nodename='_local')\n```\nReturn various system-level statistics for the running server.\n\nCouchDB version >= 2.0.\n\n## Database\n```python\ndb = Database(server, name, check=True)\n```\nInterface to a named CouchDB database.\n\nIf `check` is true, then raise NotFoundError if the the database does not exist.\n\n### \\_\\_str\\_\\_\n```python\nstr(db)\n```\nReturn the name of the CouchDB database.\n\n### \\_\\_len\\_\\_\n```python\nlen(db)\n```\nReturn the number of documents in the database.\n\n### \\_\\_contains\\_\\_\n```python\nif id in db: ...\n```\nDoes a document with the given id exist in the database?\n\n### \\_\\_iter\\_\\_\n```python\nfor doc in db: ...\n```\nReturn an iterator over all documents in the database.\n\n### \\_\\_getitem\\_\\_\n```python\ndoc = db[id]\n```\nReturn the document with the given id.\n\n### exists\n```python\nif db.exists(): ...\n```\nDoes the database exist?\n\n### check\n```python\ndb.check()\n```\nRaises NotFoundError if the database does not exist.\n\n### create\n```python\ndb.create()\n```\nCreate the database.\n\n### destroy\n```python\ndb.destroy()\n```\nDelete the database and all its contents.\n\n### get_info\n```python\ndata = db.get_info()\n```\nReturn a dictionary with information about the database.\n\n### get_security\n```python\ndata = db.get_security()\n```\nReturn a dictionary with security information for the database.\n\n### set_security\n```python\ndb.set_security(doc)\n```\nSet the security information for the database.\n\n### compact\n```python\ndb.compact(finish=False, callback=None)\n```\nCompact the CouchDB database by rewriting the disk database file\nand removing old revisions of documents.\n\nIf `finish` is True, then return only when compaction is done.\nIn addition, if defined, the function `callback(seconds)` is called\nevery second until compaction is done.\n\n### compact_design\n```python\ndb.compact_design(designname)\n```\nCompact the view indexes associated with the named design document.\n\n### view_cleanup\n```python\ndb.view_cleanup()\n```\nRemove unnecessary view index files due to changed views in\ndesign documents of the database.\n\n### get\n```python\ndoc = db.get(id, rev=None, revs_info=False, default=None)\n```\nReturn the document with the given id, or the `default` value if not found.\n\n### put\n```python\ndb.put(doc)\n```\nInsert or update the document.\n\nIf the document is already in the database, the `_rev` item must\nbe present in the document; its value will be updated.\n\nIf the document does not contain an item `_id`, one will be added\nhaving a UUID4 value. The `_rev` item will also be added.\n\n### delete\n```python\ndb.delete(doc)\n```\nDelete the document.\n\n### get_designs\n```python\ndata = db.get_designs()\n```\nReturn the design documents for the database.\n\nCouchDB version >= 2.2.\n\n### get_design\n```python\ndata = db.get_design(designname)\n```\nGet the named design document.\n\n### put_design\n```python\ndb.put_design(designname, doc, rebuild=True)\n```\nInsert or update the design document under the given name.\n\nIf the existing design document is identical, no action is taken and\nFalse is returned, else the document is updated and True is returned.\n\nIf `rebuild` is True, force view indexes to be rebuilt after update. \nThis may take some time.\n\nExample of doc:\n```\n {\"views\":\n {\"name\":\n {\"map\": \"function (doc) {emit(doc.name, null);}\"},\n \"name_sum\":\n {\"map\": \"function (doc) {emit(doc.name, 1);}\",\n \"reduce\": \"_sum\"},\n \"name_count\":\n {\"map\": \"function (doc) {emit(doc.name, null);}\",\n \"reduce\": \"_count\"}\n }}\n```\n\nMore info: http://docs.couchdb.org/en/latest/api/ddoc/common.html\n\n### view\n```python\nresult = db.view(designname, viewname, key=None, keys=None,\n startkey=None, endkey=None, skip=None, limit=None,\n sorted=True, descending=False,\n group=False, group_level=None, reduce=None,\n include_docs=False)\n```\nReturn a [ViewResult](#viewresult) object, containing\n[Row](#row) objects in the attribute `rows` (a list).\n\n### get_indexes\n```python\ndata = db.get_indexes()\n```\nReturn a list of all indexes in the database.\n\nCouchDB version >= 2.0.\n\n### put_index\n```python\ndb.put_index(fields, ddoc=None, name=None, selector=None)\n```\nStore a Mango index specification. CouchDB v2.x only.\n\n- `fields` is a list of fields to index.\n- `ddoc` is the design document name. Generated if none given.\n- `name` is the name of the index. Generated if none given.\n- `selector` is a partial filter selector, which may be omitted.\n\nReturns a dictionary with items `id` (design document name; sic!),\n`name` (index name) and `result` (`created` or `exists`).\n\nCouchDB version >= 2.0.\n\n### find\n```python\ndata = db.find(selector, use_index=None, limit=None, skip=None, sort=None,\n fields=None, bookmark=None, update=None)\n```\nSelect documents according to the Mango index selector.\n\nReturns a dictionary with items `docs`, `warning`, `execution_stats`\nand `bookmark`.\n\nCouchDB version >= 2.0.\n\n### explain\n```python\ndata = db.explain(selector, use_index=None, limit=None, skip=None, sort=None,\n fields=None, bookmark=None, update=None)\n```\nReturn info on which index is being used by the query.\n\nCouchDB version >= 2.0.\n\n### get_attachment\n```python\nfileobj = db.get_attachment(doc, filename)\n```\nReturn a file-like object containing the content of the attachment.\n\n### put_attachment\n```python\nrev = db.put_attachment(doc, content, filename=None, content_type=None)\n```\n`content` is a string or a file-like object.\nReturn the new revision of the document.\nThe revision in the input `doc` is **not** changed.\n\nIf no filename, then an attempt is made to get it from content object.\n\n### delete_attachment\n```python\nrev = db.delete_attachment(doc, filename)\n```\nDelete the attachment. Return the new revision of the document.\nThe revision in the input `doc` is **not** changed.\n\n### dump\n```python\n(ndocs, nfiles) = db.dump(filepath, callback=None)\n```\nDump the entire database to a tar file.\n\nIf defined, the function `callback(ndocs, nfiles)` is called \nevery 100 documents.\n\nIf the filepath ends with `.gz`, then the tar file is gzip compressed.\nThe `_rev` item of each document is kept.\n\nA tuple `(ndocs, nfiles)` is returned.\n\n### undump\n```python\n(ndocs, nfiles) = db.undump(filepath, callback=None)\n```\nLoad the tar file, which must have been produced by `dump`.\n\nIf defined, the function `callback(ndocs, nfiles)` is called \nevery 100 documents.\n\nNOTE: The documents are just added to the database, ignoring any\n`_rev` items.\n\nA tuple `(ndocs, nfiles)` is returned.\n\n## CouchDB2Exception\n```python\nCouchDB2Exception()\n```\nBase CouchDB2 exception.\n## NotFoundError\n```python\nNotFoundError()\n```\nNo such entity exists.\n## BadRequestError\n```python\nBadRequestError()\n```\nInvalid request; bad name, body or headers.\n## CreationError\n```python\nCreationError()\n```\nCould not create the entity; it exists already.\n## RevisionError\n```python\nRevisionError()\n```\nWrong or missing `_rev` item in the document to save.\n## AuthorizationError\n```python\nAuthorizationError()\n```\nCurrent user not authorized to perform the operation.\n## ContentTypeError\n```python\nContentTypeError()\n```\nBad `Content-Type` value in the request.\n## ServerError\n```python\nServerError()\n```\nInternal server error.\n## ViewResult\n\nObject returned as result from `db.view()`.\n\n```python\nViewResult(rows, offset, total_rows)\n```\nAttributes:\n\n- `rows`: the list of `Row` objects.\n- `offset`: the offset used for the set of rows.\n- `total_rows`: the total number of rows selected.\n\n### \\_\\_len\\_\\_\n```python\nlen(viewresult)\n```\nReturn the number of rows in the view result.\n\n### \\_\\_iter\\_\\_\n```python\nfor row in viewresult: ...\n```\nReturn an iterator over all rows in the view result.\n\n### \\_\\_getitem\\_\\_\n```python\nrow = viewresult[i]\n```\nReturn the indexed view result row.\n\n### json\n```python\ndata = viewresult.json()\n```\nReturn view result data in a JSON-like representation.\n\n## Row\n\nNamed-tuple object returned in ViewResult list attribute `rows`.\n\n```python\nRow(id, key, value, doc)\n```\n\n- `id`: the identifier of the document, if any.\n- `key`: the key for the index row.\n- `value`: the value for the index row.\n- `doc`: the document, if any.\n\n### id\nAlias for field number 0\n### key\nAlias for field number 1\n### value\nAlias for field number 2\n### doc\nAlias for field number 3\n\n## Utility functions\n\n### read_settings\n```python\nread_settings(filepath, settings=None)\n```\nRead the settings lookup from a JSON format file.\nIf `settings` is given, then return an updated copy of it,\nelse copy the default settings, update, and return.\n\n## Command line tool\n\nThe module is also a command line tool for interacting with the CouchDB server.\nInstalling it using `pip` will set up the command `couchdb2`.\n\nSettings for the command line tool are updated from the following sources,\nin the order given and if existing:\n\n1) Default values are\n ```\n {\n \"SERVER\": \"http://localhost:5984\",\n \"DATABASE\": null,\n \"USERNAME\": null,\n \"PASSWORD\": null\n }\n ```\n2) Read from the JSON file `~/.couchdb2` (in your home directory).\n3) Read from the JSON file `settings.json` (in the current working directory).\n4) Read from the JSON file given by command line option `--settings FILEPATH`.\n\n### Options\n\nTo print available command options:\n\n```\n$ couchdb2 -h\nusage: couchdb2 [options]\n\nCouchDB v2.x command line tool, leveraging Python module CouchDB2.\n\noptional arguments:\n -h, --help show this help message and exit\n --settings FILEPATH settings file in JSON format\n -S SERVER, --server SERVER\n CouchDB server URL, including port number\n -d DATABASE, --database DATABASE\n database to operate on\n -u USERNAME, --username USERNAME\n CouchDB user account name\n -p PASSWORD, --password PASSWORD\n CouchDB user account password\n -q, --password_question\n ask for the password by interactive input\n -o FILEPATH, --output FILEPATH\n write output to the given file (JSON format)\n --indent INT indentation level for JSON format output file\n -y, --yes do not ask for confirmation (delete, destroy)\n -v, --verbose print more information\n -s, --silent print no information\n\nserver operations:\n -V, --version output CouchDB server version\n --list output a list of the databases on the server\n\ndatabase operations:\n --create create the database\n --destroy delete the database and all its contents\n --compact compact the database; may take some time\n --compact_design DDOC\n compact the view indexes for the named design doc\n --view_cleanup remove view index files no longer required\n --info output information about the database\n --security output security information for the database\n --set_security FILEPATH\n set security information for the database from the\n JSON file\n --list_designs list design documents for the database\n --design DDOC output the named design document\n --put_design DDOC FILEPATH\n store the named design document from the file\n --delete_design DDOC delete the named design document\n --dump FILEPATH create a dump file of the database\n --undump FILEPATH load a dump file into the database\n\ndocument operations:\n -G DOCID, --get DOCID\n output the document with the given identifier\n -P FILEPATH, --put FILEPATH\n store the document; arg is literal doc or filepath\n --delete DOCID delete the document with the given identifier\n\nattachments to document:\n --attach DOCID FILEPATH\n attach the specified file to the given document\n --detach DOCID FILENAME\n remove the attached file from the given document\n --get_attach DOCID FILENAME\n get the attached file from the given document; write\n to same filepath or that given by '-o'\n\nquery a design view, returning rows:\n --view SPEC design view '{design}/{view}' to query\n --key KEY key value selecting view rows\n --startkey KEY start key value selecting range of view rows\n --endkey KEY end key value selecting range of view rows\n --startkey_docid DOCID\n return rows starting with the specified document\n --endkey_docid DOCID stop returning rows when specified document reached\n --group group the results using the 'reduce' function\n --group_level INT specify the group level to use\n --noreduce do not use the 'reduce' function of the view\n --limit INT limit the number of returned rows\n --skip INT skip this number of rows before returning result\n --descending sort rows in descending order (swap start/end keys!)\n --include_docs include documents in result\n```\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/pekrau/CouchDB2", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "CouchDB2", "package_url": "https://pypi.org/project/CouchDB2/", "platform": "", "project_url": "https://pypi.org/project/CouchDB2/", "project_urls": { "Homepage": "https://github.com/pekrau/CouchDB2" }, "release_url": "https://pypi.org/project/CouchDB2/1.7.4/", "requires_dist": [ "requests (>=2)" ], "requires_python": "", "summary": "CouchDB v2.x Python interface in a single module. Also a command line tool.", "version": "1.7.4" }, "last_serial": 4725618, "releases": { "1.6.10": [ { "comment_text": "", "digests": { "md5": "3732dcad98c385261ff2cd55c7f99857", "sha256": "7f7ec022c5f8a1c1857c293ce6d75936c3d36c5decaa7698096239c42dd60b43" }, "downloads": -1, "filename": "CouchDB2-1.6.10-py3-none-any.whl", "has_sig": false, "md5_digest": "3732dcad98c385261ff2cd55c7f99857", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 16721, "upload_time": "2019-01-14T13:35:01", "url": "https://files.pythonhosted.org/packages/3c/5e/cba502537076602c333bf123f9adb43b9d81c147521a712ccf6af0ccb8b4/CouchDB2-1.6.10-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "689938376185a87d6368c493cce6d7b8", "sha256": "169a77ef30d1bf6b8fd7dab1ed07c982b82625ac03793d57a2148acc9b449db9" }, "downloads": -1, "filename": "CouchDB2-1.6.10.tar.gz", "has_sig": false, "md5_digest": "689938376185a87d6368c493cce6d7b8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17058, "upload_time": "2019-01-14T13:35:04", "url": "https://files.pythonhosted.org/packages/c4/ac/f64d4d18033bf5c5135ef7bdb9042106fc7101f9a515fedde846b187514c/CouchDB2-1.6.10.tar.gz" } ], "1.7.2": [ { "comment_text": "", "digests": { "md5": "7caa10c7fe52bb02d343d5ee26222211", "sha256": "eba1caa0797ef8c9600332cc3f1306b1c2371c754c7f6c0047f3bcb14e64a212" }, "downloads": -1, "filename": "CouchDB2-1.7.2-py3-none-any.whl", "has_sig": false, "md5_digest": "7caa10c7fe52bb02d343d5ee26222211", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 17980, "upload_time": "2019-01-15T11:44:23", "url": "https://files.pythonhosted.org/packages/07/93/60968a6d2eaa80e1a23e9c52d19234c9cf9c9ea8cc5c5611e89bd421e7c2/CouchDB2-1.7.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "96b45deeb4a074098527143662a9dcdb", "sha256": "0a29d7daeb5df92910914ea01641b63e5685bede7b119948e296a6c3562da586" }, "downloads": -1, "filename": "CouchDB2-1.7.2.tar.gz", "has_sig": false, "md5_digest": "96b45deeb4a074098527143662a9dcdb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17700, "upload_time": "2019-01-15T11:44:25", "url": "https://files.pythonhosted.org/packages/6f/36/e4687d38b35a15ca69de2bf3d60391bb56a2efca8d04ee55f35b4282a142/CouchDB2-1.7.2.tar.gz" } ], "1.7.4": [ { "comment_text": "", "digests": { "md5": "1a02d07e128bee9a6da1a0a7d8261e90", "sha256": "41a0ce98f3ba90b92355ec3e6c138d54905ca973340a8be358b93441374e8e14" }, "downloads": -1, "filename": "CouchDB2-1.7.4-py3-none-any.whl", "has_sig": false, "md5_digest": "1a02d07e128bee9a6da1a0a7d8261e90", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 17196, "upload_time": "2019-01-22T11:46:48", "url": "https://files.pythonhosted.org/packages/fd/ed/7417b916b0cd7863618dc9e73b80ea51c627c05604fcd372ba6185791c57/CouchDB2-1.7.4-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "9602765c067af0b6903c0453682363df", "sha256": "599b2233efbaf83fcfa6fc11c91d70265d88a04fd8feff38a622c32860e583e4" }, "downloads": -1, "filename": "CouchDB2-1.7.4.tar.gz", "has_sig": false, "md5_digest": "9602765c067af0b6903c0453682363df", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17749, "upload_time": "2019-01-22T11:46:50", "url": "https://files.pythonhosted.org/packages/f7/d6/e1baac91732d1b5c691b44885cf2fcc38d2ce845afbc5d1d6ec8b86926db/CouchDB2-1.7.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "1a02d07e128bee9a6da1a0a7d8261e90", "sha256": "41a0ce98f3ba90b92355ec3e6c138d54905ca973340a8be358b93441374e8e14" }, "downloads": -1, "filename": "CouchDB2-1.7.4-py3-none-any.whl", "has_sig": false, "md5_digest": "1a02d07e128bee9a6da1a0a7d8261e90", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 17196, "upload_time": "2019-01-22T11:46:48", "url": "https://files.pythonhosted.org/packages/fd/ed/7417b916b0cd7863618dc9e73b80ea51c627c05604fcd372ba6185791c57/CouchDB2-1.7.4-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "9602765c067af0b6903c0453682363df", "sha256": "599b2233efbaf83fcfa6fc11c91d70265d88a04fd8feff38a622c32860e583e4" }, "downloads": -1, "filename": "CouchDB2-1.7.4.tar.gz", "has_sig": false, "md5_digest": "9602765c067af0b6903c0453682363df", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17749, "upload_time": "2019-01-22T11:46:50", "url": "https://files.pythonhosted.org/packages/f7/d6/e1baac91732d1b5c691b44885cf2fcc38d2ce845afbc5d1d6ec8b86926db/CouchDB2-1.7.4.tar.gz" } ] }