matrixone-python-sdk 0.1.0__py3-none-any.whl

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 (122) hide show
  1. matrixone/__init__.py +155 -0
  2. matrixone/account.py +723 -0
  3. matrixone/async_client.py +3913 -0
  4. matrixone/async_metadata_manager.py +311 -0
  5. matrixone/async_orm.py +123 -0
  6. matrixone/async_vector_index_manager.py +633 -0
  7. matrixone/base_client.py +208 -0
  8. matrixone/client.py +4672 -0
  9. matrixone/config.py +452 -0
  10. matrixone/connection_hooks.py +286 -0
  11. matrixone/exceptions.py +89 -0
  12. matrixone/logger.py +782 -0
  13. matrixone/metadata.py +820 -0
  14. matrixone/moctl.py +219 -0
  15. matrixone/orm.py +2277 -0
  16. matrixone/pitr.py +646 -0
  17. matrixone/pubsub.py +771 -0
  18. matrixone/restore.py +411 -0
  19. matrixone/search_vector_index.py +1176 -0
  20. matrixone/snapshot.py +550 -0
  21. matrixone/sql_builder.py +844 -0
  22. matrixone/sqlalchemy_ext/__init__.py +161 -0
  23. matrixone/sqlalchemy_ext/adapters.py +163 -0
  24. matrixone/sqlalchemy_ext/dialect.py +534 -0
  25. matrixone/sqlalchemy_ext/fulltext_index.py +895 -0
  26. matrixone/sqlalchemy_ext/fulltext_search.py +1686 -0
  27. matrixone/sqlalchemy_ext/hnsw_config.py +194 -0
  28. matrixone/sqlalchemy_ext/ivf_config.py +252 -0
  29. matrixone/sqlalchemy_ext/table_builder.py +351 -0
  30. matrixone/sqlalchemy_ext/vector_index.py +1721 -0
  31. matrixone/sqlalchemy_ext/vector_type.py +948 -0
  32. matrixone/version.py +580 -0
  33. matrixone_python_sdk-0.1.0.dist-info/METADATA +706 -0
  34. matrixone_python_sdk-0.1.0.dist-info/RECORD +122 -0
  35. matrixone_python_sdk-0.1.0.dist-info/WHEEL +5 -0
  36. matrixone_python_sdk-0.1.0.dist-info/entry_points.txt +5 -0
  37. matrixone_python_sdk-0.1.0.dist-info/licenses/LICENSE +200 -0
  38. matrixone_python_sdk-0.1.0.dist-info/top_level.txt +2 -0
  39. tests/__init__.py +19 -0
  40. tests/offline/__init__.py +20 -0
  41. tests/offline/conftest.py +77 -0
  42. tests/offline/test_account.py +703 -0
  43. tests/offline/test_async_client_query_comprehensive.py +1218 -0
  44. tests/offline/test_basic.py +54 -0
  45. tests/offline/test_case_sensitivity.py +227 -0
  46. tests/offline/test_connection_hooks_offline.py +287 -0
  47. tests/offline/test_dialect_schema_handling.py +609 -0
  48. tests/offline/test_explain_methods.py +346 -0
  49. tests/offline/test_filter_logical_in.py +237 -0
  50. tests/offline/test_fulltext_search_comprehensive.py +795 -0
  51. tests/offline/test_ivf_config.py +249 -0
  52. tests/offline/test_join_methods.py +281 -0
  53. tests/offline/test_join_sqlalchemy_compatibility.py +276 -0
  54. tests/offline/test_logical_in_method.py +237 -0
  55. tests/offline/test_matrixone_version_parsing.py +264 -0
  56. tests/offline/test_metadata_offline.py +557 -0
  57. tests/offline/test_moctl.py +300 -0
  58. tests/offline/test_moctl_simple.py +251 -0
  59. tests/offline/test_model_support_offline.py +359 -0
  60. tests/offline/test_model_support_simple.py +225 -0
  61. tests/offline/test_pinecone_filter_offline.py +377 -0
  62. tests/offline/test_pitr.py +585 -0
  63. tests/offline/test_pubsub.py +712 -0
  64. tests/offline/test_query_update.py +283 -0
  65. tests/offline/test_restore.py +445 -0
  66. tests/offline/test_snapshot_comprehensive.py +384 -0
  67. tests/offline/test_sql_escaping_edge_cases.py +551 -0
  68. tests/offline/test_sqlalchemy_integration.py +382 -0
  69. tests/offline/test_sqlalchemy_vector_integration.py +434 -0
  70. tests/offline/test_table_builder.py +198 -0
  71. tests/offline/test_unified_filter.py +398 -0
  72. tests/offline/test_unified_transaction.py +495 -0
  73. tests/offline/test_vector_index.py +238 -0
  74. tests/offline/test_vector_operations.py +688 -0
  75. tests/offline/test_vector_type.py +174 -0
  76. tests/offline/test_version_core.py +328 -0
  77. tests/offline/test_version_management.py +372 -0
  78. tests/offline/test_version_standalone.py +652 -0
  79. tests/online/__init__.py +20 -0
  80. tests/online/conftest.py +216 -0
  81. tests/online/test_account_management.py +194 -0
  82. tests/online/test_advanced_features.py +344 -0
  83. tests/online/test_async_client_interfaces.py +330 -0
  84. tests/online/test_async_client_online.py +285 -0
  85. tests/online/test_async_model_insert_online.py +293 -0
  86. tests/online/test_async_orm_online.py +300 -0
  87. tests/online/test_async_simple_query_online.py +802 -0
  88. tests/online/test_async_transaction_simple_query.py +300 -0
  89. tests/online/test_basic_connection.py +130 -0
  90. tests/online/test_client_online.py +238 -0
  91. tests/online/test_config.py +90 -0
  92. tests/online/test_config_validation.py +123 -0
  93. tests/online/test_connection_hooks_new_online.py +217 -0
  94. tests/online/test_dialect_schema_handling_online.py +331 -0
  95. tests/online/test_filter_logical_in_online.py +374 -0
  96. tests/online/test_fulltext_comprehensive.py +1773 -0
  97. tests/online/test_fulltext_label_online.py +433 -0
  98. tests/online/test_fulltext_search_online.py +842 -0
  99. tests/online/test_ivf_stats_online.py +506 -0
  100. tests/online/test_logger_integration.py +311 -0
  101. tests/online/test_matrixone_query_orm.py +540 -0
  102. tests/online/test_metadata_online.py +579 -0
  103. tests/online/test_model_insert_online.py +255 -0
  104. tests/online/test_mysql_driver_validation.py +213 -0
  105. tests/online/test_orm_advanced_features.py +2022 -0
  106. tests/online/test_orm_cte_integration.py +269 -0
  107. tests/online/test_orm_online.py +270 -0
  108. tests/online/test_pinecone_filter.py +708 -0
  109. tests/online/test_pubsub_operations.py +352 -0
  110. tests/online/test_query_methods.py +225 -0
  111. tests/online/test_query_update_online.py +433 -0
  112. tests/online/test_search_vector_index.py +557 -0
  113. tests/online/test_simple_fulltext_online.py +915 -0
  114. tests/online/test_snapshot_comprehensive.py +998 -0
  115. tests/online/test_sqlalchemy_engine_integration.py +336 -0
  116. tests/online/test_sqlalchemy_integration.py +425 -0
  117. tests/online/test_transaction_contexts.py +1219 -0
  118. tests/online/test_transaction_insert_methods.py +356 -0
  119. tests/online/test_transaction_query_methods.py +288 -0
  120. tests/online/test_unified_filter_online.py +529 -0
  121. tests/online/test_vector_comprehensive.py +706 -0
  122. tests/online/test_version_management.py +291 -0
matrixone/config.py ADDED
@@ -0,0 +1,452 @@
1
+ # Copyright 2021 - 2022 Matrix Origin
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """
16
+ MatrixOne Configuration Management
17
+
18
+ This module provides comprehensive configuration management for MatrixOne connections,
19
+ allowing users to override default connection parameters via environment variables,
20
+ configuration files, or direct parameter overrides.
21
+
22
+ Features:
23
+
24
+ - Default connection parameters with sensible defaults
25
+ - Environment variable overrides for all connection parameters
26
+ - Support for connection hooks via on_connect parameter
27
+ - Multiple configuration retrieval methods (tuple, dict, kwargs)
28
+ - Configuration debugging and validation
29
+
30
+ Usage Examples::
31
+
32
+ from matrixone.config import get_connection_kwargs, print_config
33
+ from matrixone.connection_hooks import ConnectionAction
34
+ from matrixone import Client
35
+
36
+ # Basic Configuration
37
+ config = get_connection_kwargs()
38
+ print_config()
39
+
40
+ # Parameter Overrides
41
+ config = get_connection_kwargs(
42
+ host="production-server",
43
+ port=6002,
44
+ on_connect=[ConnectionAction.ENABLE_FULLTEXT]
45
+ )
46
+
47
+ # Using with Client
48
+ client = Client()
49
+ client.connect(**config)
50
+
51
+ Environment Variables:
52
+
53
+ - MATRIXONE_HOST: Database host (default: 127.0.0.1)
54
+ - MATRIXONE_PORT: Database port (default: 6001)
55
+ - MATRIXONE_USER: Database user (default: root)
56
+ - MATRIXONE_PASSWORD: Database password (default: 111)
57
+ - MATRIXONE_DATABASE: Database name (default: test)
58
+ - MATRIXONE_CHARSET: Character set (default: utf8mb4)
59
+ - MATRIXONE_CONNECT_TIMEOUT: Connection timeout in seconds (default: 30)
60
+ - MATRIXONE_AUTOCOMMIT: Enable autocommit (default: True)
61
+ - MATRIXONE_ON_CONNECT: Connection hooks (comma-separated list)
62
+
63
+ Connection Hooks:
64
+
65
+ The on_connect parameter supports:
66
+
67
+ - Predefined actions: enable_all, enable_ivf, enable_hnsw, enable_fulltext, enable_vector
68
+ - Custom callback functions
69
+ - Mixed actions and callbacks
70
+
71
+ Example on_connect values: "enable_all", "enable_ivf,enable_hnsw", or custom function
72
+ """
73
+
74
+ import os
75
+ from typing import Any, Dict
76
+
77
+
78
+ class MatrixOneConfig:
79
+ """
80
+ MatrixOne connection configuration manager.
81
+
82
+ This class provides centralized configuration management for MatrixOne connections,
83
+ supporting environment variable overrides, parameter validation, and multiple
84
+ output formats for different use cases.
85
+
86
+ Attributes::
87
+
88
+ DEFAULT_CONFIG (Dict[str, Any]): Default connection parameters
89
+ ENV_MAPPING (Dict[str, str]): Mapping of parameters to environment variables
90
+
91
+ Example::
92
+
93
+ # Get configuration with environment overrides
94
+ config = MatrixOneConfig.get_config()
95
+
96
+ # Get connection parameters as tuple
97
+ host, port, user, password, database = MatrixOneConfig.get_connection_params()
98
+
99
+ # Get connection parameters as keyword arguments
100
+ kwargs = MatrixOneConfig.get_connection_kwargs()
101
+
102
+ # Print current configuration
103
+ MatrixOneConfig.print_config()
104
+
105
+ """
106
+
107
+ # Default connection parameters
108
+ DEFAULT_CONFIG = {
109
+ "host": "127.0.0.1",
110
+ "port": 6001,
111
+ "user": "root",
112
+ "password": "111",
113
+ "database": "test",
114
+ "charset": "utf8mb4",
115
+ "connect_timeout": 30,
116
+ "autocommit": True,
117
+ "on_connect": None,
118
+ }
119
+
120
+ # Environment variable mapping
121
+ ENV_MAPPING = {
122
+ "host": "MATRIXONE_HOST",
123
+ "port": "MATRIXONE_PORT",
124
+ "user": "MATRIXONE_USER",
125
+ "password": "MATRIXONE_PASSWORD",
126
+ "database": "MATRIXONE_DATABASE",
127
+ "charset": "MATRIXONE_CHARSET",
128
+ "connect_timeout": "MATRIXONE_CONNECT_TIMEOUT",
129
+ "autocommit": "MATRIXONE_AUTOCOMMIT",
130
+ "on_connect": "MATRIXONE_ON_CONNECT",
131
+ }
132
+
133
+ @classmethod
134
+ def get_config(cls, **overrides) -> Dict[str, Any]:
135
+ """
136
+ Get connection configuration with environment variable overrides.
137
+
138
+ This method retrieves the complete configuration dictionary, applying
139
+ environment variable overrides and direct parameter overrides in order:
140
+ 1. Default configuration
141
+ 2. Environment variable overrides
142
+ 3. Direct parameter overrides
143
+
144
+ Args::
145
+
146
+ **overrides: Additional parameter overrides. These take precedence
147
+ over environment variables and defaults.
148
+
149
+ Returns::
150
+
151
+ Dict[str, Any]: Complete configuration dictionary containing:
152
+ - host (str): Database host
153
+ - port (int): Database port
154
+ - user (str): Database user
155
+ - password (str): Database password
156
+ - database (str): Database name
157
+ - charset (str): Character set
158
+ - connect_timeout (int): Connection timeout in seconds
159
+ - autocommit (bool): Enable autocommit
160
+ - on_connect (Any): Connection hooks configuration
161
+
162
+ Example::
163
+
164
+ # Get default configuration
165
+ config = MatrixOneConfig.get_config()
166
+
167
+ # Override specific parameters
168
+ config = MatrixOneConfig.get_config(
169
+ host="production-server",
170
+ port=6002,
171
+ on_connect=[ConnectionAction.ENABLE_ALL]
172
+ )
173
+ """
174
+ config = cls.DEFAULT_CONFIG.copy()
175
+
176
+ # Apply environment variable overrides
177
+ for param, env_var in cls.ENV_MAPPING.items():
178
+ env_value = os.getenv(env_var)
179
+ if env_value is not None:
180
+ # Convert types based on parameter
181
+ if param == "port":
182
+ config[param] = int(env_value)
183
+ elif param == "connect_timeout":
184
+ config[param] = int(env_value)
185
+ elif param == "autocommit":
186
+ config[param] = env_value.lower() in ("true", "1", "yes", "on")
187
+ else:
188
+ config[param] = env_value
189
+
190
+ # Apply direct overrides
191
+ config.update(overrides)
192
+
193
+ return config
194
+
195
+ @classmethod
196
+ def get_connection_params(cls, **overrides) -> tuple:
197
+ """
198
+ Get connection parameters as tuple for easy unpacking.
199
+
200
+ This method returns the core connection parameters as a tuple,
201
+ which is useful for direct unpacking into function calls.
202
+
203
+ Args::
204
+
205
+ **overrides: Additional parameter overrides
206
+
207
+ Returns::
208
+
209
+ Tuple[str, int, str, str, str]: Tuple containing (host, port, user, password, database)
210
+
211
+ Example::
212
+
213
+ # Unpack parameters directly
214
+ host, port, user, password, database = MatrixOneConfig.get_connection_params()
215
+
216
+ # Use with legacy connection methods
217
+ connection = create_connection(*MatrixOneConfig.get_connection_params())
218
+ """
219
+ config = cls.get_config(**overrides)
220
+ return (
221
+ config["host"],
222
+ config["port"],
223
+ config["user"],
224
+ config["password"],
225
+ config["database"],
226
+ )
227
+
228
+ @classmethod
229
+ def get_connection_kwargs(cls, **overrides) -> Dict[str, Any]:
230
+ """
231
+ Get connection parameters as keyword arguments.
232
+
233
+ This method returns all connection parameters as a dictionary,
234
+ including extended parameters like charset, timeout, and connection hooks.
235
+ This is the most comprehensive configuration method.
236
+
237
+ Args::
238
+
239
+ **overrides: Additional parameter overrides
240
+
241
+ Returns::
242
+
243
+ Dict[str, Any]: Complete connection parameters dictionary
244
+
245
+ Example::
246
+
247
+ from matrixone import Client
248
+ from matrixone.connection_hooks import ConnectionAction
249
+
250
+ # Get complete configuration and use directly with Client constructor
251
+ client = Client(**MatrixOneConfig.get_connection_kwargs(
252
+ on_connect=[ConnectionAction.ENABLE_ALL]
253
+ ))
254
+
255
+ # Or use with connect method
256
+ config = MatrixOneConfig.get_connection_kwargs()
257
+ client = Client()
258
+ client.connect(
259
+ host=config['host'],
260
+ port=config['port'],
261
+ user=config['user'],
262
+ password=config['password'],
263
+ database=config['database'],
264
+ charset=config['charset'],
265
+ on_connect=config['on_connect']
266
+ )
267
+ """
268
+ config = cls.get_config(**overrides)
269
+ return {
270
+ "host": config["host"],
271
+ "port": config["port"],
272
+ "user": config["user"],
273
+ "password": config["password"],
274
+ "database": config["database"],
275
+ "charset": config["charset"],
276
+ "connection_timeout": config["connect_timeout"],
277
+ "auto_commit": config["autocommit"],
278
+ "on_connect": config["on_connect"],
279
+ }
280
+
281
+ @classmethod
282
+ def print_config(cls, **overrides):
283
+ """
284
+ Print current configuration for debugging and validation.
285
+
286
+ This method displays the current configuration in a formatted way,
287
+ showing all parameters with their current values. Sensitive information
288
+ like passwords are masked for security.
289
+
290
+ Args::
291
+
292
+ **overrides: Additional parameter overrides to apply before printing
293
+
294
+ Example::
295
+
296
+ # Print default configuration
297
+ MatrixOneConfig.print_config()
298
+
299
+ # Print configuration with overrides
300
+ MatrixOneConfig.print_config(host="production-server", port=6002)
301
+
302
+ Note: Prints formatted configuration to stdout.
303
+ """
304
+ config = cls.get_config(**overrides)
305
+ print("MatrixOne Connection Configuration:")
306
+ print("=" * 40)
307
+ for key, value in config.items():
308
+ if key == "password":
309
+ print(f" {key}: {'*' * len(str(value))}")
310
+ elif key == "on_connect":
311
+ if value is None:
312
+ print(f" {key}: None")
313
+ else:
314
+ print(f" {key}: {type(value).__name__}")
315
+ else:
316
+ print(f" {key}: {value}")
317
+ print("=" * 40)
318
+
319
+
320
+ # Convenience functions
321
+ def get_config(**overrides) -> Dict[str, Any]:
322
+ """
323
+ Get MatrixOne connection configuration.
324
+
325
+ Convenience function for MatrixOneConfig.get_config().
326
+
327
+ Args::
328
+
329
+ **overrides: Additional parameter overrides
330
+
331
+ Returns::
332
+
333
+ Dict[str, Any]: Complete configuration dictionary
334
+
335
+ Example::
336
+
337
+ from matrixone.config import get_config
338
+
339
+ config = get_config(host="production-server")
340
+
341
+ """
342
+ return MatrixOneConfig.get_config(**overrides)
343
+
344
+
345
+ def get_connection_params(**overrides) -> tuple:
346
+ """
347
+ Get MatrixOne connection parameters as tuple.
348
+
349
+ Convenience function for MatrixOneConfig.get_connection_params().
350
+
351
+ Args::
352
+
353
+ **overrides: Additional parameter overrides
354
+
355
+ Returns::
356
+
357
+ Tuple[str, int, str, str, str]: Connection parameters tuple
358
+
359
+ Example::
360
+
361
+ from matrixone.config import get_connection_params
362
+
363
+ host, port, user, password, database = get_connection_params()
364
+
365
+ """
366
+ return MatrixOneConfig.get_connection_params(**overrides)
367
+
368
+
369
+ def get_connection_kwargs(**overrides) -> Dict[str, Any]:
370
+ """
371
+ Get MatrixOne connection parameters as keyword arguments.
372
+
373
+ Convenience function for MatrixOneConfig.get_connection_kwargs().
374
+ This is the most commonly used function for getting complete configuration.
375
+
376
+ Args::
377
+
378
+ **overrides: Additional parameter overrides
379
+
380
+ Returns::
381
+
382
+ Dict[str, Any]: Complete connection parameters dictionary
383
+
384
+ Example::
385
+
386
+ from matrixone.config import get_connection_kwargs
387
+ from matrixone.connection_hooks import ConnectionAction
388
+
389
+ config = get_connection_kwargs(on_connect=[ConnectionAction.ENABLE_ALL])
390
+
391
+ """
392
+ return MatrixOneConfig.get_connection_kwargs(**overrides)
393
+
394
+
395
+ def get_client_kwargs(**overrides) -> Dict[str, Any]:
396
+ """
397
+ Get connection parameters suitable for Client constructor.
398
+
399
+ This method returns connection parameters that can be directly passed
400
+ to the Client() constructor, excluding parameters that are only used
401
+ by the connect() method.
402
+
403
+ Args::
404
+
405
+ **overrides: Additional parameter overrides
406
+
407
+ Returns::
408
+
409
+ Dict[str, Any]: Client constructor parameters dictionary
410
+
411
+ Example::
412
+
413
+ from matrixone import Client
414
+ from matrixone.config import get_client_kwargs
415
+
416
+ # Create client with all configuration in one line
417
+ client = Client(**get_client_kwargs())
418
+
419
+ # Or with overrides
420
+ client = Client(**get_client_kwargs(host="production-server"))
421
+ """
422
+ config = MatrixOneConfig.get_config(**overrides)
423
+ return {
424
+ "host": config["host"],
425
+ "port": config["port"],
426
+ "user": config["user"],
427
+ "password": config["password"],
428
+ "database": config["database"],
429
+ "charset": config["charset"],
430
+ "connection_timeout": config["connect_timeout"],
431
+ "auto_commit": config["autocommit"],
432
+ }
433
+
434
+
435
+ def print_config(**overrides):
436
+ """
437
+ Print current MatrixOne configuration.
438
+
439
+ Convenience function for MatrixOneConfig.print_config().
440
+
441
+ Args::
442
+
443
+ **overrides: Additional parameter overrides to apply before printing
444
+
445
+ Example::
446
+
447
+ from matrixone.config import print_config
448
+
449
+ print_config() # Print current configuration
450
+
451
+ """
452
+ MatrixOneConfig.print_config(**overrides)