couchdb3 2.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
couchdb3-2.0.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Nikolai Vlahovic
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,180 @@
1
+ Metadata-Version: 2.3
2
+ Name: couchdb3
3
+ Version: 2.0.0
4
+ Summary: A wrapper around the CouchDB API.
5
+ License: MIT
6
+ Author: Nikolai Vlahovic
7
+ Author-email: vlahovic.nikolai@gmail.com
8
+ Requires-Python: >= 3.10
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Requires-Dist: requests (>=2.32.4,<3.0.0)
16
+ Description-Content-Type: text/markdown
17
+
18
+ # CouchDB3
19
+
20
+ *CouchDB3* is a wrapper around the CouchDB API. For more detailed information, please refer to
21
+ [the documentation](https://n-vlahovic.github.io/couchdb3/).
22
+
23
+ ## Disclaimer
24
+
25
+ Big parts of the documentation (and thus docstrings) have been copied from CouchDB's API's great
26
+ [official documentation](https://docs.couchdb.org/en/main/api/index.html).
27
+
28
+
29
+ ## Requirements
30
+
31
+ - Python version `>= 3.10`
32
+ - CouchDB version `3.x`
33
+
34
+ ## Installation
35
+ Installing via PyPi
36
+ ```bash
37
+ pip install couchdb3
38
+ ```
39
+
40
+ Installing via Github
41
+ ```bash
42
+ python -m pip install git+https://github.com/n-Vlahovic/couchdb3.git
43
+ ```
44
+
45
+ Installing from source
46
+ ```bash
47
+ git clone https://github.com/n-Vlahovic/couchdb3
48
+ python -m pip install -e couchdb3
49
+ ```
50
+
51
+ ## Quickstart
52
+
53
+ ### Connecting to a database server
54
+
55
+ ```python
56
+ import couchdb3
57
+
58
+ client = couchdb3.Server(
59
+ "http://user:password@127.0.0.1:5984"
60
+ )
61
+
62
+ # Checking if the server is up
63
+ print(client.up())
64
+ # True
65
+ ```
66
+
67
+ user and password can also be passed into the Server constructor as keyword parameters, e.g.
68
+
69
+ ```python
70
+ client = couchdb3.Server(
71
+ "127.0.0.1:5984", # Scheme omitted - will assume http protocol
72
+ user="user",
73
+ password="password"
74
+ )
75
+ ```
76
+
77
+ Both approaches are equivalent, i.e. in both cases the instance's `scheme,host,port,user,password` will be identical.
78
+
79
+ Further, clients can be used with context managers:
80
+ ```python
81
+ with couchdb3.Server("http://user:password@127.0.0.1:5984") as client:
82
+ # Do stuff
83
+ ...
84
+ ```
85
+
86
+ ### Getting or creating a database
87
+ ```python
88
+ dbname = "mydb"
89
+ db = client.get(dbname) if dbname in client else client.create(dbname)
90
+ print(db)
91
+ # Database: mydb
92
+ ```
93
+
94
+ ### Creating a document
95
+ ```python
96
+ mydoc = {
97
+ "_id": "mydoc-id",
98
+ "name": "Hello",
99
+ "type": "World"
100
+ }
101
+ print(db.save(mydoc))
102
+ # ('mydoc-id', True, '1-24fa3b3fd2691da9649dd6abe3cafc7e')
103
+ ```
104
+ Note: `Database.save` requires the document to have an id (i.e. a key `_id`),
105
+ `Database.create` does not.
106
+
107
+ ### Updating a document
108
+ To update an existing document, retrieving the revision is paramount.
109
+ In the example below, `dbdoc` contains the key `_rev` and the builtin `dict.update` function is used to update the
110
+ document before saving it.
111
+ ```python
112
+ mydoc = {
113
+ "_id": "mydoc-id",
114
+ "name": "Hello World",
115
+ "type": "Hello World"
116
+ }
117
+ dbdoc = db.get(mydoc["_id"])
118
+ dbdoc.update(mydoc)
119
+ print(db.save(dbdoc))
120
+ # ('mydoc-id', True, '2-374aa8f0236b9120242ca64935e2e8f1')
121
+ ```
122
+ Alternatively, one can use `Database.rev` to fetch the latest revision and overwrite the document
123
+ ```python
124
+ mydoc = {
125
+ "_id": "mydoc-id",
126
+ "_rev": db.rev("mydoc-id"),
127
+ "name": "Hello World",
128
+ "type": "Hello World"
129
+ }
130
+ print(db.save(mydoc))
131
+ # ('mydoc-id', True, '3-d56b14b7ffb87960b51d03269990a30d')
132
+ ```
133
+
134
+ ### Deleting a document
135
+ To delete a document, the `docid` and `rev` are needed
136
+ ```python
137
+ docid = "mydoc-id"
138
+ print(db.delete(docid=docid, rev=db.rev(docid))) # Fetch the revision on the go
139
+ # True
140
+ ```
141
+
142
+ ### Working with partitions
143
+ For a partitioned database, the `couchdb3.database.Partition` class offers a wrapper around partitions (acting similarly
144
+ to collections in Mongo).
145
+
146
+ ```python
147
+ from couchdb3 import Server, Database, Partition
148
+
149
+
150
+ client: Server = Server(...)
151
+ db: Database = client["some-db"]
152
+ partition: Partition = db.get_partition("partition_id")
153
+ ```
154
+
155
+ Partition instances append the partition's ID the document IDs (`partition-id:doc-id`) for a simpler user interaction,
156
+ e.g.
157
+ ```python
158
+ doc_id = "test-id"
159
+ print(doc_id in partition) # no need to append the partition's ID
160
+ rev = partition.rev(doc_id)
161
+ partition.save({
162
+ "_id": doc_id, # no need to append the partition's ID
163
+ "_rev": rev,
164
+ ...
165
+ })
166
+ ```
167
+
168
+ The partition ID will only be appended provided document IDs do not start with `partition-id`, e.g. the following will
169
+ work and be equivalent to the previous example
170
+ ```python
171
+ doc_id = "partition_id:test-id"
172
+ print(doc_id in partition)
173
+ rev = partition.rev(doc_id)
174
+ partition.save({
175
+ "_id": doc_id,
176
+ "_rev": rev,
177
+ ...
178
+ })
179
+ ```
180
+
@@ -0,0 +1,162 @@
1
+ # CouchDB3
2
+
3
+ *CouchDB3* is a wrapper around the CouchDB API. For more detailed information, please refer to
4
+ [the documentation](https://n-vlahovic.github.io/couchdb3/).
5
+
6
+ ## Disclaimer
7
+
8
+ Big parts of the documentation (and thus docstrings) have been copied from CouchDB's API's great
9
+ [official documentation](https://docs.couchdb.org/en/main/api/index.html).
10
+
11
+
12
+ ## Requirements
13
+
14
+ - Python version `>= 3.10`
15
+ - CouchDB version `3.x`
16
+
17
+ ## Installation
18
+ Installing via PyPi
19
+ ```bash
20
+ pip install couchdb3
21
+ ```
22
+
23
+ Installing via Github
24
+ ```bash
25
+ python -m pip install git+https://github.com/n-Vlahovic/couchdb3.git
26
+ ```
27
+
28
+ Installing from source
29
+ ```bash
30
+ git clone https://github.com/n-Vlahovic/couchdb3
31
+ python -m pip install -e couchdb3
32
+ ```
33
+
34
+ ## Quickstart
35
+
36
+ ### Connecting to a database server
37
+
38
+ ```python
39
+ import couchdb3
40
+
41
+ client = couchdb3.Server(
42
+ "http://user:password@127.0.0.1:5984"
43
+ )
44
+
45
+ # Checking if the server is up
46
+ print(client.up())
47
+ # True
48
+ ```
49
+
50
+ user and password can also be passed into the Server constructor as keyword parameters, e.g.
51
+
52
+ ```python
53
+ client = couchdb3.Server(
54
+ "127.0.0.1:5984", # Scheme omitted - will assume http protocol
55
+ user="user",
56
+ password="password"
57
+ )
58
+ ```
59
+
60
+ Both approaches are equivalent, i.e. in both cases the instance's `scheme,host,port,user,password` will be identical.
61
+
62
+ Further, clients can be used with context managers:
63
+ ```python
64
+ with couchdb3.Server("http://user:password@127.0.0.1:5984") as client:
65
+ # Do stuff
66
+ ...
67
+ ```
68
+
69
+ ### Getting or creating a database
70
+ ```python
71
+ dbname = "mydb"
72
+ db = client.get(dbname) if dbname in client else client.create(dbname)
73
+ print(db)
74
+ # Database: mydb
75
+ ```
76
+
77
+ ### Creating a document
78
+ ```python
79
+ mydoc = {
80
+ "_id": "mydoc-id",
81
+ "name": "Hello",
82
+ "type": "World"
83
+ }
84
+ print(db.save(mydoc))
85
+ # ('mydoc-id', True, '1-24fa3b3fd2691da9649dd6abe3cafc7e')
86
+ ```
87
+ Note: `Database.save` requires the document to have an id (i.e. a key `_id`),
88
+ `Database.create` does not.
89
+
90
+ ### Updating a document
91
+ To update an existing document, retrieving the revision is paramount.
92
+ In the example below, `dbdoc` contains the key `_rev` and the builtin `dict.update` function is used to update the
93
+ document before saving it.
94
+ ```python
95
+ mydoc = {
96
+ "_id": "mydoc-id",
97
+ "name": "Hello World",
98
+ "type": "Hello World"
99
+ }
100
+ dbdoc = db.get(mydoc["_id"])
101
+ dbdoc.update(mydoc)
102
+ print(db.save(dbdoc))
103
+ # ('mydoc-id', True, '2-374aa8f0236b9120242ca64935e2e8f1')
104
+ ```
105
+ Alternatively, one can use `Database.rev` to fetch the latest revision and overwrite the document
106
+ ```python
107
+ mydoc = {
108
+ "_id": "mydoc-id",
109
+ "_rev": db.rev("mydoc-id"),
110
+ "name": "Hello World",
111
+ "type": "Hello World"
112
+ }
113
+ print(db.save(mydoc))
114
+ # ('mydoc-id', True, '3-d56b14b7ffb87960b51d03269990a30d')
115
+ ```
116
+
117
+ ### Deleting a document
118
+ To delete a document, the `docid` and `rev` are needed
119
+ ```python
120
+ docid = "mydoc-id"
121
+ print(db.delete(docid=docid, rev=db.rev(docid))) # Fetch the revision on the go
122
+ # True
123
+ ```
124
+
125
+ ### Working with partitions
126
+ For a partitioned database, the `couchdb3.database.Partition` class offers a wrapper around partitions (acting similarly
127
+ to collections in Mongo).
128
+
129
+ ```python
130
+ from couchdb3 import Server, Database, Partition
131
+
132
+
133
+ client: Server = Server(...)
134
+ db: Database = client["some-db"]
135
+ partition: Partition = db.get_partition("partition_id")
136
+ ```
137
+
138
+ Partition instances append the partition's ID the document IDs (`partition-id:doc-id`) for a simpler user interaction,
139
+ e.g.
140
+ ```python
141
+ doc_id = "test-id"
142
+ print(doc_id in partition) # no need to append the partition's ID
143
+ rev = partition.rev(doc_id)
144
+ partition.save({
145
+ "_id": doc_id, # no need to append the partition's ID
146
+ "_rev": rev,
147
+ ...
148
+ })
149
+ ```
150
+
151
+ The partition ID will only be appended provided document IDs do not start with `partition-id`, e.g. the following will
152
+ work and be equivalent to the previous example
153
+ ```python
154
+ doc_id = "partition_id:test-id"
155
+ print(doc_id in partition)
156
+ rev = partition.rev(doc_id)
157
+ partition.save({
158
+ "_id": doc_id,
159
+ "_rev": rev,
160
+ ...
161
+ })
162
+ ```
@@ -0,0 +1,18 @@
1
+ [project]
2
+ name = "couchdb3"
3
+ version = "2.0.0"
4
+ description = "A wrapper around the CouchDB API."
5
+ authors = [
6
+ {name = "Nikolai Vlahovic",email = "vlahovic.nikolai@gmail.com"}
7
+ ]
8
+ license = {text = "MIT"}
9
+ readme = "README.md"
10
+ requires-python = ">= 3.10"
11
+ dependencies = [
12
+ "requests (>=2.32.4,<3.0.0)"
13
+ ]
14
+
15
+
16
+ [build-system]
17
+ requires = ["poetry-core>=2.0.0,<3.0.0"]
18
+ build-backend = "poetry.core.masonry.api"
@@ -0,0 +1,169 @@
1
+ __doc__ = """# CouchDB3
2
+
3
+ *CouchDB3* is a wrapper around the CouchDB API. For more detailed information, please refer to
4
+ [the documentation](https://n-vlahovic.github.io/couchdb3/).
5
+
6
+ ## Disclaimer
7
+
8
+ Big parts of the documentation (and thus docstrings) have been copied from CouchDB's API's great
9
+ [official documentation](https://docs.couchdb.org/en/main/api/index.html).
10
+
11
+
12
+ ## Requirements
13
+
14
+ - Python version `>= 3.10`
15
+ - CouchDB version `3.x`
16
+
17
+ ## Installation
18
+ Installing via PyPi
19
+ ```bash
20
+ pip install couchdb3
21
+ ```
22
+
23
+ Installing via Github
24
+ ```bash
25
+ python -m pip install git+https://github.com/n-Vlahovic/couchdb3.git
26
+ ```
27
+
28
+ Installing from source
29
+ ```bash
30
+ git clone https://github.com/n-Vlahovic/couchdb3
31
+ python -m pip install -e couchdb3
32
+ ```
33
+
34
+ ## Quickstart
35
+
36
+ ### Connecting to a database server
37
+
38
+ ```python
39
+ import couchdb3
40
+
41
+ client = couchdb3.Server(
42
+ "http://user:password@127.0.0.1:5984"
43
+ )
44
+
45
+ # Checking if the server is up
46
+ print(client.up())
47
+ # True
48
+ ```
49
+
50
+ user and password can also be passed into the Server constructor as keyword parameters, e.g.
51
+
52
+ ```python
53
+ client = couchdb3.Server(
54
+ "127.0.0.1:5984", # Scheme omitted - will assume http protocol
55
+ user="user",
56
+ password="password"
57
+ )
58
+ ```
59
+
60
+ Both approaches are equivalent, i.e. in both cases the instance's `scheme,host,port,user,password` will be identical.
61
+
62
+ Further, clients can be used with context managers:
63
+ ```python
64
+ with couchdb3.Server("http://user:password@127.0.0.1:5984") as client:
65
+ # Do stuff
66
+ ...
67
+ ```
68
+
69
+ ### Getting or creating a database
70
+ ```python
71
+ dbname = "mydb"
72
+ db = client.get(dbname) if dbname in client else client.create(dbname)
73
+ print(db)
74
+ # Database: mydb
75
+ ```
76
+
77
+ ### Creating a document
78
+ ```python
79
+ mydoc = {
80
+ "_id": "mydoc-id",
81
+ "name": "Hello",
82
+ "type": "World"
83
+ }
84
+ print(db.save(mydoc))
85
+ # ('mydoc-id', True, '1-24fa3b3fd2691da9649dd6abe3cafc7e')
86
+ ```
87
+ Note: `Database.save` requires the document to have an id (i.e. a key `_id`),
88
+ `Database.create` does not.
89
+
90
+ ### Updating a document
91
+ To update an existing document, retrieving the revision is paramount.
92
+ In the example below, `dbdoc` contains the key `_rev` and the builtin `dict.update` function is used to update the
93
+ document before saving it.
94
+ ```python
95
+ mydoc = {
96
+ "_id": "mydoc-id",
97
+ "name": "Hello World",
98
+ "type": "Hello World"
99
+ }
100
+ dbdoc = db.get(mydoc["_id"])
101
+ dbdoc.update(mydoc)
102
+ print(db.save(dbdoc))
103
+ # ('mydoc-id', True, '2-374aa8f0236b9120242ca64935e2e8f1')
104
+ ```
105
+ Alternatively, one can use `Database.rev` to fetch the latest revision and overwrite the document
106
+ ```python
107
+ mydoc = {
108
+ "_id": "mydoc-id",
109
+ "_rev": db.rev("mydoc-id"),
110
+ "name": "Hello World",
111
+ "type": "Hello World"
112
+ }
113
+ print(db.save(mydoc))
114
+ # ('mydoc-id', True, '3-d56b14b7ffb87960b51d03269990a30d')
115
+ ```
116
+
117
+ ### Deleting a document
118
+ To delete a document, the `docid` and `rev` are needed
119
+ ```python
120
+ docid = "mydoc-id"
121
+ print(db.delete(docid=docid, rev=db.rev(docid))) # Fetch the revision on the go
122
+ # True
123
+ ```
124
+
125
+ ### Working with partitions
126
+ For a partitioned database, the `couchdb3.database.Partition` class offers a wrapper around partitions (acting similarly
127
+ to collections in Mongo).
128
+
129
+ ```python
130
+ from couchdb3 import Server, Database, Partition
131
+
132
+
133
+ client: Server = Server(...)
134
+ db: Database = client["some-db"]
135
+ partition: Partition = db.get_partition("partition_id")
136
+ ```
137
+
138
+ Partition instances append the partition's ID the document IDs (`partition-id:doc-id`) for a simpler user interaction,
139
+ e.g.
140
+ ```python
141
+ doc_id = "test-id"
142
+ print(doc_id in partition) # no need to append the partition's ID
143
+ rev = partition.rev(doc_id)
144
+ partition.save({
145
+ "_id": doc_id, # no need to append the partition's ID
146
+ "_rev": rev,
147
+ ...
148
+ })
149
+ ```
150
+
151
+ The partition ID will only be appended provided document IDs do not start with `partition-id`, e.g. the following will
152
+ work and be equivalent to the previous example
153
+ ```python
154
+ doc_id = "partition_id:test-id"
155
+ print(doc_id in partition)
156
+ rev = partition.rev(doc_id)
157
+ partition.save({
158
+ "_id": doc_id,
159
+ "_rev": rev,
160
+ ...
161
+ })
162
+ ```
163
+ """
164
+ from . import exceptions
165
+ from . import utils
166
+ from .database import Database, Partition
167
+ from .document import Document
168
+ from .server import Server
169
+ from .view import ViewResult, ViewRow