misata 0.1.0b0__tar.gz → 0.3.0b0__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 (57) hide show
  1. misata-0.3.0b0/LICENSE +21 -0
  2. {misata-0.1.0b0 → misata-0.3.0b0}/PKG-INFO +4 -2
  3. {misata-0.1.0b0 → misata-0.3.0b0}/README.md +1 -1
  4. misata-0.3.0b0/misata/__init__.py +134 -0
  5. misata-0.3.0b0/misata/cache.py +258 -0
  6. misata-0.3.0b0/misata/constraints.py +307 -0
  7. misata-0.3.0b0/misata/context.py +259 -0
  8. misata-0.3.0b0/misata/exceptions.py +277 -0
  9. misata-0.3.0b0/misata/generators/__init__.py +29 -0
  10. misata-0.3.0b0/misata/generators/base.py +586 -0
  11. {misata-0.1.0b0 → misata-0.3.0b0}/misata/llm_parser.py +41 -2
  12. misata-0.3.0b0/misata/profiles.py +332 -0
  13. misata-0.3.0b0/misata/quality.py +329 -0
  14. {misata-0.1.0b0 → misata-0.3.0b0}/misata/schema.py +8 -3
  15. {misata-0.1.0b0 → misata-0.3.0b0}/misata/simulator.py +81 -5
  16. misata-0.3.0b0/misata/smart_values.py +762 -0
  17. misata-0.3.0b0/misata/streaming.py +228 -0
  18. misata-0.3.0b0/misata/templates/library.py +344 -0
  19. {misata-0.1.0b0 → misata-0.3.0b0}/misata.egg-info/PKG-INFO +4 -2
  20. {misata-0.1.0b0 → misata-0.3.0b0}/misata.egg-info/SOURCES.txt +12 -0
  21. {misata-0.1.0b0 → misata-0.3.0b0}/pyproject.toml +1 -1
  22. misata-0.1.0b0/misata/__init__.py +0 -48
  23. {misata-0.1.0b0 → misata-0.3.0b0}/misata/api.py +0 -0
  24. {misata-0.1.0b0 → misata-0.3.0b0}/misata/audit.py +0 -0
  25. {misata-0.1.0b0 → misata-0.3.0b0}/misata/benchmark.py +0 -0
  26. {misata-0.1.0b0 → misata-0.3.0b0}/misata/cli.py +0 -0
  27. {misata-0.1.0b0 → misata-0.3.0b0}/misata/codegen.py +0 -0
  28. {misata-0.1.0b0 → misata-0.3.0b0}/misata/curve_fitting.py +0 -0
  29. {misata-0.1.0b0 → misata-0.3.0b0}/misata/customization.py +0 -0
  30. {misata-0.1.0b0 → misata-0.3.0b0}/misata/feedback.py +0 -0
  31. {misata-0.1.0b0 → misata-0.3.0b0}/misata/formulas.py +0 -0
  32. {misata-0.1.0b0 → misata-0.3.0b0}/misata/generators.py +0 -0
  33. {misata-0.1.0b0 → misata-0.3.0b0}/misata/hybrid.py +0 -0
  34. {misata-0.1.0b0 → misata-0.3.0b0}/misata/noise.py +0 -0
  35. {misata-0.1.0b0 → misata-0.3.0b0}/misata/semantic.py +0 -0
  36. {misata-0.1.0b0 → misata-0.3.0b0}/misata/story_parser.py +0 -0
  37. {misata-0.1.0b0 → misata-0.3.0b0}/misata/templates/__init__.py +0 -0
  38. {misata-0.1.0b0 → misata-0.3.0b0}/misata/validation.py +0 -0
  39. {misata-0.1.0b0 → misata-0.3.0b0}/misata.egg-info/dependency_links.txt +0 -0
  40. {misata-0.1.0b0 → misata-0.3.0b0}/misata.egg-info/entry_points.txt +0 -0
  41. {misata-0.1.0b0 → misata-0.3.0b0}/misata.egg-info/requires.txt +0 -0
  42. {misata-0.1.0b0 → misata-0.3.0b0}/misata.egg-info/top_level.txt +0 -0
  43. {misata-0.1.0b0 → misata-0.3.0b0}/setup.cfg +0 -0
  44. {misata-0.1.0b0 → misata-0.3.0b0}/tests/test_api.py +0 -0
  45. {misata-0.1.0b0 → misata-0.3.0b0}/tests/test_cli.py +0 -0
  46. {misata-0.1.0b0 → misata-0.3.0b0}/tests/test_constraints.py +0 -0
  47. {misata-0.1.0b0 → misata-0.3.0b0}/tests/test_curve_fitting.py +0 -0
  48. {misata-0.1.0b0 → misata-0.3.0b0}/tests/test_enterprise.py +0 -0
  49. {misata-0.1.0b0 → misata-0.3.0b0}/tests/test_formulas.py +0 -0
  50. {misata-0.1.0b0 → misata-0.3.0b0}/tests/test_integrity.py +0 -0
  51. {misata-0.1.0b0 → misata-0.3.0b0}/tests/test_llm_parser.py +0 -0
  52. {misata-0.1.0b0 → misata-0.3.0b0}/tests/test_schema.py +0 -0
  53. {misata-0.1.0b0 → misata-0.3.0b0}/tests/test_security.py +0 -0
  54. {misata-0.1.0b0 → misata-0.3.0b0}/tests/test_semantic.py +0 -0
  55. {misata-0.1.0b0 → misata-0.3.0b0}/tests/test_simulator.py +0 -0
  56. {misata-0.1.0b0 → misata-0.3.0b0}/tests/test_templates.py +0 -0
  57. {misata-0.1.0b0 → misata-0.3.0b0}/tests/test_validation.py +0 -0
misata-0.3.0b0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Muhammed Rasin
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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: misata
3
- Version: 0.1.0b0
3
+ Version: 0.3.0b0
4
4
  Summary: AI-Powered Synthetic Data Engine - Generate realistic multi-table datasets from natural language
5
5
  Author-email: Muhammed Rasin <rasinbinabdulla@gmail.com>
6
6
  License: MIT
@@ -23,6 +23,7 @@ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
23
23
  Classifier: Topic :: Database
24
24
  Requires-Python: >=3.10
25
25
  Description-Content-Type: text/markdown
26
+ License-File: LICENSE
26
27
  Requires-Dist: pandas>=2.0.0
27
28
  Requires-Dist: numpy>=1.24.0
28
29
  Requires-Dist: pydantic>=2.0.0
@@ -41,6 +42,7 @@ Requires-Dist: pytest-benchmark>=4.0.0; extra == "dev"
41
42
  Requires-Dist: black>=23.0.0; extra == "dev"
42
43
  Requires-Dist: ruff>=0.1.0; extra == "dev"
43
44
  Requires-Dist: mypy>=1.5.0; extra == "dev"
45
+ Dynamic: license-file
44
46
 
45
47
  # 🧠 Misata
46
48
 
@@ -48,7 +50,7 @@ Requires-Dist: mypy>=1.5.0; extra == "dev"
48
50
 
49
51
  No schema writing. No training data. Just describe what you need.
50
52
 
51
- [![Version](https://img.shields.io/badge/version-0.1.0--beta-purple.svg)]()
53
+ [![Version](https://img.shields.io/badge/version-0.2.0--beta-purple.svg)]()
52
54
  [![License](https://img.shields.io/badge/license-MIT-blue.svg)]()
53
55
  [![Python](https://img.shields.io/badge/python-3.10+-green.svg)]()
54
56
 
@@ -4,7 +4,7 @@
4
4
 
5
5
  No schema writing. No training data. Just describe what you need.
6
6
 
7
- [![Version](https://img.shields.io/badge/version-0.1.0--beta-purple.svg)]()
7
+ [![Version](https://img.shields.io/badge/version-0.2.0--beta-purple.svg)]()
8
8
  [![License](https://img.shields.io/badge/license-MIT-blue.svg)]()
9
9
  [![Python](https://img.shields.io/badge/python-3.10+-green.svg)]()
10
10
 
@@ -0,0 +1,134 @@
1
+ """
2
+ Misata - AI-Powered Synthetic Data Engine
3
+
4
+ Generate realistic multi-table datasets from natural language descriptions.
5
+ Supports OpenAI, Groq, Gemini, and Ollama for intelligent schema generation.
6
+
7
+ Usage:
8
+ from misata import DataSimulator, SchemaConfig
9
+
10
+ # Or use the CLI:
11
+ # misata generate --story "A SaaS with 50k users..."
12
+
13
+ # Or use pre-built templates:
14
+ from misata.templates.library import load_template
15
+ config = load_template("ecommerce")
16
+ """
17
+
18
+ __version__ = "0.3.0b0"
19
+ __author__ = "Muhammed Rasin"
20
+
21
+ from misata.schema import (
22
+ Column,
23
+ Constraint,
24
+ Relationship,
25
+ ScenarioEvent,
26
+ SchemaConfig,
27
+ Table,
28
+ )
29
+ from misata.simulator import DataSimulator
30
+ from misata.generators import TextGenerator
31
+ from misata.generators.base import (
32
+ BaseGenerator,
33
+ IntegerGenerator,
34
+ FloatGenerator,
35
+ BooleanGenerator,
36
+ CategoricalGenerator,
37
+ DateGenerator,
38
+ ForeignKeyGenerator,
39
+ GeneratorFactory,
40
+ )
41
+ from misata.constraints import (
42
+ BaseConstraint,
43
+ SumConstraint,
44
+ RangeConstraint,
45
+ UniqueConstraint,
46
+ NotNullConstraint,
47
+ RatioConstraint,
48
+ ConstraintEngine,
49
+ )
50
+ from misata.context import GenerationContext
51
+ from misata.exceptions import (
52
+ MisataError,
53
+ SchemaValidationError,
54
+ ColumnGenerationError,
55
+ LLMError,
56
+ ConfigurationError,
57
+ ExportError,
58
+ )
59
+ from misata.smart_values import SmartValueGenerator
60
+ from misata.noise import NoiseInjector, add_noise
61
+ from misata.customization import Customizer, ColumnOverride
62
+ from misata.quality import DataQualityChecker, check_quality
63
+ from misata.templates.library import load_template, list_templates
64
+ from misata.profiles import (
65
+ DistributionProfile,
66
+ get_profile,
67
+ list_profiles,
68
+ generate_with_profile,
69
+ )
70
+ from misata.generators.base import (
71
+ ConditionalCategoricalGenerator,
72
+ CONDITIONAL_LOOKUPS,
73
+ create_conditional_generator,
74
+ )
75
+
76
+ __all__ = [
77
+ # Core
78
+ "Column",
79
+ "Constraint",
80
+ "Relationship",
81
+ "ScenarioEvent",
82
+ "SchemaConfig",
83
+ "Table",
84
+ "DataSimulator",
85
+ # Generators
86
+ "TextGenerator",
87
+ "BaseGenerator",
88
+ "IntegerGenerator",
89
+ "FloatGenerator",
90
+ "BooleanGenerator",
91
+ "CategoricalGenerator",
92
+ "DateGenerator",
93
+ "ForeignKeyGenerator",
94
+ "GeneratorFactory",
95
+ "ConditionalCategoricalGenerator",
96
+ "CONDITIONAL_LOOKUPS",
97
+ "create_conditional_generator",
98
+ # Constraints
99
+ "BaseConstraint",
100
+ "SumConstraint",
101
+ "RangeConstraint",
102
+ "UniqueConstraint",
103
+ "NotNullConstraint",
104
+ "RatioConstraint",
105
+ "ConstraintEngine",
106
+ # Context
107
+ "GenerationContext",
108
+ # Exceptions
109
+ "MisataError",
110
+ "SchemaValidationError",
111
+ "ColumnGenerationError",
112
+ "LLMError",
113
+ "ConfigurationError",
114
+ "ExportError",
115
+ # Smart Values
116
+ "SmartValueGenerator",
117
+ # Distribution Profiles
118
+ "DistributionProfile",
119
+ "get_profile",
120
+ "list_profiles",
121
+ "generate_with_profile",
122
+ # ML-ready features
123
+ "NoiseInjector",
124
+ "add_noise",
125
+ "Customizer",
126
+ "ColumnOverride",
127
+ # Quality
128
+ "DataQualityChecker",
129
+ "check_quality",
130
+ # Templates
131
+ "load_template",
132
+ "list_templates",
133
+ ]
134
+
@@ -0,0 +1,258 @@
1
+ """
2
+ Caching utilities for Misata.
3
+
4
+ Provides LLM response caching using diskcache for performance optimization.
5
+ """
6
+
7
+ import hashlib
8
+ import json
9
+ import os
10
+ from pathlib import Path
11
+ from typing import Any, Dict, Optional, Union
12
+
13
+ try:
14
+ import diskcache
15
+ HAS_DISKCACHE = True
16
+ except ImportError:
17
+ HAS_DISKCACHE = False
18
+
19
+
20
+ class LLMCache:
21
+ """Cache for LLM responses to avoid repeated API calls.
22
+
23
+ Uses diskcache for persistent storage with automatic expiration.
24
+ Falls back to in-memory dict if diskcache is not installed.
25
+
26
+ Example:
27
+ cache = LLMCache()
28
+
29
+ # Check cache first
30
+ key = cache.make_key("groq", "llama-3.3", prompt)
31
+ cached = cache.get(key)
32
+ if cached:
33
+ return cached
34
+
35
+ # Make LLM call
36
+ response = llm.generate(prompt)
37
+
38
+ # Cache the result
39
+ cache.set(key, response)
40
+ """
41
+
42
+ def __init__(
43
+ self,
44
+ cache_dir: Optional[str] = None,
45
+ max_size_mb: int = 100,
46
+ expire_days: int = 7,
47
+ ):
48
+ """Initialize the cache.
49
+
50
+ Args:
51
+ cache_dir: Directory for cache storage (default: ~/.misata/cache)
52
+ max_size_mb: Maximum cache size in MB
53
+ expire_days: Days before cache entries expire
54
+ """
55
+ self.expire_seconds = expire_days * 24 * 60 * 60
56
+
57
+ if cache_dir is None:
58
+ cache_dir = os.path.expanduser("~/.misata/cache/llm")
59
+
60
+ self.cache_dir = Path(cache_dir)
61
+
62
+ if HAS_DISKCACHE:
63
+ self.cache_dir.mkdir(parents=True, exist_ok=True)
64
+ self._cache = diskcache.Cache(
65
+ str(self.cache_dir),
66
+ size_limit=max_size_mb * 1024 * 1024,
67
+ )
68
+ else:
69
+ # Fallback to in-memory cache
70
+ self._cache: Dict[str, Any] = {}
71
+ self._memory_mode = True
72
+
73
+ def make_key(
74
+ self,
75
+ provider: str,
76
+ model: str,
77
+ prompt: str,
78
+ temperature: float = 0.0,
79
+ **kwargs: Any
80
+ ) -> str:
81
+ """Create a cache key from request parameters.
82
+
83
+ Args:
84
+ provider: LLM provider (groq, openai, etc.)
85
+ model: Model name
86
+ prompt: The prompt text
87
+ temperature: Temperature setting
88
+ **kwargs: Additional parameters to include in key
89
+
90
+ Returns:
91
+ Hash-based cache key
92
+ """
93
+ key_data = {
94
+ "provider": provider,
95
+ "model": model,
96
+ "prompt": prompt,
97
+ "temperature": temperature,
98
+ **kwargs
99
+ }
100
+ key_str = json.dumps(key_data, sort_keys=True)
101
+ return hashlib.sha256(key_str.encode()).hexdigest()[:32]
102
+
103
+ def get(self, key: str) -> Optional[Any]:
104
+ """Get a cached value.
105
+
106
+ Args:
107
+ key: Cache key
108
+
109
+ Returns:
110
+ Cached value or None if not found/expired
111
+ """
112
+ if HAS_DISKCACHE:
113
+ return self._cache.get(key)
114
+ else:
115
+ return self._cache.get(key)
116
+
117
+ def set(self, key: str, value: Any) -> None:
118
+ """Store a value in cache.
119
+
120
+ Args:
121
+ key: Cache key
122
+ value: Value to cache (must be JSON-serializable for persistence)
123
+ """
124
+ if HAS_DISKCACHE:
125
+ self._cache.set(key, value, expire=self.expire_seconds)
126
+ else:
127
+ self._cache[key] = value
128
+
129
+ def delete(self, key: str) -> bool:
130
+ """Delete a cached value.
131
+
132
+ Args:
133
+ key: Cache key
134
+
135
+ Returns:
136
+ True if deleted, False if not found
137
+ """
138
+ if HAS_DISKCACHE:
139
+ return self._cache.delete(key)
140
+ else:
141
+ if key in self._cache:
142
+ del self._cache[key]
143
+ return True
144
+ return False
145
+
146
+ def clear(self) -> None:
147
+ """Clear all cached values."""
148
+ if HAS_DISKCACHE:
149
+ self._cache.clear()
150
+ else:
151
+ self._cache.clear()
152
+
153
+ def stats(self) -> Dict[str, Any]:
154
+ """Get cache statistics."""
155
+ if HAS_DISKCACHE:
156
+ return {
157
+ "type": "diskcache",
158
+ "directory": str(self.cache_dir),
159
+ "size_bytes": self._cache.volume(),
160
+ "count": len(self._cache),
161
+ }
162
+ else:
163
+ return {
164
+ "type": "memory",
165
+ "count": len(self._cache),
166
+ }
167
+
168
+ def __contains__(self, key: str) -> bool:
169
+ return self.get(key) is not None
170
+
171
+ def close(self) -> None:
172
+ """Close the cache (required for diskcache)."""
173
+ if HAS_DISKCACHE:
174
+ self._cache.close()
175
+
176
+
177
+ class SmartValueCache:
178
+ """Cache for SmartValueGenerator pools.
179
+
180
+ Caches generated value pools by domain/context to avoid
181
+ repeated LLM calls for the same domain.
182
+ """
183
+
184
+ def __init__(self, cache: Optional[LLMCache] = None):
185
+ self._cache = cache or LLMCache(
186
+ cache_dir=os.path.expanduser("~/.misata/cache/smart_values")
187
+ )
188
+
189
+ def get_pool(
190
+ self,
191
+ domain: str,
192
+ context: Optional[str] = None,
193
+ provider: str = "groq"
194
+ ) -> Optional[list]:
195
+ """Get cached value pool for a domain.
196
+
197
+ Args:
198
+ domain: Domain type (disease, prescription, etc.)
199
+ context: Additional context
200
+ provider: LLM provider used
201
+
202
+ Returns:
203
+ List of values or None if not cached
204
+ """
205
+ key = self._make_pool_key(domain, context, provider)
206
+ return self._cache.get(key)
207
+
208
+ def set_pool(
209
+ self,
210
+ domain: str,
211
+ values: list,
212
+ context: Optional[str] = None,
213
+ provider: str = "groq"
214
+ ) -> None:
215
+ """Cache a value pool.
216
+
217
+ Args:
218
+ domain: Domain type
219
+ values: List of generated values
220
+ context: Additional context
221
+ provider: LLM provider used
222
+ """
223
+ key = self._make_pool_key(domain, context, provider)
224
+ self._cache.set(key, values)
225
+
226
+ def _make_pool_key(
227
+ self,
228
+ domain: str,
229
+ context: Optional[str],
230
+ provider: str
231
+ ) -> str:
232
+ key_data = f"{provider}:{domain}:{context or ''}"
233
+ return hashlib.sha256(key_data.encode()).hexdigest()[:24]
234
+
235
+ def clear(self) -> None:
236
+ """Clear all cached pools."""
237
+ self._cache.clear()
238
+
239
+
240
+ # Global cache instances
241
+ _llm_cache: Optional[LLMCache] = None
242
+ _smart_value_cache: Optional[SmartValueCache] = None
243
+
244
+
245
+ def get_llm_cache() -> LLMCache:
246
+ """Get the global LLM cache instance."""
247
+ global _llm_cache
248
+ if _llm_cache is None:
249
+ _llm_cache = LLMCache()
250
+ return _llm_cache
251
+
252
+
253
+ def get_smart_value_cache() -> SmartValueCache:
254
+ """Get the global smart value cache instance."""
255
+ global _smart_value_cache
256
+ if _smart_value_cache is None:
257
+ _smart_value_cache = SmartValueCache()
258
+ return _smart_value_cache