kailash 0.3.2__py3-none-any.whl → 0.4.1__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 (151) hide show
  1. kailash/__init__.py +33 -1
  2. kailash/access_control/__init__.py +129 -0
  3. kailash/access_control/managers.py +461 -0
  4. kailash/access_control/rule_evaluators.py +467 -0
  5. kailash/access_control_abac.py +825 -0
  6. kailash/config/__init__.py +27 -0
  7. kailash/config/database_config.py +359 -0
  8. kailash/database/__init__.py +28 -0
  9. kailash/database/execution_pipeline.py +499 -0
  10. kailash/middleware/__init__.py +306 -0
  11. kailash/middleware/auth/__init__.py +33 -0
  12. kailash/middleware/auth/access_control.py +436 -0
  13. kailash/middleware/auth/auth_manager.py +422 -0
  14. kailash/middleware/auth/jwt_auth.py +477 -0
  15. kailash/middleware/auth/kailash_jwt_auth.py +616 -0
  16. kailash/middleware/communication/__init__.py +37 -0
  17. kailash/middleware/communication/ai_chat.py +989 -0
  18. kailash/middleware/communication/api_gateway.py +802 -0
  19. kailash/middleware/communication/events.py +470 -0
  20. kailash/middleware/communication/realtime.py +710 -0
  21. kailash/middleware/core/__init__.py +21 -0
  22. kailash/middleware/core/agent_ui.py +890 -0
  23. kailash/middleware/core/schema.py +643 -0
  24. kailash/middleware/core/workflows.py +396 -0
  25. kailash/middleware/database/__init__.py +63 -0
  26. kailash/middleware/database/base.py +113 -0
  27. kailash/middleware/database/base_models.py +525 -0
  28. kailash/middleware/database/enums.py +106 -0
  29. kailash/middleware/database/migrations.py +12 -0
  30. kailash/{api/database.py → middleware/database/models.py} +183 -291
  31. kailash/middleware/database/repositories.py +685 -0
  32. kailash/middleware/database/session_manager.py +19 -0
  33. kailash/middleware/mcp/__init__.py +38 -0
  34. kailash/middleware/mcp/client_integration.py +585 -0
  35. kailash/middleware/mcp/enhanced_server.py +576 -0
  36. kailash/nodes/__init__.py +27 -3
  37. kailash/nodes/admin/__init__.py +42 -0
  38. kailash/nodes/admin/audit_log.py +794 -0
  39. kailash/nodes/admin/permission_check.py +864 -0
  40. kailash/nodes/admin/role_management.py +823 -0
  41. kailash/nodes/admin/security_event.py +1523 -0
  42. kailash/nodes/admin/user_management.py +944 -0
  43. kailash/nodes/ai/a2a.py +24 -7
  44. kailash/nodes/ai/ai_providers.py +248 -40
  45. kailash/nodes/ai/embedding_generator.py +11 -11
  46. kailash/nodes/ai/intelligent_agent_orchestrator.py +99 -11
  47. kailash/nodes/ai/llm_agent.py +436 -5
  48. kailash/nodes/ai/self_organizing.py +85 -10
  49. kailash/nodes/ai/vision_utils.py +148 -0
  50. kailash/nodes/alerts/__init__.py +26 -0
  51. kailash/nodes/alerts/base.py +234 -0
  52. kailash/nodes/alerts/discord.py +499 -0
  53. kailash/nodes/api/auth.py +287 -6
  54. kailash/nodes/api/rest.py +151 -0
  55. kailash/nodes/auth/__init__.py +17 -0
  56. kailash/nodes/auth/directory_integration.py +1228 -0
  57. kailash/nodes/auth/enterprise_auth_provider.py +1328 -0
  58. kailash/nodes/auth/mfa.py +2338 -0
  59. kailash/nodes/auth/risk_assessment.py +872 -0
  60. kailash/nodes/auth/session_management.py +1093 -0
  61. kailash/nodes/auth/sso.py +1040 -0
  62. kailash/nodes/base.py +344 -13
  63. kailash/nodes/base_cycle_aware.py +4 -2
  64. kailash/nodes/base_with_acl.py +1 -1
  65. kailash/nodes/code/python.py +283 -10
  66. kailash/nodes/compliance/__init__.py +9 -0
  67. kailash/nodes/compliance/data_retention.py +1888 -0
  68. kailash/nodes/compliance/gdpr.py +2004 -0
  69. kailash/nodes/data/__init__.py +22 -2
  70. kailash/nodes/data/async_connection.py +469 -0
  71. kailash/nodes/data/async_sql.py +757 -0
  72. kailash/nodes/data/async_vector.py +598 -0
  73. kailash/nodes/data/readers.py +767 -0
  74. kailash/nodes/data/retrieval.py +360 -1
  75. kailash/nodes/data/sharepoint_graph.py +397 -21
  76. kailash/nodes/data/sql.py +94 -5
  77. kailash/nodes/data/streaming.py +68 -8
  78. kailash/nodes/data/vector_db.py +54 -4
  79. kailash/nodes/enterprise/__init__.py +13 -0
  80. kailash/nodes/enterprise/batch_processor.py +741 -0
  81. kailash/nodes/enterprise/data_lineage.py +497 -0
  82. kailash/nodes/logic/convergence.py +31 -9
  83. kailash/nodes/logic/operations.py +14 -3
  84. kailash/nodes/mixins/__init__.py +8 -0
  85. kailash/nodes/mixins/event_emitter.py +201 -0
  86. kailash/nodes/mixins/mcp.py +9 -4
  87. kailash/nodes/mixins/security.py +165 -0
  88. kailash/nodes/monitoring/__init__.py +7 -0
  89. kailash/nodes/monitoring/performance_benchmark.py +2497 -0
  90. kailash/nodes/rag/__init__.py +284 -0
  91. kailash/nodes/rag/advanced.py +1615 -0
  92. kailash/nodes/rag/agentic.py +773 -0
  93. kailash/nodes/rag/conversational.py +999 -0
  94. kailash/nodes/rag/evaluation.py +875 -0
  95. kailash/nodes/rag/federated.py +1188 -0
  96. kailash/nodes/rag/graph.py +721 -0
  97. kailash/nodes/rag/multimodal.py +671 -0
  98. kailash/nodes/rag/optimized.py +933 -0
  99. kailash/nodes/rag/privacy.py +1059 -0
  100. kailash/nodes/rag/query_processing.py +1335 -0
  101. kailash/nodes/rag/realtime.py +764 -0
  102. kailash/nodes/rag/registry.py +547 -0
  103. kailash/nodes/rag/router.py +837 -0
  104. kailash/nodes/rag/similarity.py +1854 -0
  105. kailash/nodes/rag/strategies.py +566 -0
  106. kailash/nodes/rag/workflows.py +575 -0
  107. kailash/nodes/security/__init__.py +19 -0
  108. kailash/nodes/security/abac_evaluator.py +1411 -0
  109. kailash/nodes/security/audit_log.py +103 -0
  110. kailash/nodes/security/behavior_analysis.py +1893 -0
  111. kailash/nodes/security/credential_manager.py +401 -0
  112. kailash/nodes/security/rotating_credentials.py +760 -0
  113. kailash/nodes/security/security_event.py +133 -0
  114. kailash/nodes/security/threat_detection.py +1103 -0
  115. kailash/nodes/testing/__init__.py +9 -0
  116. kailash/nodes/testing/credential_testing.py +499 -0
  117. kailash/nodes/transform/__init__.py +10 -2
  118. kailash/nodes/transform/chunkers.py +592 -1
  119. kailash/nodes/transform/processors.py +484 -14
  120. kailash/nodes/validation.py +321 -0
  121. kailash/runtime/access_controlled.py +1 -1
  122. kailash/runtime/async_local.py +41 -7
  123. kailash/runtime/docker.py +1 -1
  124. kailash/runtime/local.py +474 -55
  125. kailash/runtime/parallel.py +1 -1
  126. kailash/runtime/parallel_cyclic.py +1 -1
  127. kailash/runtime/testing.py +210 -2
  128. kailash/security.py +1 -1
  129. kailash/utils/migrations/__init__.py +25 -0
  130. kailash/utils/migrations/generator.py +433 -0
  131. kailash/utils/migrations/models.py +231 -0
  132. kailash/utils/migrations/runner.py +489 -0
  133. kailash/utils/secure_logging.py +342 -0
  134. kailash/workflow/__init__.py +16 -0
  135. kailash/workflow/cyclic_runner.py +3 -4
  136. kailash/workflow/graph.py +70 -2
  137. kailash/workflow/resilience.py +249 -0
  138. kailash/workflow/templates.py +726 -0
  139. {kailash-0.3.2.dist-info → kailash-0.4.1.dist-info}/METADATA +256 -20
  140. kailash-0.4.1.dist-info/RECORD +227 -0
  141. kailash/api/__init__.py +0 -17
  142. kailash/api/__main__.py +0 -6
  143. kailash/api/studio_secure.py +0 -893
  144. kailash/mcp/__main__.py +0 -13
  145. kailash/mcp/server_new.py +0 -336
  146. kailash/mcp/servers/__init__.py +0 -12
  147. kailash-0.3.2.dist-info/RECORD +0 -136
  148. {kailash-0.3.2.dist-info → kailash-0.4.1.dist-info}/WHEEL +0 -0
  149. {kailash-0.3.2.dist-info → kailash-0.4.1.dist-info}/entry_points.txt +0 -0
  150. {kailash-0.3.2.dist-info → kailash-0.4.1.dist-info}/licenses/LICENSE +0 -0
  151. {kailash-0.3.2.dist-info → kailash-0.4.1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,27 @@
1
+ """Configuration objects for the Kailash SDK.
2
+
3
+ This module provides typed, validated configuration objects that
4
+ replace scattered parameters with clean, structured configuration.
5
+ """
6
+
7
+ from kailash.config.database_config import (
8
+ AsyncDatabaseConfig,
9
+ AsyncDatabaseConfigBuilder,
10
+ DatabaseConfig,
11
+ DatabaseConfigBuilder,
12
+ PoolConfig,
13
+ SecurityConfig,
14
+ ValidationConfig,
15
+ VectorDatabaseConfig,
16
+ )
17
+
18
+ __all__ = [
19
+ "PoolConfig",
20
+ "SecurityConfig",
21
+ "ValidationConfig",
22
+ "DatabaseConfig",
23
+ "AsyncDatabaseConfig",
24
+ "VectorDatabaseConfig",
25
+ "DatabaseConfigBuilder",
26
+ "AsyncDatabaseConfigBuilder",
27
+ ]
@@ -0,0 +1,359 @@
1
+ """Typed configuration objects for database and security settings.
2
+
3
+ This module provides clean, typed configuration objects that replace
4
+ scattered parameters with structured, validated configuration.
5
+ """
6
+
7
+ import logging
8
+ from dataclasses import dataclass, field
9
+ from typing import Any, Dict, List, Optional, Union
10
+
11
+ logger = logging.getLogger(__name__)
12
+
13
+
14
+ @dataclass
15
+ class PoolConfig:
16
+ """Database connection pool configuration."""
17
+
18
+ pool_size: int = 5
19
+ max_overflow: int = 10
20
+ pool_timeout: int = 30
21
+ pool_recycle: int = 3600
22
+ pool_pre_ping: bool = True
23
+
24
+ def __post_init__(self):
25
+ """Validate pool configuration."""
26
+ if self.pool_size < 1:
27
+ raise ValueError("pool_size must be at least 1")
28
+ if self.max_overflow < 0:
29
+ raise ValueError("max_overflow cannot be negative")
30
+ if self.pool_timeout < 1:
31
+ raise ValueError("pool_timeout must be at least 1 second")
32
+
33
+
34
+ @dataclass
35
+ class SecurityConfig:
36
+ """Security and access control configuration."""
37
+
38
+ access_control_manager: Optional[Any] = None
39
+ masking_rules: Dict[str, Any] = field(default_factory=dict)
40
+ audit_enabled: bool = True
41
+ encryption_enabled: bool = False
42
+ ssl_config: Optional[Dict[str, Any]] = None
43
+
44
+ def __post_init__(self):
45
+ """Validate security configuration."""
46
+ if self.encryption_enabled and not self.ssl_config:
47
+ logger.warning("Encryption enabled but no SSL configuration provided")
48
+
49
+
50
+ @dataclass
51
+ class ValidationConfig:
52
+ """Query validation configuration."""
53
+
54
+ enabled: bool = True
55
+ dangerous_keywords_blocked: bool = True
56
+ custom_validators: List[Any] = field(default_factory=list)
57
+ sql_injection_check: bool = True
58
+ max_query_length: int = 100000
59
+
60
+ def __post_init__(self):
61
+ """Validate validation configuration."""
62
+ if self.max_query_length < 1:
63
+ raise ValueError("max_query_length must be positive")
64
+
65
+
66
+ @dataclass
67
+ class DatabaseConfig:
68
+ """Comprehensive database configuration."""
69
+
70
+ # Connection settings
71
+ connection_string: str
72
+ database_type: Optional[str] = None
73
+ host: Optional[str] = None
74
+ port: Optional[int] = None
75
+ database: Optional[str] = None
76
+ username: Optional[str] = None
77
+ password: Optional[str] = None
78
+
79
+ # Configuration objects
80
+ pool_config: PoolConfig = field(default_factory=PoolConfig)
81
+ security_config: SecurityConfig = field(default_factory=SecurityConfig)
82
+ validation_config: ValidationConfig = field(default_factory=ValidationConfig)
83
+
84
+ # Additional settings
85
+ echo: bool = False
86
+ connect_args: Dict[str, Any] = field(default_factory=dict)
87
+ isolation_level: Optional[str] = None
88
+
89
+ def __post_init__(self):
90
+ """Validate database configuration."""
91
+ if not self.connection_string:
92
+ raise ValueError("connection_string is required")
93
+
94
+ # Extract database type from connection string if not provided
95
+ if not self.database_type and "://" in self.connection_string:
96
+ self.database_type = self.connection_string.split("://")[0].split("+")[0]
97
+
98
+ # Validate connection string format
99
+ self._validate_connection_string()
100
+
101
+ def _validate_connection_string(self):
102
+ """Validate connection string format."""
103
+ if not self.connection_string.startswith(
104
+ ("postgresql://", "mysql://", "sqlite:///")
105
+ ):
106
+ # Allow driver specifications like postgresql+psycopg2://
107
+ valid_prefixes = ("postgresql+", "mysql+", "sqlite+")
108
+ if not any(
109
+ self.connection_string.startswith(prefix) for prefix in valid_prefixes
110
+ ):
111
+ raise ValueError(
112
+ "connection_string must start with postgresql://, mysql://, or sqlite:///"
113
+ )
114
+
115
+ def get_sqlalchemy_config(self) -> Dict[str, Any]:
116
+ """Get SQLAlchemy-compatible configuration."""
117
+ config = {
118
+ "poolclass": "QueuePool", # Will be converted to actual class
119
+ "pool_size": self.pool_config.pool_size,
120
+ "max_overflow": self.pool_config.max_overflow,
121
+ "pool_timeout": self.pool_config.pool_timeout,
122
+ "pool_recycle": self.pool_config.pool_recycle,
123
+ "pool_pre_ping": self.pool_config.pool_pre_ping,
124
+ "echo": self.echo,
125
+ }
126
+
127
+ if self.isolation_level:
128
+ config["isolation_level"] = self.isolation_level
129
+
130
+ if self.connect_args:
131
+ config["connect_args"] = self.connect_args
132
+
133
+ return config
134
+
135
+ def get_masked_connection_string(self) -> str:
136
+ """Get connection string with password masked for logging."""
137
+ import re
138
+
139
+ pattern = r"(://[^:]+:)[^@]+(@)"
140
+ return re.sub(pattern, r"\1***\2", self.connection_string)
141
+
142
+ def is_encrypted(self) -> bool:
143
+ """Check if connection uses encryption."""
144
+ return (
145
+ self.security_config.encryption_enabled
146
+ or "sslmode=require" in self.connection_string
147
+ or "ssl=true" in self.connection_string
148
+ )
149
+
150
+
151
+ @dataclass
152
+ class AsyncDatabaseConfig(DatabaseConfig):
153
+ """Configuration for async database operations."""
154
+
155
+ # Async-specific settings
156
+ min_size: int = 1
157
+ max_size: int = 10
158
+ command_timeout: int = 60
159
+ server_settings: Dict[str, str] = field(default_factory=dict)
160
+
161
+ def __post_init__(self):
162
+ """Validate async database configuration."""
163
+ super().__post_init__()
164
+
165
+ if self.min_size < 1:
166
+ raise ValueError("min_size must be at least 1")
167
+ if self.max_size < self.min_size:
168
+ raise ValueError("max_size must be >= min_size")
169
+ if self.command_timeout < 1:
170
+ raise ValueError("command_timeout must be positive")
171
+
172
+ def get_asyncpg_config(self) -> Dict[str, Any]:
173
+ """Get asyncpg-compatible configuration."""
174
+ config = {
175
+ "min_size": self.min_size,
176
+ "max_size": self.max_size,
177
+ "command_timeout": self.command_timeout,
178
+ }
179
+
180
+ if self.server_settings:
181
+ config["server_settings"] = self.server_settings
182
+
183
+ return config
184
+
185
+
186
+ @dataclass
187
+ class VectorDatabaseConfig(AsyncDatabaseConfig):
188
+ """Configuration for vector database operations."""
189
+
190
+ # Vector-specific settings
191
+ dimension: int = 1536
192
+ index_type: str = "hnsw"
193
+ distance_metric: str = "cosine"
194
+ index_params: Dict[str, Any] = field(default_factory=dict)
195
+
196
+ def __post_init__(self):
197
+ """Validate vector database configuration."""
198
+ super().__post_init__()
199
+
200
+ if self.dimension < 1:
201
+ raise ValueError("dimension must be positive")
202
+
203
+ valid_index_types = ["hnsw", "ivfflat"]
204
+ if self.index_type not in valid_index_types:
205
+ raise ValueError(f"index_type must be one of {valid_index_types}")
206
+
207
+ valid_metrics = ["cosine", "euclidean", "manhattan", "dot_product"]
208
+ if self.distance_metric not in valid_metrics:
209
+ raise ValueError(f"distance_metric must be one of {valid_metrics}")
210
+
211
+ def get_pgvector_config(self) -> Dict[str, Any]:
212
+ """Get pgvector-specific configuration."""
213
+ config = {
214
+ "dimension": self.dimension,
215
+ "index_type": self.index_type,
216
+ "distance_metric": self.distance_metric,
217
+ }
218
+
219
+ if self.index_params:
220
+ config["index_params"] = self.index_params
221
+
222
+ return config
223
+
224
+
225
+ # Configuration builders for common scenarios
226
+ class DatabaseConfigBuilder:
227
+ """Builder for database configurations."""
228
+
229
+ @staticmethod
230
+ def postgresql(
231
+ host: str = "localhost",
232
+ port: int = 5432,
233
+ database: str = "postgres",
234
+ username: str = "postgres",
235
+ password: str = "",
236
+ **kwargs,
237
+ ) -> DatabaseConfig:
238
+ """Build PostgreSQL configuration."""
239
+ connection_string = (
240
+ f"postgresql://{username}:{password}@{host}:{port}/{database}"
241
+ )
242
+
243
+ return DatabaseConfig(
244
+ connection_string=connection_string,
245
+ database_type="postgresql",
246
+ host=host,
247
+ port=port,
248
+ database=database,
249
+ username=username,
250
+ password=password,
251
+ **kwargs,
252
+ )
253
+
254
+ @staticmethod
255
+ def mysql(
256
+ host: str = "localhost",
257
+ port: int = 3306,
258
+ database: str = "mysql",
259
+ username: str = "root",
260
+ password: str = "",
261
+ **kwargs,
262
+ ) -> DatabaseConfig:
263
+ """Build MySQL configuration."""
264
+ connection_string = f"mysql://{username}:{password}@{host}:{port}/{database}"
265
+
266
+ return DatabaseConfig(
267
+ connection_string=connection_string,
268
+ database_type="mysql",
269
+ host=host,
270
+ port=port,
271
+ database=database,
272
+ username=username,
273
+ password=password,
274
+ **kwargs,
275
+ )
276
+
277
+ @staticmethod
278
+ def sqlite(database_path: str, **kwargs) -> DatabaseConfig:
279
+ """Build SQLite configuration."""
280
+ connection_string = f"sqlite:///{database_path}"
281
+
282
+ return DatabaseConfig(
283
+ connection_string=connection_string,
284
+ database_type="sqlite",
285
+ database=database_path,
286
+ **kwargs,
287
+ )
288
+
289
+
290
+ class AsyncDatabaseConfigBuilder:
291
+ """Builder for async database configurations."""
292
+
293
+ @staticmethod
294
+ def postgresql(
295
+ host: str = "localhost",
296
+ port: int = 5432,
297
+ database: str = "postgres",
298
+ username: str = "postgres",
299
+ password: str = "",
300
+ **kwargs,
301
+ ) -> AsyncDatabaseConfig:
302
+ """Build async PostgreSQL configuration."""
303
+ connection_string = (
304
+ f"postgresql://{username}:{password}@{host}:{port}/{database}"
305
+ )
306
+
307
+ return AsyncDatabaseConfig(
308
+ connection_string=connection_string,
309
+ database_type="postgresql",
310
+ host=host,
311
+ port=port,
312
+ database=database,
313
+ username=username,
314
+ password=password,
315
+ **kwargs,
316
+ )
317
+
318
+ @staticmethod
319
+ def with_vector_support(
320
+ base_config: AsyncDatabaseConfig, dimension: int = 1536, **vector_kwargs
321
+ ) -> VectorDatabaseConfig:
322
+ """Add vector support to async database configuration."""
323
+ # Convert to vector config
324
+ config_dict = {
325
+ "connection_string": base_config.connection_string,
326
+ "database_type": base_config.database_type,
327
+ "host": base_config.host,
328
+ "port": base_config.port,
329
+ "database": base_config.database,
330
+ "username": base_config.username,
331
+ "password": base_config.password,
332
+ "pool_config": base_config.pool_config,
333
+ "security_config": base_config.security_config,
334
+ "validation_config": base_config.validation_config,
335
+ "echo": base_config.echo,
336
+ "connect_args": base_config.connect_args,
337
+ "isolation_level": base_config.isolation_level,
338
+ "min_size": base_config.min_size,
339
+ "max_size": base_config.max_size,
340
+ "command_timeout": base_config.command_timeout,
341
+ "server_settings": base_config.server_settings,
342
+ "dimension": dimension,
343
+ **vector_kwargs,
344
+ }
345
+
346
+ return VectorDatabaseConfig(**config_dict)
347
+
348
+
349
+ # Export components
350
+ __all__ = [
351
+ "PoolConfig",
352
+ "SecurityConfig",
353
+ "ValidationConfig",
354
+ "DatabaseConfig",
355
+ "AsyncDatabaseConfig",
356
+ "VectorDatabaseConfig",
357
+ "DatabaseConfigBuilder",
358
+ "AsyncDatabaseConfigBuilder",
359
+ ]
@@ -0,0 +1,28 @@
1
+ """Database execution pipeline components.
2
+
3
+ This module provides a clean, testable approach to database operations
4
+ with proper separation of concerns between permission checking, query
5
+ execution, and data masking.
6
+ """
7
+
8
+ from kailash.database.execution_pipeline import (
9
+ DatabaseExecutionPipeline,
10
+ DataMaskingStage,
11
+ ExecutionContext,
12
+ ExecutionResult,
13
+ PermissionCheckStage,
14
+ PipelineStage,
15
+ QueryExecutionStage,
16
+ QueryValidationStage,
17
+ )
18
+
19
+ __all__ = [
20
+ "DatabaseExecutionPipeline",
21
+ "ExecutionContext",
22
+ "ExecutionResult",
23
+ "PipelineStage",
24
+ "PermissionCheckStage",
25
+ "QueryValidationStage",
26
+ "QueryExecutionStage",
27
+ "DataMaskingStage",
28
+ ]