taipanstack 0.4.3__tar.gz → 0.4.5__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.
- {taipanstack-0.4.3 → taipanstack-0.4.5}/PKG-INFO +22 -22
- {taipanstack-0.4.3 → taipanstack-0.4.5}/README.md +21 -21
- {taipanstack-0.4.3 → taipanstack-0.4.5}/pyproject.toml +18 -11
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/__init__.py +1 -1
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/bridges/db_bridge.py +6 -6
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/bridges/http_bridge.py +14 -7
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/core/compat.py +2 -2
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/core/optimizations.py +33 -27
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/core/result.py +19 -10
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/resilience/adaptive/orchestrator.py +10 -17
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/resilience/circuit_breaker.py +150 -75
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/resilience/resilience.py +13 -14
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/resilience/retry.py +84 -18
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/resilience/watchdogs/_base.py +1 -1
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/resilience/watchdogs/config_watcher.py +41 -23
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/resilience/watchdogs/resource_watcher.py +2 -2
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/security/decorators.py +2 -2
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/security/guards.py +169 -79
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/security/jwt.py +10 -10
- taipanstack-0.4.5/src/taipanstack/security/models.py +178 -0
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/security/sanitizers.py +88 -71
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/security/validators.py +40 -27
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/utils/cache.py +41 -16
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/utils/concurrency.py +5 -5
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/utils/logging.py +1 -1
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/utils/rate_limit.py +37 -11
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/utils/subprocess.py +2 -2
- taipanstack-0.4.3/src/taipanstack/security/models.py +0 -110
- {taipanstack-0.4.3 → taipanstack-0.4.5}/LICENSE +0 -0
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/bridges/__init__.py +0 -0
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/bridges/_imports.py +0 -0
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/bridges/web_bridge.py +0 -0
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/config/__init__.py +0 -0
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/config/generators.py +0 -0
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/config/models.py +0 -0
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/config/version_config.py +0 -0
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/core/__init__.py +0 -0
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/resilience/__init__.py +0 -0
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/resilience/adaptive/__init__.py +0 -0
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/resilience/adaptive/adaptive_breaker.py +0 -0
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/resilience/adaptive/adaptive_retry.py +0 -0
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/resilience/adaptive/bulkhead.py +0 -0
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/resilience/watchdogs/__init__.py +0 -0
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/resilience/watchdogs/health_pinger.py +0 -0
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/security/__init__.py +0 -0
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/security/password.py +0 -0
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/security/types.py +0 -0
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/utils/__init__.py +0 -0
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/utils/circuit_breaker.py +0 -0
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/utils/context.py +0 -0
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/utils/filesystem.py +0 -0
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/utils/resilience.py +0 -0
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/utils/retry.py +0 -0
- {taipanstack-0.4.3 → taipanstack-0.4.5}/src/taipanstack/utils/serialization.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: taipanstack
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.5
|
|
4
4
|
Summary: TaipanStack - Modular, secure, and scalable Python stack for robust development
|
|
5
5
|
License-Expression: MIT
|
|
6
6
|
License-File: LICENSE
|
|
@@ -56,13 +56,12 @@ Description-Content-Type: text/markdown
|
|
|
56
56
|
|
|
57
57
|
<div align="center">
|
|
58
58
|
|
|
59
|
-
# 🐍
|
|
59
|
+
# 🐍 Taipan Stack
|
|
60
60
|
|
|
61
61
|
### **The Modern Python Foundation**
|
|
62
62
|
|
|
63
63
|
*Launch secure, high-performance Python applications in seconds.*
|
|
64
64
|
|
|
65
|
-
[](https://github.com/gabrielima7/TaipanStack/actions/workflows/ci.yml)
|
|
66
65
|
[](https://www.python.org/)
|
|
67
66
|
[](https://github.com/gabrielima7/TaipanStack)
|
|
68
67
|
[](https://github.com/astral-sh/ruff)
|
|
@@ -81,16 +80,18 @@ Description-Content-Type: text/markdown
|
|
|
81
80
|
|
|
82
81
|
---
|
|
83
82
|
|
|
84
|
-
## ✨ Why
|
|
83
|
+
## ✨ Why Taipan Stack?
|
|
85
84
|
|
|
86
85
|
> **"Write less, build better."**
|
|
87
86
|
|
|
88
|
-
|
|
87
|
+
Taipan Stack is a battle-tested foundation for production-grade Python projects that combines **security**, **performance**, and **developer experience** into a single, cohesive toolkit.
|
|
89
88
|
|
|
90
|
-
### ✨ What's New in v0.4.
|
|
91
|
-
- **
|
|
92
|
-
- **
|
|
93
|
-
- **
|
|
89
|
+
### ✨ What's New in v0.4.5
|
|
90
|
+
- **100% Genuine Coverage**: Achieved the milestone of **true 100% code coverage** without a single `pragma: no cover` bypass (PR #636).
|
|
91
|
+
- **Security Hardening**: Reinforced `RateLimiter` and `CircuitBreaker` against state corruption and `NaN` poisoning (PR #622, #630).
|
|
92
|
+
- **Strict Typing**: Eliminated remaining `Any` usage and resolved all `type: ignore` directives for a pure strictly-typed codebase (PR #624).
|
|
93
|
+
- **Refactoring**: Significantly reduced cyclomatic complexity across core security and resilience modules.
|
|
94
|
+
- **Total Stack Coverage**: Reached **1,249 passing tests** with true 100% coverage across all core and bridge components.
|
|
94
95
|
|
|
95
96
|
<table>
|
|
96
97
|
<tr>
|
|
@@ -128,7 +129,7 @@ TaipanStack is a battle-tested foundation for production-grade Python projects t
|
|
|
128
129
|
|
|
129
130
|
### 🔧 Developer Experience
|
|
130
131
|
- Pre-configured quality tools
|
|
131
|
-
- **100% code coverage** (
|
|
132
|
+
- **100% code coverage** (1249 tests)
|
|
132
133
|
- Architecture enforcement
|
|
133
134
|
- Hardened Docker template
|
|
134
135
|
|
|
@@ -170,7 +171,7 @@ make all
|
|
|
170
171
|
### Verify Installation
|
|
171
172
|
|
|
172
173
|
```bash
|
|
173
|
-
# Run tests with 100% coverage (
|
|
174
|
+
# Run tests with 100% coverage (1249 tests)
|
|
174
175
|
make test
|
|
175
176
|
|
|
176
177
|
# Check architecture contracts
|
|
@@ -190,7 +191,7 @@ make benchmark
|
|
|
190
191
|
|
|
191
192
|
## 📐 Architecture
|
|
192
193
|
|
|
193
|
-
|
|
194
|
+
Taipan Stack follows a clean, layered architecture with strict dependency rules enforced by **Import Linter**.
|
|
194
195
|
|
|
195
196
|
```
|
|
196
197
|
┌─────────────────────────────────────┐
|
|
@@ -225,7 +226,7 @@ TaipanStack/
|
|
|
225
226
|
│ ├── config/ # ⚙️ Configuration models & generators
|
|
226
227
|
│ ├── security/ # 🛡️ Guards, sanitizers, validators
|
|
227
228
|
│ └── utils/ # 🔧 Logging, metrics, retry, filesystem
|
|
228
|
-
├── tests/ # ✅
|
|
229
|
+
├── tests/ # ✅ 1249 tests, 100% coverage
|
|
229
230
|
├── .semgrep/ # 🔍 Custom SAST rules
|
|
230
231
|
├── .github/ # 🔄 CI/CD + SBOM/SLSA workflows
|
|
231
232
|
├── Dockerfile # 🐳 Hardened multi-stage container
|
|
@@ -236,7 +237,7 @@ TaipanStack/
|
|
|
236
237
|
|
|
237
238
|
## 🔐 DevSecOps
|
|
238
239
|
|
|
239
|
-
|
|
240
|
+
Taipan Stack integrates security and quality at every level:
|
|
240
241
|
|
|
241
242
|
| Category | Tools | Purpose |
|
|
242
243
|
|----------|-------|---------|
|
|
@@ -304,7 +305,7 @@ safe_cmd = guard_command_injection(
|
|
|
304
305
|
### Retry with Exponential Backoff
|
|
305
306
|
|
|
306
307
|
```python
|
|
307
|
-
from taipanstack.
|
|
308
|
+
from taipanstack.resilience.retry import retry
|
|
308
309
|
|
|
309
310
|
@retry(max_attempts=3, on=(ConnectionError, TimeoutError))
|
|
310
311
|
async def fetch_data(url: str) -> dict:
|
|
@@ -314,7 +315,7 @@ async def fetch_data(url: str) -> dict:
|
|
|
314
315
|
### Circuit Breaker
|
|
315
316
|
|
|
316
317
|
```python
|
|
317
|
-
from taipanstack.
|
|
318
|
+
from taipanstack.resilience.circuit_breaker import circuit_breaker
|
|
318
319
|
|
|
319
320
|
@circuit_breaker(failure_threshold=5, timeout=30)
|
|
320
321
|
def call_external_service() -> Response:
|
|
@@ -325,7 +326,7 @@ def call_external_service() -> Response:
|
|
|
325
326
|
|
|
326
327
|
```python
|
|
327
328
|
from taipanstack.core.result import safe, Ok, Err
|
|
328
|
-
from taipanstack.
|
|
329
|
+
from taipanstack.resilience.circuit_breaker import CircuitBreaker
|
|
329
330
|
|
|
330
331
|
breaker = CircuitBreaker(failure_threshold=3, timeout=60, name="payments")
|
|
331
332
|
|
|
@@ -347,7 +348,7 @@ match result:
|
|
|
347
348
|
|
|
348
349
|
```python
|
|
349
350
|
from taipanstack.core.result import safe, unwrap_or
|
|
350
|
-
from taipanstack.
|
|
351
|
+
from taipanstack.resilience.retry import retry
|
|
351
352
|
|
|
352
353
|
@retry(
|
|
353
354
|
max_attempts=3,
|
|
@@ -368,7 +369,7 @@ profile = unwrap_or(fetch_user_profile("usr_456"), {"name": "Unknown"})
|
|
|
368
369
|
|
|
369
370
|
```python
|
|
370
371
|
from taipanstack.core.result import Result, Ok, Err
|
|
371
|
-
from taipanstack.resilience.adaptive import ResilienceOrchestrator, AdaptiveCircuitBreaker
|
|
372
|
+
from taipanstack.resilience.adaptive import ResilienceOrchestrator, AdaptiveCircuitBreaker
|
|
372
373
|
from taipanstack.resilience.retry import RetryConfig
|
|
373
374
|
|
|
374
375
|
# Compose an intelligent pipeline: Bulkhead -> Breaker -> Retry -> Timeout -> Fallback
|
|
@@ -376,7 +377,6 @@ orch = (
|
|
|
376
377
|
ResilienceOrchestrator("billing_api")
|
|
377
378
|
.with_bulkhead(max_concurrent=10, max_queue=50) # Prevent resource exhaustion
|
|
378
379
|
.with_circuit_breaker(AdaptiveCircuitBreaker("billing", target_error_rate=0.1)) # Auto-tunes thresholds
|
|
379
|
-
.with_timeout(AdaptiveTimeout(min_timeout=1.0, max_timeout=10.0))
|
|
380
380
|
.with_retry(RetryConfig(max_attempts=3, initial_delay=0.1))
|
|
381
381
|
.with_fallback({"status": "unavailable"})
|
|
382
382
|
)
|
|
@@ -400,10 +400,10 @@ async def get_user_data(user_id: int) -> Result[dict, Exception]:
|
|
|
400
400
|
### Fallbacks & Timeouts
|
|
401
401
|
|
|
402
402
|
```python
|
|
403
|
-
from taipanstack.
|
|
403
|
+
from taipanstack.resilience.resilience import fallback, timeout
|
|
404
404
|
from taipanstack.core.result import Result
|
|
405
405
|
|
|
406
|
-
@fallback(
|
|
406
|
+
@fallback({"status": "offline"}, exceptions=(TimeoutError,))
|
|
407
407
|
@timeout(seconds=5.0)
|
|
408
408
|
async def fetch_remote_status() -> Result[dict, Exception]:
|
|
409
409
|
return await api.get_status()
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
|
|
3
|
-
# 🐍
|
|
3
|
+
# 🐍 Taipan Stack
|
|
4
4
|
|
|
5
5
|
### **The Modern Python Foundation**
|
|
6
6
|
|
|
7
7
|
*Launch secure, high-performance Python applications in seconds.*
|
|
8
8
|
|
|
9
|
-
[](https://github.com/gabrielima7/TaipanStack/actions/workflows/ci.yml)
|
|
10
9
|
[](https://www.python.org/)
|
|
11
10
|
[](https://github.com/gabrielima7/TaipanStack)
|
|
12
11
|
[](https://github.com/astral-sh/ruff)
|
|
@@ -25,16 +24,18 @@
|
|
|
25
24
|
|
|
26
25
|
---
|
|
27
26
|
|
|
28
|
-
## ✨ Why
|
|
27
|
+
## ✨ Why Taipan Stack?
|
|
29
28
|
|
|
30
29
|
> **"Write less, build better."**
|
|
31
30
|
|
|
32
|
-
|
|
31
|
+
Taipan Stack is a battle-tested foundation for production-grade Python projects that combines **security**, **performance**, and **developer experience** into a single, cohesive toolkit.
|
|
33
32
|
|
|
34
|
-
### ✨ What's New in v0.4.
|
|
35
|
-
- **
|
|
36
|
-
- **
|
|
37
|
-
- **
|
|
33
|
+
### ✨ What's New in v0.4.5
|
|
34
|
+
- **100% Genuine Coverage**: Achieved the milestone of **true 100% code coverage** without a single `pragma: no cover` bypass (PR #636).
|
|
35
|
+
- **Security Hardening**: Reinforced `RateLimiter` and `CircuitBreaker` against state corruption and `NaN` poisoning (PR #622, #630).
|
|
36
|
+
- **Strict Typing**: Eliminated remaining `Any` usage and resolved all `type: ignore` directives for a pure strictly-typed codebase (PR #624).
|
|
37
|
+
- **Refactoring**: Significantly reduced cyclomatic complexity across core security and resilience modules.
|
|
38
|
+
- **Total Stack Coverage**: Reached **1,249 passing tests** with true 100% coverage across all core and bridge components.
|
|
38
39
|
|
|
39
40
|
<table>
|
|
40
41
|
<tr>
|
|
@@ -72,7 +73,7 @@ TaipanStack is a battle-tested foundation for production-grade Python projects t
|
|
|
72
73
|
|
|
73
74
|
### 🔧 Developer Experience
|
|
74
75
|
- Pre-configured quality tools
|
|
75
|
-
- **100% code coverage** (
|
|
76
|
+
- **100% code coverage** (1249 tests)
|
|
76
77
|
- Architecture enforcement
|
|
77
78
|
- Hardened Docker template
|
|
78
79
|
|
|
@@ -114,7 +115,7 @@ make all
|
|
|
114
115
|
### Verify Installation
|
|
115
116
|
|
|
116
117
|
```bash
|
|
117
|
-
# Run tests with 100% coverage (
|
|
118
|
+
# Run tests with 100% coverage (1249 tests)
|
|
118
119
|
make test
|
|
119
120
|
|
|
120
121
|
# Check architecture contracts
|
|
@@ -134,7 +135,7 @@ make benchmark
|
|
|
134
135
|
|
|
135
136
|
## 📐 Architecture
|
|
136
137
|
|
|
137
|
-
|
|
138
|
+
Taipan Stack follows a clean, layered architecture with strict dependency rules enforced by **Import Linter**.
|
|
138
139
|
|
|
139
140
|
```
|
|
140
141
|
┌─────────────────────────────────────┐
|
|
@@ -169,7 +170,7 @@ TaipanStack/
|
|
|
169
170
|
│ ├── config/ # ⚙️ Configuration models & generators
|
|
170
171
|
│ ├── security/ # 🛡️ Guards, sanitizers, validators
|
|
171
172
|
│ └── utils/ # 🔧 Logging, metrics, retry, filesystem
|
|
172
|
-
├── tests/ # ✅
|
|
173
|
+
├── tests/ # ✅ 1249 tests, 100% coverage
|
|
173
174
|
├── .semgrep/ # 🔍 Custom SAST rules
|
|
174
175
|
├── .github/ # 🔄 CI/CD + SBOM/SLSA workflows
|
|
175
176
|
├── Dockerfile # 🐳 Hardened multi-stage container
|
|
@@ -180,7 +181,7 @@ TaipanStack/
|
|
|
180
181
|
|
|
181
182
|
## 🔐 DevSecOps
|
|
182
183
|
|
|
183
|
-
|
|
184
|
+
Taipan Stack integrates security and quality at every level:
|
|
184
185
|
|
|
185
186
|
| Category | Tools | Purpose |
|
|
186
187
|
|----------|-------|---------|
|
|
@@ -248,7 +249,7 @@ safe_cmd = guard_command_injection(
|
|
|
248
249
|
### Retry with Exponential Backoff
|
|
249
250
|
|
|
250
251
|
```python
|
|
251
|
-
from taipanstack.
|
|
252
|
+
from taipanstack.resilience.retry import retry
|
|
252
253
|
|
|
253
254
|
@retry(max_attempts=3, on=(ConnectionError, TimeoutError))
|
|
254
255
|
async def fetch_data(url: str) -> dict:
|
|
@@ -258,7 +259,7 @@ async def fetch_data(url: str) -> dict:
|
|
|
258
259
|
### Circuit Breaker
|
|
259
260
|
|
|
260
261
|
```python
|
|
261
|
-
from taipanstack.
|
|
262
|
+
from taipanstack.resilience.circuit_breaker import circuit_breaker
|
|
262
263
|
|
|
263
264
|
@circuit_breaker(failure_threshold=5, timeout=30)
|
|
264
265
|
def call_external_service() -> Response:
|
|
@@ -269,7 +270,7 @@ def call_external_service() -> Response:
|
|
|
269
270
|
|
|
270
271
|
```python
|
|
271
272
|
from taipanstack.core.result import safe, Ok, Err
|
|
272
|
-
from taipanstack.
|
|
273
|
+
from taipanstack.resilience.circuit_breaker import CircuitBreaker
|
|
273
274
|
|
|
274
275
|
breaker = CircuitBreaker(failure_threshold=3, timeout=60, name="payments")
|
|
275
276
|
|
|
@@ -291,7 +292,7 @@ match result:
|
|
|
291
292
|
|
|
292
293
|
```python
|
|
293
294
|
from taipanstack.core.result import safe, unwrap_or
|
|
294
|
-
from taipanstack.
|
|
295
|
+
from taipanstack.resilience.retry import retry
|
|
295
296
|
|
|
296
297
|
@retry(
|
|
297
298
|
max_attempts=3,
|
|
@@ -312,7 +313,7 @@ profile = unwrap_or(fetch_user_profile("usr_456"), {"name": "Unknown"})
|
|
|
312
313
|
|
|
313
314
|
```python
|
|
314
315
|
from taipanstack.core.result import Result, Ok, Err
|
|
315
|
-
from taipanstack.resilience.adaptive import ResilienceOrchestrator, AdaptiveCircuitBreaker
|
|
316
|
+
from taipanstack.resilience.adaptive import ResilienceOrchestrator, AdaptiveCircuitBreaker
|
|
316
317
|
from taipanstack.resilience.retry import RetryConfig
|
|
317
318
|
|
|
318
319
|
# Compose an intelligent pipeline: Bulkhead -> Breaker -> Retry -> Timeout -> Fallback
|
|
@@ -320,7 +321,6 @@ orch = (
|
|
|
320
321
|
ResilienceOrchestrator("billing_api")
|
|
321
322
|
.with_bulkhead(max_concurrent=10, max_queue=50) # Prevent resource exhaustion
|
|
322
323
|
.with_circuit_breaker(AdaptiveCircuitBreaker("billing", target_error_rate=0.1)) # Auto-tunes thresholds
|
|
323
|
-
.with_timeout(AdaptiveTimeout(min_timeout=1.0, max_timeout=10.0))
|
|
324
324
|
.with_retry(RetryConfig(max_attempts=3, initial_delay=0.1))
|
|
325
325
|
.with_fallback({"status": "unavailable"})
|
|
326
326
|
)
|
|
@@ -344,10 +344,10 @@ async def get_user_data(user_id: int) -> Result[dict, Exception]:
|
|
|
344
344
|
### Fallbacks & Timeouts
|
|
345
345
|
|
|
346
346
|
```python
|
|
347
|
-
from taipanstack.
|
|
347
|
+
from taipanstack.resilience.resilience import fallback, timeout
|
|
348
348
|
from taipanstack.core.result import Result
|
|
349
349
|
|
|
350
|
-
@fallback(
|
|
350
|
+
@fallback({"status": "offline"}, exceptions=(TimeoutError,))
|
|
351
351
|
@timeout(seconds=5.0)
|
|
352
352
|
async def fetch_remote_status() -> Result[dict, Exception]:
|
|
353
353
|
return await api.get_status()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "taipanstack"
|
|
3
|
-
version = "0.4.
|
|
3
|
+
version = "0.4.5"
|
|
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"}
|
|
@@ -84,17 +84,15 @@ dev = [
|
|
|
84
84
|
"mypy (>=1.10.0)",
|
|
85
85
|
"bandit (>=1.7.0)",
|
|
86
86
|
"pre-commit (>=3.7.0)",
|
|
87
|
-
"pytest (>=
|
|
87
|
+
"pytest (>=9.0.3)",
|
|
88
88
|
"pytest-cov (>=5.0.0)",
|
|
89
89
|
"pytest-timeout (>=2.3.0)",
|
|
90
90
|
"pytest-xdist (>=3.6.0)",
|
|
91
91
|
"vulture (>=2.11)",
|
|
92
|
-
"interrogate (>=1.5.0)",
|
|
93
92
|
"polyfactory (>=2.0.0)",
|
|
94
93
|
"structlog (>=25.5.0,<26.0.0)",
|
|
95
94
|
"import-linter (>=2.1)",
|
|
96
95
|
"gitingest (>=0.1.0)",
|
|
97
|
-
"mutmut (>=3.0.0)",
|
|
98
96
|
"pytest-benchmark (>=5.0.0)",
|
|
99
97
|
"pytest-asyncio (>=0.23.0)",
|
|
100
98
|
"radon (>=6.0.1,<7.0.0)",
|
|
@@ -106,7 +104,22 @@ dev = [
|
|
|
106
104
|
# CVSS 1.9/10 Low - local attack vector only, no upstream patch available yet
|
|
107
105
|
# Pinned to latest available; monitor for upstream fix in pygments >2.19.2
|
|
108
106
|
"pygments (>=2.19.2)",
|
|
107
|
+
# Security note: CVE-2026-3219 affects pip 26.0.1 (confused install via concatenated tar+ZIP).
|
|
108
|
+
# CVSS Moderate - no pip fix published yet (expected in pip>=26.1).
|
|
109
|
+
# pip-audit ignores this CVE explicitly via --ignore-vuln in CI and Makefile.
|
|
110
|
+
# Monitor: https://github.com/pypa/pip/issues — Remove ignore once pip>=26.1 is available.
|
|
111
|
+
#
|
|
112
|
+
# Security note: PYSEC-2022-42969 affects py 1.11.0 (ReDoS via svn blame parsing).
|
|
113
|
+
# py is a transitive dependency of pytest with no upstream fix version published.
|
|
114
|
+
# Attack vector is local (requires attacker-controlled SVN output). Low real-world risk.
|
|
115
|
+
# pip-audit ignores this via --ignore-vuln in CI and Makefile.
|
|
116
|
+
# Monitor: https://github.com/pytest-dev/py/issues — Remove ignore if fix is published.
|
|
109
117
|
"hypothesis (>=6.151.12,<7.0.0)",
|
|
118
|
+
"authlib (>=1.6.11,<2.0.0)",
|
|
119
|
+
"cryptography (>=46.0.7,<47.0.0)",
|
|
120
|
+
"nltk (>=3.9.4,<4.0.0)",
|
|
121
|
+
"mutmut (>=3.0.0,<4.0.0)",
|
|
122
|
+
"pip (>=26.1,<27.0)",
|
|
110
123
|
]
|
|
111
124
|
|
|
112
125
|
|
|
@@ -259,16 +272,10 @@ min_confidence = 80
|
|
|
259
272
|
paths = ["src"]
|
|
260
273
|
exclude = ["tests"]
|
|
261
274
|
|
|
262
|
-
[tool.interrogate]
|
|
263
|
-
ignore-init-module = true
|
|
264
|
-
ignore-private = true
|
|
265
|
-
ignore-semiprivate = true
|
|
266
|
-
fail-under = 80
|
|
267
|
-
verbose = 1
|
|
268
275
|
|
|
269
276
|
[tool.mutmut]
|
|
270
277
|
paths_to_mutate = ["src/taipanstack/security/sanitizers.py", "src/taipanstack/security/validators.py", "src/taipanstack/security/guards.py", "src/taipanstack/resilience/retry.py", "src/taipanstack/resilience/circuit_breaker.py"]
|
|
271
|
-
tests_dir = ["tests/
|
|
278
|
+
tests_dir = ["tests/test_property_sanitizers_operations_expected.py", "tests/test_security_validators_operations_expected.py", "tests/test_security_guards_operations_expected.py", "tests/test_security_ssrf_operations_expected.py", "tests/test_utils_retry_operations_expected.py", "tests/test_utils_circuit_breaker_operations_expected.py"]
|
|
272
279
|
also_copy = ["src/"]
|
|
273
280
|
runner = "python -m pytest -x -q --tb=no --timeout=10 --no-cov"
|
|
274
281
|
dict_synonyms = "Struct, NamedStruct"
|
|
@@ -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.4.
|
|
8
|
+
__version__ = "0.4.5"
|
|
9
9
|
|
|
10
10
|
from taipanstack.config.version_config import (
|
|
11
11
|
VersionRecommendations,
|
|
@@ -25,18 +25,18 @@ logger = logging.getLogger("taipanstack.bridges.db")
|
|
|
25
25
|
|
|
26
26
|
try:
|
|
27
27
|
import sqlalchemy # noqa: F401
|
|
28
|
-
from sqlalchemy import text as sa_text
|
|
29
|
-
from sqlalchemy.ext.asyncio import AsyncSession
|
|
28
|
+
from sqlalchemy import text as sa_text
|
|
29
|
+
from sqlalchemy.ext.asyncio import AsyncSession
|
|
30
30
|
|
|
31
|
-
_HAS_SQLALCHEMY = True
|
|
32
|
-
except ImportError:
|
|
31
|
+
_HAS_SQLALCHEMY = True
|
|
32
|
+
except ImportError:
|
|
33
33
|
_HAS_SQLALCHEMY = False
|
|
34
34
|
|
|
35
35
|
try:
|
|
36
36
|
import redis.asyncio as aioredis
|
|
37
37
|
|
|
38
|
-
_HAS_REDIS = True
|
|
39
|
-
except ImportError:
|
|
38
|
+
_HAS_REDIS = True
|
|
39
|
+
except ImportError:
|
|
40
40
|
_HAS_REDIS = False
|
|
41
41
|
|
|
42
42
|
if TYPE_CHECKING:
|
|
@@ -11,7 +11,7 @@ from __future__ import annotations
|
|
|
11
11
|
import asyncio
|
|
12
12
|
import logging
|
|
13
13
|
from collections.abc import Awaitable, Callable, Mapping, Sequence
|
|
14
|
-
from typing import TYPE_CHECKING
|
|
14
|
+
from typing import TYPE_CHECKING, cast
|
|
15
15
|
|
|
16
16
|
from typing_extensions import TypedDict, Unpack
|
|
17
17
|
|
|
@@ -80,8 +80,8 @@ class HttpClientKwargs(TypedDict, total=False):
|
|
|
80
80
|
try:
|
|
81
81
|
import httpx
|
|
82
82
|
|
|
83
|
-
_HAS_HTTPX = True
|
|
84
|
-
except ImportError:
|
|
83
|
+
_HAS_HTTPX = True
|
|
84
|
+
except ImportError:
|
|
85
85
|
_HAS_HTTPX = False
|
|
86
86
|
|
|
87
87
|
if TYPE_CHECKING:
|
|
@@ -196,7 +196,8 @@ async def _execute_with_retries(
|
|
|
196
196
|
attempt,
|
|
197
197
|
max_attempts,
|
|
198
198
|
):
|
|
199
|
-
|
|
199
|
+
# Config is not None if we reach here
|
|
200
|
+
delay = calculate_delay(attempt, cast(RetryConfig, retry_config))
|
|
200
201
|
await asyncio.sleep(min(delay, 3600.0))
|
|
201
202
|
continue
|
|
202
203
|
return Ok(response)
|
|
@@ -260,7 +261,10 @@ async def safe_request(
|
|
|
260
261
|
|
|
261
262
|
async def _do_request() -> httpx.Response:
|
|
262
263
|
async with httpx.AsyncClient(timeout=timeout) as client: # nosemgrep
|
|
263
|
-
|
|
264
|
+
request_func = cast(
|
|
265
|
+
Callable[..., Awaitable[httpx.Response]], client.request
|
|
266
|
+
)
|
|
267
|
+
response = await request_func(method, url, **kwargs)
|
|
264
268
|
return response
|
|
265
269
|
|
|
266
270
|
return await _execute_with_retries(
|
|
@@ -377,8 +381,11 @@ class SafeHttpClient:
|
|
|
377
381
|
|
|
378
382
|
async def _do_request() -> httpx.Response:
|
|
379
383
|
# We explicitly verified client is not None above
|
|
380
|
-
client: httpx.AsyncClient = self._client
|
|
381
|
-
|
|
384
|
+
client: httpx.AsyncClient = cast(httpx.AsyncClient, self._client)
|
|
385
|
+
request_func = cast(
|
|
386
|
+
Callable[..., Awaitable[httpx.Response]], client.request
|
|
387
|
+
)
|
|
388
|
+
response = await request_func(method, url, **kwargs)
|
|
382
389
|
return response
|
|
383
390
|
|
|
384
391
|
return await _execute_with_retries(
|
|
@@ -80,7 +80,7 @@ def _check_jit_available() -> bool:
|
|
|
80
80
|
|
|
81
81
|
JIT is available in Python 3.13+ when built with --enable-experimental-jit.
|
|
82
82
|
"""
|
|
83
|
-
if not PY313:
|
|
83
|
+
if not PY313:
|
|
84
84
|
return False
|
|
85
85
|
|
|
86
86
|
try:
|
|
@@ -96,7 +96,7 @@ def _check_free_threading_available() -> bool:
|
|
|
96
96
|
|
|
97
97
|
Free-threading is available in Python 3.13+ experimental builds.
|
|
98
98
|
"""
|
|
99
|
-
if not PY313:
|
|
99
|
+
if not PY313:
|
|
100
100
|
return False
|
|
101
101
|
|
|
102
102
|
try:
|
|
@@ -175,6 +175,37 @@ _PROFILE_314 = OptimizationProfile(
|
|
|
175
175
|
_cached_optimization_profile: OptimizationProfile | None = None
|
|
176
176
|
|
|
177
177
|
|
|
178
|
+
def _get_base_profile() -> OptimizationProfile:
|
|
179
|
+
"""Select base profile by version."""
|
|
180
|
+
if PY314:
|
|
181
|
+
return _PROFILE_314
|
|
182
|
+
if PY313:
|
|
183
|
+
return _PROFILE_313
|
|
184
|
+
if PY312:
|
|
185
|
+
return _PROFILE_312
|
|
186
|
+
return _PROFILE_311
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def _build_aggressive_profile(profile: OptimizationProfile) -> OptimizationProfile:
|
|
190
|
+
"""Build an aggressive optimization profile with experimental features."""
|
|
191
|
+
return OptimizationProfile(
|
|
192
|
+
gc_threshold_0=profile.gc_threshold_0,
|
|
193
|
+
gc_threshold_1=profile.gc_threshold_1,
|
|
194
|
+
gc_threshold_2=profile.gc_threshold_2,
|
|
195
|
+
gc_freeze_enabled=profile.gc_freeze_enabled,
|
|
196
|
+
thread_pool_multiplier=profile.thread_pool_multiplier,
|
|
197
|
+
max_thread_pool_size=profile.max_thread_pool_size,
|
|
198
|
+
prefer_slots=profile.prefer_slots,
|
|
199
|
+
use_frozen_dataclasses=profile.use_frozen_dataclasses,
|
|
200
|
+
prefer_match_statements=profile.prefer_match_statements,
|
|
201
|
+
prefer_exception_groups=profile.prefer_exception_groups,
|
|
202
|
+
prefer_type_params=profile.prefer_type_params,
|
|
203
|
+
enable_perf_hints=profile.enable_perf_hints,
|
|
204
|
+
aggressive_inlining=profile.aggressive_inlining,
|
|
205
|
+
enable_experimental=True,
|
|
206
|
+
)
|
|
207
|
+
|
|
208
|
+
|
|
178
209
|
def get_optimization_profile(*, force_refresh: bool = False) -> OptimizationProfile:
|
|
179
210
|
"""Get the optimization profile for the current Python version.
|
|
180
211
|
|
|
@@ -194,39 +225,14 @@ def get_optimization_profile(*, force_refresh: bool = False) -> OptimizationProf
|
|
|
194
225
|
experimental = is_experimental_enabled(force_refresh=force_refresh)
|
|
195
226
|
opt_level = get_optimization_level(force_refresh=force_refresh)
|
|
196
227
|
|
|
197
|
-
|
|
198
|
-
if PY314:
|
|
199
|
-
profile = _PROFILE_314
|
|
200
|
-
elif PY313:
|
|
201
|
-
profile = _PROFILE_313
|
|
202
|
-
elif PY312:
|
|
203
|
-
profile = _PROFILE_312
|
|
204
|
-
else:
|
|
205
|
-
profile = _PROFILE_311
|
|
228
|
+
profile = _get_base_profile()
|
|
206
229
|
|
|
207
230
|
# Adjust for optimization level
|
|
208
231
|
match opt_level:
|
|
209
232
|
case opt if opt == OPT_LEVEL_NONE:
|
|
210
|
-
# Minimal optimizations - use 3.11 baseline
|
|
211
233
|
_cached_optimization_profile = _PROFILE_311
|
|
212
234
|
case opt if opt == OPT_LEVEL_AGGRESSIVE and experimental:
|
|
213
|
-
|
|
214
|
-
_cached_optimization_profile = OptimizationProfile(
|
|
215
|
-
gc_threshold_0=profile.gc_threshold_0,
|
|
216
|
-
gc_threshold_1=profile.gc_threshold_1,
|
|
217
|
-
gc_threshold_2=profile.gc_threshold_2,
|
|
218
|
-
gc_freeze_enabled=profile.gc_freeze_enabled,
|
|
219
|
-
thread_pool_multiplier=profile.thread_pool_multiplier,
|
|
220
|
-
max_thread_pool_size=profile.max_thread_pool_size,
|
|
221
|
-
prefer_slots=profile.prefer_slots,
|
|
222
|
-
use_frozen_dataclasses=profile.use_frozen_dataclasses,
|
|
223
|
-
prefer_match_statements=profile.prefer_match_statements,
|
|
224
|
-
prefer_exception_groups=profile.prefer_exception_groups,
|
|
225
|
-
prefer_type_params=profile.prefer_type_params,
|
|
226
|
-
enable_perf_hints=profile.enable_perf_hints,
|
|
227
|
-
aggressive_inlining=profile.aggressive_inlining,
|
|
228
|
-
enable_experimental=True,
|
|
229
|
-
)
|
|
235
|
+
_cached_optimization_profile = _build_aggressive_profile(profile)
|
|
230
236
|
case _:
|
|
231
237
|
_cached_optimization_profile = profile
|
|
232
238
|
|
|
@@ -85,7 +85,13 @@ def safe(
|
|
|
85
85
|
Err(ValueError("invalid literal for int()..."))
|
|
86
86
|
|
|
87
87
|
"""
|
|
88
|
+
# Pre-cache constructors for minor speedup in tight loops
|
|
89
|
+
# (LOAD_DEREF is faster than LOAD_GLOBAL)
|
|
90
|
+
ok_cls = Ok
|
|
91
|
+
err_cls = Err
|
|
92
|
+
|
|
88
93
|
if inspect.iscoroutinefunction(func):
|
|
94
|
+
# Cast once here to satisfy mypy inside the closure
|
|
89
95
|
func_coro = cast(Callable[P, Awaitable[T]], func)
|
|
90
96
|
|
|
91
97
|
@functools.wraps(func)
|
|
@@ -94,20 +100,21 @@ def safe(
|
|
|
94
100
|
**kwargs: P.kwargs,
|
|
95
101
|
) -> Result[T, Exception]:
|
|
96
102
|
try:
|
|
97
|
-
return
|
|
103
|
+
return ok_cls(await func_coro(*args, **kwargs))
|
|
98
104
|
except Exception as e:
|
|
99
|
-
return
|
|
105
|
+
return err_cls(e)
|
|
100
106
|
|
|
101
107
|
return cast(Callable[P, Awaitable[Result[T, Exception]]], async_wrapper)
|
|
102
108
|
|
|
109
|
+
# Cast once here to satisfy mypy inside the closure
|
|
103
110
|
func_sync = cast(Callable[P, T], func)
|
|
104
111
|
|
|
105
112
|
@functools.wraps(func)
|
|
106
113
|
def wrapper(*args: P.args, **kwargs: P.kwargs) -> Result[T, Exception]:
|
|
107
114
|
try:
|
|
108
|
-
return
|
|
115
|
+
return ok_cls(func_sync(*args, **kwargs))
|
|
109
116
|
except Exception as e:
|
|
110
|
-
return
|
|
117
|
+
return err_cls(e)
|
|
111
118
|
|
|
112
119
|
return cast(Callable[P, Result[T, Exception]], wrapper)
|
|
113
120
|
|
|
@@ -202,19 +209,21 @@ def collect_results(
|
|
|
202
209
|
except AttributeError:
|
|
203
210
|
pass
|
|
204
211
|
|
|
212
|
+
ok_cls = Ok
|
|
213
|
+
err_cls = Err
|
|
205
214
|
values: list[T] = []
|
|
206
215
|
append = values.append
|
|
207
216
|
for result in results:
|
|
208
|
-
# We
|
|
209
|
-
#
|
|
210
|
-
|
|
211
|
-
if isinstance(result, Ok):
|
|
217
|
+
# We use explicit type checks (isinstance) but pre-cache the constructors.
|
|
218
|
+
# type(result) is ok_cls would be even faster but breaks subclassing.
|
|
219
|
+
if isinstance(result, ok_cls):
|
|
212
220
|
append(result.ok_value)
|
|
213
|
-
elif isinstance(result,
|
|
221
|
+
elif isinstance(result, err_cls):
|
|
214
222
|
return result
|
|
215
223
|
else:
|
|
224
|
+
# Fallback for structural compatibility
|
|
216
225
|
return result
|
|
217
|
-
return
|
|
226
|
+
return ok_cls(values)
|
|
218
227
|
|
|
219
228
|
|
|
220
229
|
@overload
|