taipanstack 0.3.9__tar.gz → 0.3.11__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 (36) hide show
  1. {taipanstack-0.3.9 → taipanstack-0.3.11}/PKG-INFO +28 -4
  2. {taipanstack-0.3.9 → taipanstack-0.3.11}/README.md +26 -3
  3. {taipanstack-0.3.9 → taipanstack-0.3.11}/pyproject.toml +8 -4
  4. {taipanstack-0.3.9 → taipanstack-0.3.11}/src/taipanstack/__init__.py +1 -1
  5. {taipanstack-0.3.9 → taipanstack-0.3.11}/src/taipanstack/config/generators.py +1 -1
  6. {taipanstack-0.3.9 → taipanstack-0.3.11}/src/taipanstack/config/models.py +2 -2
  7. {taipanstack-0.3.9 → taipanstack-0.3.11}/src/taipanstack/core/compat.py +37 -7
  8. {taipanstack-0.3.9 → taipanstack-0.3.11}/src/taipanstack/core/optimizations.py +49 -35
  9. {taipanstack-0.3.9 → taipanstack-0.3.11}/src/taipanstack/core/result.py +65 -119
  10. {taipanstack-0.3.9 → taipanstack-0.3.11}/src/taipanstack/security/decorators.py +24 -13
  11. {taipanstack-0.3.9 → taipanstack-0.3.11}/src/taipanstack/security/guards.py +224 -158
  12. {taipanstack-0.3.9 → taipanstack-0.3.11}/src/taipanstack/security/jwt.py +7 -5
  13. {taipanstack-0.3.9 → taipanstack-0.3.11}/src/taipanstack/security/models.py +36 -7
  14. taipanstack-0.3.11/src/taipanstack/security/password.py +94 -0
  15. {taipanstack-0.3.9 → taipanstack-0.3.11}/src/taipanstack/security/sanitizers.py +106 -51
  16. {taipanstack-0.3.9 → taipanstack-0.3.11}/src/taipanstack/security/types.py +46 -0
  17. {taipanstack-0.3.9 → taipanstack-0.3.11}/src/taipanstack/security/validators.py +3 -117
  18. {taipanstack-0.3.9 → taipanstack-0.3.11}/src/taipanstack/utils/__init__.py +16 -4
  19. taipanstack-0.3.11/src/taipanstack/utils/cache.py +112 -0
  20. {taipanstack-0.3.9 → taipanstack-0.3.11}/src/taipanstack/utils/circuit_breaker.py +53 -20
  21. {taipanstack-0.3.9 → taipanstack-0.3.11}/src/taipanstack/utils/concurrency.py +70 -44
  22. taipanstack-0.3.11/src/taipanstack/utils/context.py +61 -0
  23. {taipanstack-0.3.9 → taipanstack-0.3.11}/src/taipanstack/utils/filesystem.py +77 -41
  24. {taipanstack-0.3.9 → taipanstack-0.3.11}/src/taipanstack/utils/logging.py +51 -50
  25. {taipanstack-0.3.9 → taipanstack-0.3.11}/src/taipanstack/utils/metrics.py +27 -8
  26. {taipanstack-0.3.9 → taipanstack-0.3.11}/src/taipanstack/utils/rate_limit.py +15 -12
  27. taipanstack-0.3.11/src/taipanstack/utils/resilience.py +185 -0
  28. {taipanstack-0.3.9 → taipanstack-0.3.11}/src/taipanstack/utils/retry.py +41 -23
  29. {taipanstack-0.3.9 → taipanstack-0.3.11}/src/taipanstack/utils/serialization.py +10 -12
  30. {taipanstack-0.3.9 → taipanstack-0.3.11}/src/taipanstack/utils/subprocess.py +116 -153
  31. taipanstack-0.3.9/src/taipanstack/security/password.py +0 -87
  32. {taipanstack-0.3.9 → taipanstack-0.3.11}/LICENSE +0 -0
  33. {taipanstack-0.3.9 → taipanstack-0.3.11}/src/taipanstack/config/__init__.py +0 -0
  34. {taipanstack-0.3.9 → taipanstack-0.3.11}/src/taipanstack/config/version_config.py +0 -0
  35. {taipanstack-0.3.9 → taipanstack-0.3.11}/src/taipanstack/core/__init__.py +0 -0
  36. {taipanstack-0.3.9 → taipanstack-0.3.11}/src/taipanstack/security/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: taipanstack
3
- Version: 0.3.9
3
+ Version: 0.3.11
4
4
  Summary: TaipanStack - Modular, secure, and scalable Python stack for robust development
5
5
  License-Expression: MIT
6
6
  License-File: LICENSE
@@ -19,6 +19,7 @@ Classifier: Topic :: Software Development :: Quality Assurance
19
19
  Classifier: Topic :: Security
20
20
  Classifier: Typing :: Typed
21
21
  Provides-Extra: runtime
22
+ Requires-Dist: argon2-cffi (>=25.1.0,<26.0.0)
22
23
  Requires-Dist: email-validator (>=2.0.0)
23
24
  Requires-Dist: orjson (>=3.9.0)
24
25
  Requires-Dist: pydantic (>=2.0)
@@ -103,7 +104,7 @@ TaipanStack is a battle-tested foundation for production-grade Python projects t
103
104
 
104
105
  ### 🔧 Developer Experience
105
106
  - Pre-configured quality tools
106
- - **100% code coverage** (664 tests)
107
+ - **100% code coverage** (1006 tests)
107
108
  - Architecture enforcement
108
109
  - Hardened Docker template
109
110
 
@@ -145,7 +146,7 @@ make all
145
146
  ### Verify Installation
146
147
 
147
148
  ```bash
148
- # Run tests with 100% coverage (664 tests)
149
+ # Run tests with 100% coverage (1006 tests)
149
150
  make test
150
151
 
151
152
  # Check architecture contracts
@@ -200,7 +201,7 @@ TaipanStack/
200
201
  │ ├── config/ # ⚙️ Configuration models & generators
201
202
  │ ├── security/ # 🛡️ Guards, sanitizers, validators
202
203
  │ └── utils/ # 🔧 Logging, metrics, retry, filesystem
203
- ├── tests/ # ✅ 664 tests, 100% coverage
204
+ ├── tests/ # ✅ 1006 tests, 100% coverage
204
205
  ├── .semgrep/ # 🔍 Custom SAST rules
205
206
  ├── .github/ # 🔄 CI/CD + SBOM/SLSA workflows
206
207
  ├── Dockerfile # 🐳 Hardened multi-stage container
@@ -339,6 +340,29 @@ def fetch_user_profile(user_id: str) -> dict:
339
340
  profile = unwrap_or(fetch_user_profile("usr_456"), {"name": "Unknown"})
340
341
  ```
341
342
 
343
+ ### Intelligent Caching
344
+
345
+ ```python
346
+ from taipanstack.utils.cache import cached
347
+ from taipanstack.core.result import Result
348
+
349
+ @cached(ttl=60)
350
+ async def get_user_data(user_id: int) -> Result[dict, Exception]:
351
+ return await db.fetch(user_id) # Only Ok() results are cached
352
+ ```
353
+
354
+ ### Fallbacks & Timeouts
355
+
356
+ ```python
357
+ from taipanstack.utils.resilience import fallback, timeout
358
+ from taipanstack.core.result import Result
359
+
360
+ @fallback(fallback_value={"status": "offline"}, exceptions=(TimeoutError,))
361
+ @timeout(seconds=5.0)
362
+ async def fetch_remote_status() -> Result[dict, Exception]:
363
+ return await api.get_status()
364
+ ```
365
+
342
366
  ---
343
367
 
344
368
  ## 🐳 Docker
@@ -67,7 +67,7 @@ TaipanStack is a battle-tested foundation for production-grade Python projects t
67
67
 
68
68
  ### 🔧 Developer Experience
69
69
  - Pre-configured quality tools
70
- - **100% code coverage** (664 tests)
70
+ - **100% code coverage** (1006 tests)
71
71
  - Architecture enforcement
72
72
  - Hardened Docker template
73
73
 
@@ -109,7 +109,7 @@ make all
109
109
  ### Verify Installation
110
110
 
111
111
  ```bash
112
- # Run tests with 100% coverage (664 tests)
112
+ # Run tests with 100% coverage (1006 tests)
113
113
  make test
114
114
 
115
115
  # Check architecture contracts
@@ -164,7 +164,7 @@ TaipanStack/
164
164
  │ ├── config/ # ⚙️ Configuration models & generators
165
165
  │ ├── security/ # 🛡️ Guards, sanitizers, validators
166
166
  │ └── utils/ # 🔧 Logging, metrics, retry, filesystem
167
- ├── tests/ # ✅ 664 tests, 100% coverage
167
+ ├── tests/ # ✅ 1006 tests, 100% coverage
168
168
  ├── .semgrep/ # 🔍 Custom SAST rules
169
169
  ├── .github/ # 🔄 CI/CD + SBOM/SLSA workflows
170
170
  ├── Dockerfile # 🐳 Hardened multi-stage container
@@ -303,6 +303,29 @@ def fetch_user_profile(user_id: str) -> dict:
303
303
  profile = unwrap_or(fetch_user_profile("usr_456"), {"name": "Unknown"})
304
304
  ```
305
305
 
306
+ ### Intelligent Caching
307
+
308
+ ```python
309
+ from taipanstack.utils.cache import cached
310
+ from taipanstack.core.result import Result
311
+
312
+ @cached(ttl=60)
313
+ async def get_user_data(user_id: int) -> Result[dict, Exception]:
314
+ return await db.fetch(user_id) # Only Ok() results are cached
315
+ ```
316
+
317
+ ### Fallbacks & Timeouts
318
+
319
+ ```python
320
+ from taipanstack.utils.resilience import fallback, timeout
321
+ from taipanstack.core.result import Result
322
+
323
+ @fallback(fallback_value={"status": "offline"}, exceptions=(TimeoutError,))
324
+ @timeout(seconds=5.0)
325
+ async def fetch_remote_status() -> Result[dict, Exception]:
326
+ return await api.get_status()
327
+ ```
328
+
306
329
  ---
307
330
 
308
331
  ## 🐳 Docker
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "taipanstack"
3
- version = "0.3.9"
3
+ version = "0.3.11"
4
4
  description = "TaipanStack - Modular, secure, and scalable Python stack for robust development"
5
5
  authors = [
6
6
  {name = "gabrielima7", email = "gabrielima.alu.lmb@gmail.com"}
@@ -28,6 +28,7 @@ dependencies = [
28
28
  "email-validator (>=2.0.0)",
29
29
  "result (>=0.17.0)",
30
30
  "pyjwt (>=2.11.0,<3.0.0)",
31
+ "argon2-cffi (>=25.1.0,<26.0.0)",
31
32
  ]
32
33
 
33
34
  [project.urls]
@@ -53,7 +54,6 @@ dev = [
53
54
  "ruff (>=0.8.0)",
54
55
  "mypy (>=1.10.0)",
55
56
  "bandit (>=1.7.0)",
56
- "safety (>=3.0.0)",
57
57
  "pre-commit (>=3.7.0)",
58
58
  "pytest (>=8.0.0)",
59
59
  "pytest-cov (>=5.0.0)",
@@ -69,6 +69,8 @@ dev = [
69
69
  "mutmut (>=3.0.0)",
70
70
  "pytest-benchmark (>=5.0.0)",
71
71
  "pytest-asyncio (>=0.23.0)",
72
+ "radon (>=6.0.1,<7.0.0)",
73
+ "pip-audit (>=2.10.0,<3.0.0)",
72
74
  ]
73
75
 
74
76
 
@@ -112,7 +114,7 @@ select = [
112
114
  "ERA", # eradicate
113
115
  "TRY", # tryceratops
114
116
  ]
115
- ignore = ["D203", "D212", "D213", "D416", "D417", "B905", "TRY003"]
117
+ ignore = ["D203", "D212", "D213", "D416", "D417", "TRY003"]
116
118
 
117
119
  [tool.ruff.lint.mccabe]
118
120
  max-complexity = 10
@@ -181,7 +183,7 @@ markers = [
181
183
  "benchmark: marks tests as performance benchmarks",
182
184
  ]
183
185
  filterwarnings = [
184
- "ignore::DeprecationWarning",
186
+
185
187
  "ignore::ResourceWarning",
186
188
  "ignore::pytest.PytestUnraisableExceptionWarning",
187
189
  ]
@@ -199,6 +201,8 @@ exclude_lines = [
199
201
  "if TYPE_CHECKING:",
200
202
  "if __name__ == .__main__.:",
201
203
  "@abstractmethod",
204
+ "@overload",
205
+ "def __call__\\(.*\\) -> .*:\\s*(?:\"\"\".*?\"\"\"\\s*)?\\.\\.\\.",
202
206
  ]
203
207
  partial_branches = [
204
208
  "pragma: no branch",
@@ -5,7 +5,7 @@ A modular, secure, and scalable Python stack for robust development.
5
5
  Supports Python 3.11+ with version-aware optimizations for 3.13/3.14.
6
6
  """
7
7
 
8
- __version__ = "0.3.9"
8
+ __version__ = "0.3.11"
9
9
 
10
10
  from taipanstack.config.version_config import (
11
11
  VersionRecommendations,
@@ -52,7 +52,7 @@ select = [
52
52
  "ERA", # eradicate
53
53
  "TRY", # tryceratops
54
54
  ]
55
- ignore = ["D203", "D212", "D213", "D416", "D417", "B905"]
55
+ ignore = ["D203", "D212", "D213", "D416", "D417"]
56
56
 
57
57
  [tool.ruff.lint.mccabe]
58
58
  max-complexity = 10
@@ -209,7 +209,7 @@ class StackConfig(BaseModel):
209
209
  ValueError: If project name contains invalid characters.
210
210
 
211
211
  """
212
- pattern = r"^[a-zA-Z][a-zA-Z0-9_-]*$"
212
+ pattern = r"^[a-zA-Z][a-zA-Z0-9_-]*\Z"
213
213
  if not re.match(pattern, value):
214
214
  msg = (
215
215
  f"Project name '{value}' is invalid. "
@@ -234,7 +234,7 @@ class StackConfig(BaseModel):
234
234
  ValueError: If version format is invalid.
235
235
 
236
236
  """
237
- pattern = r"^\d+\.\d+$"
237
+ pattern = r"^\d+\.\d+\Z"
238
238
  if not re.match(pattern, value):
239
239
  msg = (
240
240
  f"Python version '{value}' is invalid. Use format 'X.Y' (e.g., '3.12')."
@@ -141,31 +141,60 @@ def _check_tail_call_interpreter() -> bool:
141
141
  return PY314
142
142
 
143
143
 
144
- def is_experimental_enabled() -> bool:
144
+ _cached_experimental_enabled: bool | None = None
145
+
146
+
147
+ def is_experimental_enabled(*, force_refresh: bool = False) -> bool:
145
148
  """Check if experimental features are explicitly enabled.
146
149
 
150
+ Features are cached after first detection for performance.
151
+
152
+ Args:
153
+ force_refresh: If True, re-detect instead of using cache.
154
+
147
155
  Returns:
148
156
  True if STACK_ENABLE_EXPERIMENTAL=1 is set.
149
157
 
150
158
  """
159
+ global _cached_experimental_enabled # noqa: PLW0603
160
+
161
+ if _cached_experimental_enabled is not None and not force_refresh:
162
+ return _cached_experimental_enabled
163
+
151
164
  value = os.environ.get(ENV_ENABLE_EXPERIMENTAL, "").lower()
152
- return value in ("1", "true", "yes", "on")
165
+ _cached_experimental_enabled = value in {"1", "true", "yes", "on"}
166
+ return _cached_experimental_enabled
167
+
153
168
 
169
+ _cached_optimization_level: int | None = None
154
170
 
155
- def get_optimization_level() -> int:
171
+
172
+ def get_optimization_level(*, force_refresh: bool = False) -> int:
156
173
  """Get the configured optimization level.
157
174
 
175
+ Features are cached after first detection for performance.
176
+
177
+ Args:
178
+ force_refresh: If True, re-detect instead of using cache.
179
+
158
180
  Returns:
159
181
  0 = No optimizations
160
182
  1 = Safe optimizations only (default)
161
183
  2 = Aggressive optimizations (requires experimental)
162
184
 
163
185
  """
186
+ global _cached_optimization_level # noqa: PLW0603
187
+
188
+ if _cached_optimization_level is not None and not force_refresh:
189
+ return _cached_optimization_level
190
+
164
191
  try:
165
192
  level = int(os.environ.get(ENV_OPTIMIZATION_LEVEL, "1"))
166
- return max(0, min(2, level)) # Clamp to 0-2
193
+ _cached_optimization_level = max(0, min(2, level)) # Clamp to 0-2
167
194
  except ValueError:
168
- return 1
195
+ _cached_optimization_level = 1
196
+
197
+ return _cached_optimization_level
169
198
 
170
199
 
171
200
  # =============================================================================
@@ -260,7 +289,7 @@ def get_features(*, force_refresh: bool = False) -> PythonFeatures:
260
289
  else:
261
290
  tier = VersionTier.STABLE
262
291
 
263
- experimental = is_experimental_enabled()
292
+ experimental = is_experimental_enabled(force_refresh=force_refresh)
264
293
 
265
294
  # Build features (only if experimental is enabled for safety)
266
295
  has_jit = _check_jit_available() if experimental else False
@@ -292,10 +321,11 @@ def get_features(*, force_refresh: bool = False) -> PythonFeatures:
292
321
 
293
322
  # Log detected features at DEBUG level
294
323
  logger.debug(
295
- "Python %s detected (tier=%s, experimental=%s)",
324
+ "Python %s detected (tier=%s, experimental=%s): %r",
296
325
  features.version_string,
297
326
  tier.value,
298
327
  experimental,
328
+ features,
299
329
  )
300
330
 
301
331
  return features
@@ -11,7 +11,6 @@ import gc
11
11
  import logging
12
12
  import os
13
13
  from dataclasses import dataclass
14
- from typing import TYPE_CHECKING
15
14
 
16
15
  from taipanstack.core.compat import (
17
16
  PY312,
@@ -22,9 +21,6 @@ from taipanstack.core.compat import (
22
21
  is_experimental_enabled,
23
22
  )
24
23
 
25
- if TYPE_CHECKING:
26
- pass
27
-
28
24
  __all__ = [
29
25
  "OptimizationProfile",
30
26
  "OptimizationResult",
@@ -177,16 +173,27 @@ _PROFILE_314 = OptimizationProfile(
177
173
  )
178
174
 
179
175
 
180
- def get_optimization_profile() -> OptimizationProfile:
176
+ _cached_optimization_profile: OptimizationProfile | None = None
177
+
178
+
179
+ def get_optimization_profile(*, force_refresh: bool = False) -> OptimizationProfile:
181
180
  """Get the optimization profile for the current Python version.
182
181
 
182
+ Args:
183
+ force_refresh: If True, re-detect instead of using cache.
184
+
183
185
  Returns:
184
186
  OptimizationProfile suitable for the runtime environment.
185
187
 
186
188
  """
187
- _ = get_features() # Warm up cache, validate version
188
- experimental = is_experimental_enabled()
189
- opt_level = get_optimization_level()
189
+ global _cached_optimization_profile # noqa: PLW0603
190
+
191
+ if _cached_optimization_profile is not None and not force_refresh:
192
+ return _cached_optimization_profile
193
+
194
+ _ = get_features(force_refresh=force_refresh) # Warm up cache, validate version
195
+ experimental = is_experimental_enabled(force_refresh=force_refresh)
196
+ opt_level = get_optimization_level(force_refresh=force_refresh)
190
197
 
191
198
  # Select base profile by version
192
199
  if PY314:
@@ -199,30 +206,32 @@ def get_optimization_profile() -> OptimizationProfile:
199
206
  profile = _PROFILE_311
200
207
 
201
208
  # Adjust for optimization level
202
- if opt_level == OPT_LEVEL_NONE:
203
- # Minimal optimizations - use 3.11 baseline
204
- return _PROFILE_311
205
-
206
- if opt_level == OPT_LEVEL_AGGRESSIVE and experimental:
207
- # Aggressive mode - enable experimental features
208
- return OptimizationProfile(
209
- gc_threshold_0=profile.gc_threshold_0,
210
- gc_threshold_1=profile.gc_threshold_1,
211
- gc_threshold_2=profile.gc_threshold_2,
212
- gc_freeze_enabled=profile.gc_freeze_enabled,
213
- thread_pool_multiplier=profile.thread_pool_multiplier,
214
- max_thread_pool_size=profile.max_thread_pool_size,
215
- prefer_slots=profile.prefer_slots,
216
- use_frozen_dataclasses=profile.use_frozen_dataclasses,
217
- prefer_match_statements=profile.prefer_match_statements,
218
- prefer_exception_groups=profile.prefer_exception_groups,
219
- prefer_type_params=profile.prefer_type_params,
220
- enable_perf_hints=profile.enable_perf_hints,
221
- aggressive_inlining=profile.aggressive_inlining,
222
- enable_experimental=True,
223
- )
224
-
225
- return profile
209
+ match opt_level:
210
+ case opt if opt == OPT_LEVEL_NONE:
211
+ # Minimal optimizations - use 3.11 baseline
212
+ _cached_optimization_profile = _PROFILE_311
213
+ case opt if opt == OPT_LEVEL_AGGRESSIVE and experimental:
214
+ # Aggressive mode - enable experimental features
215
+ _cached_optimization_profile = OptimizationProfile(
216
+ gc_threshold_0=profile.gc_threshold_0,
217
+ gc_threshold_1=profile.gc_threshold_1,
218
+ gc_threshold_2=profile.gc_threshold_2,
219
+ gc_freeze_enabled=profile.gc_freeze_enabled,
220
+ thread_pool_multiplier=profile.thread_pool_multiplier,
221
+ max_thread_pool_size=profile.max_thread_pool_size,
222
+ prefer_slots=profile.prefer_slots,
223
+ use_frozen_dataclasses=profile.use_frozen_dataclasses,
224
+ prefer_match_statements=profile.prefer_match_statements,
225
+ prefer_exception_groups=profile.prefer_exception_groups,
226
+ prefer_type_params=profile.prefer_type_params,
227
+ enable_perf_hints=profile.enable_perf_hints,
228
+ aggressive_inlining=profile.aggressive_inlining,
229
+ enable_experimental=True,
230
+ )
231
+ case _:
232
+ _cached_optimization_profile = profile
233
+
234
+ return _cached_optimization_profile
226
235
 
227
236
 
228
237
  # =============================================================================
@@ -294,6 +303,7 @@ def apply_optimizations(
294
303
  profile: OptimizationProfile | None = None,
295
304
  apply_gc: bool = True,
296
305
  freeze_after: bool = False,
306
+ force_refresh: bool = False,
297
307
  ) -> OptimizationResult:
298
308
  """Apply runtime optimizations based on profile.
299
309
 
@@ -304,13 +314,14 @@ def apply_optimizations(
304
314
  profile: Optimization profile to use (auto-detected if None).
305
315
  apply_gc: Whether to apply GC tuning.
306
316
  freeze_after: Whether to freeze objects after applying.
317
+ force_refresh: Whether to force re-detection of profile if none is provided.
307
318
 
308
319
  Returns:
309
320
  OptimizationResult with details of what was applied.
310
321
 
311
322
  """
312
323
  if profile is None:
313
- profile = get_optimization_profile()
324
+ profile = get_optimization_profile(force_refresh=force_refresh)
314
325
 
315
326
  applied: list[str] = []
316
327
  skipped: list[str] = []
@@ -356,14 +367,17 @@ def apply_optimizations(
356
367
  # =============================================================================
357
368
 
358
369
 
359
- def get_recommended_thread_pool_size() -> int:
370
+ def get_recommended_thread_pool_size(*, force_refresh: bool = False) -> int:
360
371
  """Get recommended thread pool size based on version and features.
361
372
 
373
+ Args:
374
+ force_refresh: If True, re-detect instead of using cache.
375
+
362
376
  Returns:
363
377
  Recommended number of threads for ThreadPoolExecutor.
364
378
 
365
379
  """
366
- profile = get_optimization_profile()
380
+ profile = get_optimization_profile(force_refresh=force_refresh)
367
381
  cpu_count = os.cpu_count() or 4
368
382
 
369
383
  size = int(cpu_count * profile.thread_pool_multiplier)