kover 2.2.0__tar.gz → 2.3.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.
Files changed (61) hide show
  1. {kover-2.2.0 → kover-2.3.0}/PKG-INFO +5 -1
  2. {kover-2.2.0 → kover-2.3.0}/kover/__init__.py +2 -3
  3. {kover-2.2.0 → kover-2.3.0}/kover/_internals/_mixins.py +3 -0
  4. {kover-2.2.0 → kover-2.3.0}/kover/client.py +51 -172
  5. kover-2.3.0/kover/codes.py +533 -0
  6. {kover-2.2.0 → kover-2.3.0}/kover/collection.py +108 -258
  7. {kover-2.2.0 → kover-2.3.0}/kover/cursor.py +10 -61
  8. {kover-2.2.0 → kover-2.3.0}/kover/database.py +49 -138
  9. {kover-2.2.0 → kover-2.3.0}/kover/gridfs/gridfs.py +24 -60
  10. {kover-2.2.0 → kover-2.3.0}/kover/gridfs/models.py +10 -20
  11. {kover-2.2.0 → kover-2.3.0}/kover/models/operations.py +2 -2
  12. {kover-2.2.0 → kover-2.3.0}/kover/models/other.py +16 -8
  13. {kover-2.2.0 → kover-2.3.0}/kover/models/replica_set.py +2 -2
  14. {kover-2.2.0 → kover-2.3.0}/kover/network/__init__.py +2 -0
  15. {kover-2.2.0 → kover-2.3.0}/kover/network/auth.py +20 -34
  16. kover-2.3.0/kover/network/compressors.py +73 -0
  17. {kover-2.2.0 → kover-2.3.0}/kover/network/msocket.py +16 -36
  18. {kover-2.2.0 → kover-2.3.0}/kover/network/serializer.py +49 -25
  19. {kover-2.2.0 → kover-2.3.0}/kover/schema.py +22 -40
  20. {kover-2.2.0 → kover-2.3.0}/kover/session.py +8 -36
  21. kover-2.3.0/kover/typings.py +30 -0
  22. {kover-2.2.0 → kover-2.3.0}/kover/utils.py +1 -11
  23. {kover-2.2.0 → kover-2.3.0}/pyproject.toml +9 -3
  24. kover-2.2.0/kover/codes.py +0 -104
  25. kover-2.2.0/kover/typings.py +0 -18
  26. {kover-2.2.0 → kover-2.3.0}/.gitignore +0 -0
  27. {kover-2.2.0 → kover-2.3.0}/CODE_OF_CONDUCT.md +0 -0
  28. {kover-2.2.0 → kover-2.3.0}/LICENSE +0 -0
  29. {kover-2.2.0 → kover-2.3.0}/README.md +0 -0
  30. {kover-2.2.0 → kover-2.3.0}/kover/_internals/__init__.py +0 -0
  31. {kover-2.2.0 → kover-2.3.0}/kover/_internals/_serializers.py +0 -0
  32. {kover-2.2.0 → kover-2.3.0}/kover/bson/__init__.py +0 -0
  33. {kover-2.2.0 → kover-2.3.0}/kover/bson/_helpers.py +0 -0
  34. {kover-2.2.0 → kover-2.3.0}/kover/bson/binary.py +0 -0
  35. {kover-2.2.0 → kover-2.3.0}/kover/bson/code.py +0 -0
  36. {kover-2.2.0 → kover-2.3.0}/kover/bson/codec_options.py +0 -0
  37. {kover-2.2.0 → kover-2.3.0}/kover/bson/datetime_ms.py +0 -0
  38. {kover-2.2.0 → kover-2.3.0}/kover/bson/dbref.py +0 -0
  39. {kover-2.2.0 → kover-2.3.0}/kover/bson/decimal128.py +0 -0
  40. {kover-2.2.0 → kover-2.3.0}/kover/bson/errors.py +0 -0
  41. {kover-2.2.0 → kover-2.3.0}/kover/bson/int64.py +0 -0
  42. {kover-2.2.0 → kover-2.3.0}/kover/bson/json_util.py +0 -0
  43. {kover-2.2.0 → kover-2.3.0}/kover/bson/max_key.py +0 -0
  44. {kover-2.2.0 → kover-2.3.0}/kover/bson/min_key.py +0 -0
  45. {kover-2.2.0 → kover-2.3.0}/kover/bson/objectid.py +0 -0
  46. {kover-2.2.0 → kover-2.3.0}/kover/bson/raw_bson.py +0 -0
  47. {kover-2.2.0 → kover-2.3.0}/kover/bson/regex.py +0 -0
  48. {kover-2.2.0 → kover-2.3.0}/kover/bson/son.py +0 -0
  49. {kover-2.2.0 → kover-2.3.0}/kover/bson/timestamp.py +0 -0
  50. {kover-2.2.0 → kover-2.3.0}/kover/bson/typings.py +0 -0
  51. {kover-2.2.0 → kover-2.3.0}/kover/bson/tz_util.py +0 -0
  52. {kover-2.2.0 → kover-2.3.0}/kover/enums.py +0 -0
  53. {kover-2.2.0 → kover-2.3.0}/kover/exceptions.py +0 -0
  54. {kover-2.2.0 → kover-2.3.0}/kover/gridfs/__init__.py +0 -0
  55. {kover-2.2.0 → kover-2.3.0}/kover/gridfs/exceptions.py +0 -0
  56. {kover-2.2.0 → kover-2.3.0}/kover/metadata/__init__.py +0 -0
  57. {kover-2.2.0 → kover-2.3.0}/kover/metadata/definitions.py +0 -0
  58. {kover-2.2.0 → kover-2.3.0}/kover/models/__init__.py +0 -0
  59. {kover-2.2.0 → kover-2.3.0}/kover/network/saslprep.py +0 -0
  60. {kover-2.2.0 → kover-2.3.0}/kover/py.typed +0 -0
  61. {kover-2.2.0 → kover-2.3.0}/requirements.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: kover
3
- Version: 2.2.0
3
+ Version: 2.3.0
4
4
  Summary: Fully async mongodb driver for mongod and replica sets.
5
5
  Project-URL: Repository, https://github.com/megawattka/kover
6
6
  Project-URL: Documentation, https://github.com/megawattka/kover
@@ -22,6 +22,10 @@ Requires-Python: >=3.10
22
22
  Requires-Dist: dnspython<3.0.0,>=1.16.0
23
23
  Requires-Dist: pydantic>=2.10.6
24
24
  Requires-Dist: typing-extensions>=4.12.2
25
+ Provides-Extra: snappy
26
+ Requires-Dist: python-snappy; extra == 'snappy'
27
+ Provides-Extra: zstd
28
+ Requires-Dist: zstd; extra == 'zstd'
25
29
  Description-Content-Type: text/markdown
26
30
 
27
31
  # kover
@@ -20,7 +20,7 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  # SOFTWARE.
22
22
 
23
- __version__ = "2.2.0"
23
+ __version__ = "2.3.0"
24
24
  __author__ = "oMegaPB"
25
25
  __license__ = "MIT"
26
26
  __copyright__ = "Copyright (C) 2024-present megawattka"
@@ -59,7 +59,7 @@ from .network import AuthCredentials
59
59
  from .schema import Document, SchemaGenerator
60
60
  from .session import Session, Transaction
61
61
  from .typings import xJsonT
62
- from .utils import HasToDict, chain, filter_non_null, maybe_to_dict
62
+ from .utils import chain, filter_non_null, maybe_to_dict
63
63
 
64
64
  __all__ = [
65
65
  "AuthCredentials",
@@ -73,7 +73,6 @@ __all__ = [
73
73
  "Database",
74
74
  "Delete",
75
75
  "Document",
76
- "HasToDict",
77
76
  "HelloResult",
78
77
  "Index",
79
78
  "IndexDirection",
@@ -30,3 +30,6 @@ class ModelMixin(BaseModel):
30
30
  def to_dict(self) -> xJsonT:
31
31
  """Convert the model to a dictionary with camel case keys."""
32
32
  return self.model_dump(by_alias=True, exclude_none=True)
33
+
34
+ def __str__(self) -> str:
35
+ return self.__repr__()
@@ -17,60 +17,16 @@ if TYPE_CHECKING:
17
17
 
18
18
  from .models import ReplicaSetConfig
19
19
  from .network import AuthCredentials
20
- from .typings import xJsonT
20
+ from .typings import COMPRESSION_T, xJsonT
21
21
 
22
22
 
23
23
  class Kover:
24
24
  """Kover client for interacting with a MongoDB server.
25
25
 
26
26
  Attributes:
27
- ----------
28
- socket : MongoSocket
29
- The underlying socket connection to the MongoDB server.
30
- signature : bytes | None
31
- The authentication signature, if authenticated.
32
-
33
- Methods:
34
- -------
35
- close() -> None
36
- Close the underlying socket connection.
37
- get_database(name: str) -> Database
38
- Get a Database instance for the specified database name.
39
- make_client(...)
40
- Create and return a new Kover client instance.
41
- refresh_sessions(sessions: list[Session]) -> None
42
- Refresh the provided list of sessions.
43
- end_sessions(sessions: list[Session]) -> None
44
- End the provided list of sessions.
45
- start_session() -> Session
46
- Start a new session.
47
- build_info() -> BuildInfo
48
- Retrieve build information from the MongoDB server.
49
- logout() -> None
50
- Log out the current user session.
51
- list_database_names() -> list[str]
52
- Retrieve the names of all databases on the MongoDB server.
53
- drop_database(name: str) -> None
54
- Drop the specified database from the MongoDB server.
55
- replica_set_initiate(config: xJsonT | None = None) -> None
56
- Initiate a replica set with the provided configuration.
57
- get_replica_set_status() -> xJsonT
58
- Retrieve the status of the replica set.
59
- shutdown(...)
60
- Shut down the MongoDB server.
61
- get_commandline() -> list[str]
62
- Retrieve the command line arguments used to start the MongoDB server.
63
- get_log(parameter: Literal["global", "startupWarnings"] = "startupWarnings") -> list[xJsonT]
64
- Retrieve log entries from the MongoDB server.
65
- rename_collection(...)
66
- Rename a collection in the MongoDB server.
67
- set_user_write_block_mode(param: bool) -> None
68
- Set the user write block mode on the MongoDB server.
69
- fsync(...)
70
- Flush all pending writes to disk and optionally lock the database.
71
- fsync_unlock(comment: str | None = None) -> None
72
- Unlock the database after a previous fsync lock operation.
73
- """ # noqa: E501
27
+ socket : The underlying socket connection to the MongoDB server.
28
+ signature : The authentication signature, if authenticated.
29
+ """
74
30
 
75
31
  def __init__(
76
32
  self,
@@ -95,8 +51,9 @@ class Kover:
95
51
  async def close(self) -> None:
96
52
  """Close the underlying socket connection.
97
53
 
98
- This method closes the socket writer and waits until the connection is fully closed.
99
- """ # noqa: E501
54
+ This method closes the socket writer
55
+ and waits until the connection is fully closed.
56
+ """
100
57
  self.socket.writer.close()
101
58
  await self.socket.writer.wait_closed()
102
59
 
@@ -104,13 +61,9 @@ class Kover:
104
61
  """Get a Database instance for the specified database name.
105
62
 
106
63
  Parameters:
107
- ----------
108
- name : str
109
- The name of the database to retrieve.
64
+ name : The name of the database to retrieve.
110
65
 
111
66
  Returns:
112
- -------
113
- Database
114
67
  An instance of the Database class for the given name.
115
68
  """
116
69
  return Database(name=name, client=self)
@@ -125,41 +78,38 @@ class Kover:
125
78
  port: int = 27017,
126
79
  credentials: AuthCredentials | None = None,
127
80
  loop: asyncio.AbstractEventLoop | None = None,
81
+ compression: COMPRESSION_T | None = None,
128
82
  ) -> Kover:
129
83
  """Create and return a new Kover client instance.
130
84
 
131
85
  Parameters:
132
- ----------
133
- host : str, optional
134
- The hostname of the MongoDB server, by default "127.0.0.1".
135
- port : int, optional
136
- The port number of the MongoDB server, by default 27017.
137
- credentials : AuthCredentials or None, optional
138
- Authentication credentials, if required.
139
- loop : asyncio.AbstractEventLoop or None, optional
140
- The event loop to use for asynchronous operations.
86
+ host : The hostname of the MongoDB server, by default "127.0.0.1".
87
+ port : The port number of the MongoDB server, by default 27017.
88
+ credentials : Authentication credentials, if required.
89
+ loop : The event loop to use for asynchronous operations.
141
90
 
142
91
  Returns:
143
- -------
144
- Kover
145
92
  An instance of the Kover client.
146
93
  """
147
- socket = await MongoSocket.make(host, port, loop=loop)
148
- hello = await socket.hello(credentials=credentials)
94
+ socket = await MongoSocket.make(host=host, port=port, loop=loop)
95
+ hello = await socket.hello(
96
+ credentials=credentials,
97
+ compression=compression,
98
+ )
149
99
  if hello.requires_auth and credentials:
150
100
  mechanism = random.choice(hello.sasl_supported_mechs or []) # noqa: S311
151
101
  signature = await Auth(socket).create(mechanism, credentials)
152
102
  else:
153
103
  signature = None
104
+ if hello.compression:
105
+ socket.set_compressor(hello.compression[0])
154
106
  return cls(socket, signature)
155
107
 
156
108
  async def refresh_sessions(self, sessions: list[Session]) -> None:
157
109
  """Refresh the provided list of sessions.
158
110
 
159
111
  Parameters:
160
- ----------
161
- sessions : list[Session]
162
- A list of Session objects to be refreshed.
112
+ sessions : A list of Session objects to be refreshed.
163
113
  """
164
114
  documents: list[xJsonT] = [x.document for x in sessions]
165
115
  await self.socket.request({"refreshSessions": documents})
@@ -168,9 +118,7 @@ class Kover:
168
118
  """End the provided list of sessions.
169
119
 
170
120
  Parameters:
171
- ----------
172
- sessions : list[Session]
173
- A list of Session objects to be ended.
121
+ sessions : A list of Session objects to be ended.
174
122
  """
175
123
  documents: list[xJsonT] = [x.document for x in sessions]
176
124
  await self.socket.request({"endSessions": documents})
@@ -179,8 +127,6 @@ class Kover:
179
127
  """Start a new session.
180
128
 
181
129
  Returns:
182
- -------
183
- Session
184
130
  An instance of the Session class representing the started session.
185
131
  """
186
132
  req = await self.socket.request({"startSession": 1.0})
@@ -190,36 +136,23 @@ class Kover:
190
136
  """Retrieve build information from the MongoDB server.
191
137
 
192
138
  Returns:
193
- -------
194
- BuildInfo
195
139
  An instance of BuildInfo containing server build details.
196
140
  """
197
141
  request = await self.socket.request({"buildInfo": 1.0})
198
- return BuildInfo(
199
- version=request["version"],
200
- git_version=request["gitVersion"],
201
- allocator=request["allocator"],
202
- javascript_engine=request["javascriptEngine"],
203
- version_array=request["versionArray"],
204
- openssl=request["openssl"]["running"],
205
- debug=request["debug"],
206
- max_bson_object_size=request["maxBsonObjectSize"],
207
- storage_engines=request["storageEngines"],
208
- )
142
+ return BuildInfo.model_validate(request)
209
143
 
210
144
  async def logout(self) -> None:
211
145
  """Log out the current user session.
212
146
 
213
- This method sends a logout request to the server to terminate the current authenticated session.
214
- """ # noqa: E501
147
+ This method sends a logout request to the server
148
+ to terminate the current authenticated session.
149
+ """
215
150
  await self.socket.request({"logout": 1.0})
216
151
 
217
152
  async def list_database_names(self) -> list[str]:
218
153
  """Retrieve the names of all databases on the MongoDB server.
219
154
 
220
155
  Returns:
221
- -------
222
- list[str]
223
156
  A list containing the names of all databases.
224
157
  """
225
158
  command: xJsonT = {
@@ -233,9 +166,7 @@ class Kover:
233
166
  """Drop the specified database from the MongoDB server.
234
167
 
235
168
  Parameters:
236
- ----------
237
- name : str
238
- The name of the database to drop.
169
+ name : The name of the database to drop.
239
170
  """
240
171
  await self.socket.request({"dropDatabase": 1.0}, db_name=name)
241
172
 
@@ -247,14 +178,8 @@ class Kover:
247
178
  """Initiate a replica set with the provided configuration.
248
179
 
249
180
  Parameters:
250
- ----------
251
- config : ReplicaSetConfig or None, optional
252
- The configuration document for the replica set. If None,
253
- default configuration is used.
254
-
255
- Returns:
256
- -------
257
- None
181
+ config : The configuration document for the replica set. If None,
182
+ default configuration is used.
258
183
  """
259
184
  document = maybe_to_dict(config) or {}
260
185
  await self.socket.request({"replSetInitiate": document})
@@ -269,13 +194,7 @@ class Kover:
269
194
  """Perform Reconfiguration of a replica set.
270
195
 
271
196
  Parameters:
272
- ----------
273
- config : ReplicaSetConfig
274
- The configuration document for the replica set.
275
-
276
- Returns:
277
- -------
278
- None
197
+ config : The configuration document for the replica set.
279
198
  """
280
199
  document: xJsonT = filter_non_null({
281
200
  "replSetReconfig": maybe_to_dict(config) or {},
@@ -289,8 +208,6 @@ class Kover:
289
208
  """Retrieve the status of the replica set.
290
209
 
291
210
  Returns:
292
- -------
293
- xJsonT
294
211
  A JSON document containing the replica set status information.
295
212
  """
296
213
  return await self.socket.request({"replSetGetStatus": 1.0})
@@ -305,17 +222,9 @@ class Kover:
305
222
  """Shut down the MongoDB server.
306
223
 
307
224
  Parameters:
308
- ----------
309
- force : bool, optional
310
- Whether to force the shutdown, by default False.
311
- timeout : int or None, optional
312
- Timeout in seconds before shutdown, by default None.
313
- comment : str or None, optional
314
- Optional comment for the shutdown command.
315
-
316
- Returns:
317
- -------
318
- None
225
+ force : Whether to force the shutdown, by default False.
226
+ timeout : Timeout in seconds before shutdown, by default None.
227
+ comment : Optional comment for the shutdown command.
319
228
  """
320
229
  command = filter_non_null({
321
230
  "shutdown": 1.0,
@@ -330,8 +239,6 @@ class Kover:
330
239
  """Retrieve the command line args used to start the MongoDB server.
331
240
 
332
241
  Returns:
333
- -------
334
- list[str]
335
242
  A list of command line arguments.
336
243
  """
337
244
  r = await self.socket.request({"getCmdLineOpts": 1.0})
@@ -345,13 +252,10 @@ class Kover:
345
252
  """Retrieve log entries from the MongoDB server.
346
253
 
347
254
  Parameters:
348
- ----------
349
- parameter : Literal["global", "startupWarnings"], optional
350
- The log type to retrieve, defaults to "startupWarnings".
255
+ parameter : The log type to retrieve,
256
+ defaults to "startupWarnings".
351
257
 
352
258
  Returns:
353
- -------
354
- list[xJsonT]
355
259
  A list of log entries as JSON objects.
356
260
  """
357
261
  r = await self.socket.request({"getLog": parameter})
@@ -370,20 +274,12 @@ class Kover:
370
274
  """Rename a collection in the MongoDB server.
371
275
 
372
276
  Parameters:
373
- ----------
374
- target : str
375
- The full name of the source collection to rename.
376
- new_name : str
377
- The new name for the collection.
378
- drop_target : bool, optional
379
- Whether to drop the target collection if it exists, by default False.
380
- comment : str or None, optional
381
- Optional comment for the rename operation.
382
-
383
- Returns:
384
- -------
385
- None
386
- """ # noqa: E501
277
+ target : The full name of the source collection to rename.
278
+ new_name : The new name for the collection.
279
+ drop_target : Whether to drop the target collection if it exists,
280
+ by default False.
281
+ comment : Optional comment for the rename operation.
282
+ """
387
283
  command = filter_non_null({
388
284
  "renameCollection": target,
389
285
  "to": new_name,
@@ -397,14 +293,9 @@ class Kover:
397
293
  """Set the user write block mode on the MongoDB server.
398
294
 
399
295
  Parameters:
400
- ----------
401
- param : bool
402
- Blocks writes on a cluster when set to true. To enable writes on a cluster, set global: false.
403
-
404
- Returns:
405
- -------
406
- None
407
- """ # noqa: E501
296
+ param : Blocks writes on a cluster when set to true.
297
+ To enable writes on a cluster, set global: false.
298
+ """
408
299
  await self.socket.request({
409
300
  "setUserWriteBlockMode": 1.0,
410
301
  "global": param,
@@ -420,18 +311,12 @@ class Kover:
420
311
  """Flush all pending writes to disk and optionally lock the database.
421
312
 
422
313
  Parameters:
423
- ----------
424
- timeout : int, optional
425
- Timeout in milliseconds for acquiring the fsync lock, by default 90000.
426
- lock : bool, optional
427
- Whether to lock the database after flushing, by default True.
428
- comment : str or None, optional
429
- Optional comment for the fsync operation.
430
-
431
- Returns:
432
- -------
433
- None
434
- """ # noqa: E501
314
+ timeout : Timeout in milliseconds for acquiring the
315
+ fsync lock, by default 90000.
316
+ lock : Whether to lock the database after flushing,
317
+ by default True.
318
+ comment : Optional comment for the fsync operation.
319
+ """
435
320
  command = filter_non_null({
436
321
  "fsync": 1.0,
437
322
  "fsyncLockAcquisitionTimeoutMillis": timeout,
@@ -445,13 +330,7 @@ class Kover:
445
330
  """Unlock the database after a previous fsync lock operation.
446
331
 
447
332
  Parameters:
448
- ----------
449
- comment : str or None, optional
450
- Optional comment for the fsync unlock operation.
451
-
452
- Returns:
453
- -------
454
- None
333
+ comment : Optional comment for the fsync unlock operation.
455
334
  """
456
335
  command = filter_non_null({
457
336
  "fsyncUnlock": 1.0,