devkitx 2.0.1__py3-none-any.whl → 2.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.
- devkitx/__init__.py +59 -56
- devkitx/_version.py +3 -3
- devkitx/async_bridge.py +103 -0
- devkitx/cli/__init__.py +5 -5
- devkitx/cli/main.py +349 -328
- devkitx/compliance/__init__.py +16 -14
- devkitx/compliance/audit_logger.py +298 -173
- devkitx/compliance/nist_controls.py +113 -113
- devkitx/compliance/pii_detector.py +150 -137
- devkitx/config.py +210 -0
- devkitx/http_client.py +147 -0
- devkitx/security/__init__.py +16 -15
- devkitx/security/crypto.py +150 -135
- devkitx/security/input_sanitizer.py +301 -108
- devkitx/security/secrets_scanner.py +125 -121
- devkitx/utils/__init__.py +18 -18
- devkitx/utils/json_utils.py +71 -70
- devkitx/utils/string_utils.py +124 -124
- devkitx/utils/time_utils.py +96 -97
- devkitx/utils/validation.py +77 -81
- {devkitx-2.0.1.dist-info → devkitx-2.1.0.dist-info}/METADATA +77 -34
- devkitx-2.1.0.dist-info/RECORD +25 -0
- {devkitx-2.0.1.dist-info → devkitx-2.1.0.dist-info}/WHEEL +1 -1
- devkitx-2.1.0.dist-info/licenses/LICENSE +0 -0
- devkitx-2.0.1.dist-info/RECORD +0 -21
- {devkitx-2.0.1.dist-info → devkitx-2.1.0.dist-info}/entry_points.txt +0 -0
devkitx/__init__.py
CHANGED
|
@@ -1,56 +1,59 @@
|
|
|
1
|
-
"""DevKitX - Security-first Python utilities for regulated environments.
|
|
2
|
-
|
|
3
|
-
This package provides security and compliance-focused utilities for government,
|
|
4
|
-
healthcare, and financial applications. Features include audit logging, PII detection,
|
|
5
|
-
secrets scanning, and secure defaults.
|
|
6
|
-
|
|
7
|
-
Core features:
|
|
8
|
-
- NIST 800-53 compliant audit logging
|
|
9
|
-
- PII detection and scanning
|
|
10
|
-
- Secrets scanning for hardcoded credentials
|
|
11
|
-
- Secure HTTP clients with production defaults
|
|
12
|
-
- Configuration management with secret detection
|
|
13
|
-
- Async/sync conversion utilities
|
|
14
|
-
|
|
15
|
-
Example:
|
|
16
|
-
>>> from devkitx.compliance import AuditLogger
|
|
17
|
-
>>> from devkitx.security import SecretsScanner
|
|
18
|
-
>>>
|
|
19
|
-
>>> # Audit logging
|
|
20
|
-
>>> logger = AuditLogger(service="my-api")
|
|
21
|
-
>>> logger.log_auth("user_login", user_id="123", outcome="success")
|
|
22
|
-
>>>
|
|
23
|
-
>>> # Security scanning
|
|
24
|
-
>>> scanner = SecretsScanner()
|
|
25
|
-
>>> matches = scanner.scan_directory("./src")
|
|
26
|
-
"""
|
|
27
|
-
|
|
28
|
-
from ._version import __version__
|
|
29
|
-
|
|
30
|
-
#
|
|
31
|
-
|
|
32
|
-
from
|
|
33
|
-
from
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
from .
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
"
|
|
44
|
-
#
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
#
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
#
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
|
|
1
|
+
"""DevKitX - Security-first Python utilities for regulated environments.
|
|
2
|
+
|
|
3
|
+
This package provides security and compliance-focused utilities for government,
|
|
4
|
+
healthcare, and financial applications. Features include audit logging, PII detection,
|
|
5
|
+
secrets scanning, and secure defaults.
|
|
6
|
+
|
|
7
|
+
Core features:
|
|
8
|
+
- NIST 800-53 compliant audit logging
|
|
9
|
+
- PII detection and scanning
|
|
10
|
+
- Secrets scanning for hardcoded credentials
|
|
11
|
+
- Secure HTTP clients with production defaults
|
|
12
|
+
- Configuration management with secret detection
|
|
13
|
+
- Async/sync conversion utilities
|
|
14
|
+
|
|
15
|
+
Example:
|
|
16
|
+
>>> from devkitx.compliance import AuditLogger
|
|
17
|
+
>>> from devkitx.security import SecretsScanner
|
|
18
|
+
>>>
|
|
19
|
+
>>> # Audit logging
|
|
20
|
+
>>> logger = AuditLogger(service="my-api")
|
|
21
|
+
>>> logger.log_auth("user_login", user_id="123", outcome="success")
|
|
22
|
+
>>>
|
|
23
|
+
>>> # Security scanning
|
|
24
|
+
>>> scanner = SecretsScanner()
|
|
25
|
+
>>> matches = scanner.scan_directory("./src")
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
from ._version import __version__
|
|
29
|
+
|
|
30
|
+
# Async, HTTP and config helpers (formerly the asyncbridge, httpx-defaults
|
|
31
|
+
# and configmerge packages; now part of devkitx)
|
|
32
|
+
from .async_bridge import async_to_sync, sync_to_async
|
|
33
|
+
from .config import load as load_config
|
|
34
|
+
from .config import merge as merge_config
|
|
35
|
+
from .http_client import AsyncClient as SecureAsyncClient
|
|
36
|
+
from .http_client import Client as SecureClient
|
|
37
|
+
|
|
38
|
+
# Core utilities
|
|
39
|
+
from .utils.json_utils import flatten_json
|
|
40
|
+
from .utils.string_utils import to_camel_case, to_kebab_case, to_pascal_case, to_snake_case
|
|
41
|
+
|
|
42
|
+
__all__ = [
|
|
43
|
+
"__version__",
|
|
44
|
+
# Async utilities
|
|
45
|
+
"async_to_sync",
|
|
46
|
+
"sync_to_async",
|
|
47
|
+
# HTTP utilities
|
|
48
|
+
"SecureClient",
|
|
49
|
+
"SecureAsyncClient",
|
|
50
|
+
# Config utilities
|
|
51
|
+
"load_config",
|
|
52
|
+
"merge_config",
|
|
53
|
+
# Core utilities
|
|
54
|
+
"flatten_json",
|
|
55
|
+
"to_snake_case",
|
|
56
|
+
"to_camel_case",
|
|
57
|
+
"to_pascal_case",
|
|
58
|
+
"to_kebab_case",
|
|
59
|
+
]
|
devkitx/_version.py
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"""Version information for DevKitX."""
|
|
2
|
-
|
|
3
|
-
__version__ = "2.0
|
|
1
|
+
"""Version information for DevKitX."""
|
|
2
|
+
|
|
3
|
+
__version__ = "2.1.0"
|
devkitx/async_bridge.py
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"""Simple, reliable async/sync conversion for Python.
|
|
2
|
+
|
|
3
|
+
Folded into devkitx from the standalone `asyncbridge` 1.0.0 package
|
|
4
|
+
(MIT, same author). Public names are unchanged.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import asyncio
|
|
10
|
+
import functools
|
|
11
|
+
from collections.abc import Callable, Coroutine
|
|
12
|
+
from concurrent.futures import ThreadPoolExecutor
|
|
13
|
+
from typing import Any, ParamSpec, TypeVar
|
|
14
|
+
|
|
15
|
+
__all__ = ["async_to_sync", "sync_to_async"]
|
|
16
|
+
|
|
17
|
+
P = ParamSpec("P")
|
|
18
|
+
R = TypeVar("R")
|
|
19
|
+
|
|
20
|
+
_executor = ThreadPoolExecutor(max_workers=10)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def async_to_sync(func: Callable[P, Coroutine[Any, Any, R]]) -> Callable[P, R]:
|
|
24
|
+
"""Convert an async function to sync.
|
|
25
|
+
|
|
26
|
+
Handles event loop detection and creation correctly:
|
|
27
|
+
- If no loop is running, creates a new one
|
|
28
|
+
- If a loop is running, uses run_in_executor to avoid conflicts
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
func: Async function to convert
|
|
32
|
+
|
|
33
|
+
Returns:
|
|
34
|
+
Synchronous wrapper function
|
|
35
|
+
|
|
36
|
+
Example:
|
|
37
|
+
>>> @async_to_sync
|
|
38
|
+
... async def fetch_data():
|
|
39
|
+
... await asyncio.sleep(0.1)
|
|
40
|
+
... return "data"
|
|
41
|
+
>>> result = fetch_data() # Blocks until complete
|
|
42
|
+
>>> print(result)
|
|
43
|
+
'data'
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
@functools.wraps(func)
|
|
47
|
+
def wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
|
|
48
|
+
coro = func(*args, **kwargs)
|
|
49
|
+
|
|
50
|
+
try:
|
|
51
|
+
asyncio.get_running_loop()
|
|
52
|
+
except RuntimeError:
|
|
53
|
+
# No running loop - safe to use asyncio.run()
|
|
54
|
+
return asyncio.run(coro)
|
|
55
|
+
|
|
56
|
+
# Loop is running - we need to run in a new thread
|
|
57
|
+
import concurrent.futures
|
|
58
|
+
|
|
59
|
+
def run_in_new_loop() -> R:
|
|
60
|
+
new_loop = asyncio.new_event_loop()
|
|
61
|
+
try:
|
|
62
|
+
return new_loop.run_until_complete(coro)
|
|
63
|
+
finally:
|
|
64
|
+
new_loop.close()
|
|
65
|
+
|
|
66
|
+
with concurrent.futures.ThreadPoolExecutor(max_workers=1) as executor:
|
|
67
|
+
future = executor.submit(run_in_new_loop)
|
|
68
|
+
return future.result()
|
|
69
|
+
|
|
70
|
+
return wrapper
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def sync_to_async(
|
|
74
|
+
func: Callable[P, R],
|
|
75
|
+
executor: ThreadPoolExecutor | None = None,
|
|
76
|
+
) -> Callable[P, Coroutine[Any, Any, R]]:
|
|
77
|
+
"""Convert a sync function to async.
|
|
78
|
+
|
|
79
|
+
Runs the sync function in a thread pool executor to avoid
|
|
80
|
+
blocking the event loop.
|
|
81
|
+
|
|
82
|
+
Args:
|
|
83
|
+
func: Sync function to convert
|
|
84
|
+
executor: Optional custom executor (uses default if not provided)
|
|
85
|
+
|
|
86
|
+
Returns:
|
|
87
|
+
Async wrapper function
|
|
88
|
+
|
|
89
|
+
Example:
|
|
90
|
+
>>> @sync_to_async
|
|
91
|
+
... def blocking_io():
|
|
92
|
+
... time.sleep(1)
|
|
93
|
+
... return "done"
|
|
94
|
+
>>> result = await blocking_io() # Doesn't block event loop
|
|
95
|
+
"""
|
|
96
|
+
pool = executor or _executor
|
|
97
|
+
|
|
98
|
+
@functools.wraps(func)
|
|
99
|
+
async def wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
|
|
100
|
+
loop = asyncio.get_running_loop()
|
|
101
|
+
return await loop.run_in_executor(pool, functools.partial(func, *args, **kwargs))
|
|
102
|
+
|
|
103
|
+
return wrapper
|
devkitx/cli/__init__.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"""DevKitX CLI module."""
|
|
2
|
-
|
|
3
|
-
from .main import main
|
|
4
|
-
|
|
5
|
-
__all__ = ["main"]
|
|
1
|
+
"""DevKitX CLI module."""
|
|
2
|
+
|
|
3
|
+
from .main import main
|
|
4
|
+
|
|
5
|
+
__all__ = ["main"]
|