kstlib 0.0.1a0__py3-none-any.whl → 1.0.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.
- kstlib/__init__.py +266 -1
- kstlib/__main__.py +16 -0
- kstlib/alerts/__init__.py +110 -0
- kstlib/alerts/channels/__init__.py +36 -0
- kstlib/alerts/channels/base.py +197 -0
- kstlib/alerts/channels/email.py +227 -0
- kstlib/alerts/channels/slack.py +389 -0
- kstlib/alerts/exceptions.py +72 -0
- kstlib/alerts/manager.py +651 -0
- kstlib/alerts/models.py +142 -0
- kstlib/alerts/throttle.py +263 -0
- kstlib/auth/__init__.py +139 -0
- kstlib/auth/callback.py +399 -0
- kstlib/auth/config.py +502 -0
- kstlib/auth/errors.py +127 -0
- kstlib/auth/models.py +316 -0
- kstlib/auth/providers/__init__.py +14 -0
- kstlib/auth/providers/base.py +393 -0
- kstlib/auth/providers/oauth2.py +645 -0
- kstlib/auth/providers/oidc.py +821 -0
- kstlib/auth/session.py +338 -0
- kstlib/auth/token.py +482 -0
- kstlib/cache/__init__.py +50 -0
- kstlib/cache/decorator.py +261 -0
- kstlib/cache/strategies.py +516 -0
- kstlib/cli/__init__.py +8 -0
- kstlib/cli/app.py +195 -0
- kstlib/cli/commands/__init__.py +5 -0
- kstlib/cli/commands/auth/__init__.py +39 -0
- kstlib/cli/commands/auth/common.py +122 -0
- kstlib/cli/commands/auth/login.py +325 -0
- kstlib/cli/commands/auth/logout.py +74 -0
- kstlib/cli/commands/auth/providers.py +57 -0
- kstlib/cli/commands/auth/status.py +291 -0
- kstlib/cli/commands/auth/token.py +199 -0
- kstlib/cli/commands/auth/whoami.py +106 -0
- kstlib/cli/commands/config.py +89 -0
- kstlib/cli/commands/ops/__init__.py +39 -0
- kstlib/cli/commands/ops/attach.py +49 -0
- kstlib/cli/commands/ops/common.py +269 -0
- kstlib/cli/commands/ops/list_sessions.py +252 -0
- kstlib/cli/commands/ops/logs.py +49 -0
- kstlib/cli/commands/ops/start.py +98 -0
- kstlib/cli/commands/ops/status.py +138 -0
- kstlib/cli/commands/ops/stop.py +60 -0
- kstlib/cli/commands/rapi/__init__.py +60 -0
- kstlib/cli/commands/rapi/call.py +341 -0
- kstlib/cli/commands/rapi/list.py +99 -0
- kstlib/cli/commands/rapi/show.py +206 -0
- kstlib/cli/commands/secrets/__init__.py +35 -0
- kstlib/cli/commands/secrets/common.py +425 -0
- kstlib/cli/commands/secrets/decrypt.py +88 -0
- kstlib/cli/commands/secrets/doctor.py +743 -0
- kstlib/cli/commands/secrets/encrypt.py +242 -0
- kstlib/cli/commands/secrets/shred.py +96 -0
- kstlib/cli/common.py +86 -0
- kstlib/config/__init__.py +76 -0
- kstlib/config/exceptions.py +110 -0
- kstlib/config/export.py +225 -0
- kstlib/config/loader.py +963 -0
- kstlib/config/sops.py +287 -0
- kstlib/db/__init__.py +54 -0
- kstlib/db/aiosqlcipher.py +137 -0
- kstlib/db/cipher.py +112 -0
- kstlib/db/database.py +367 -0
- kstlib/db/exceptions.py +25 -0
- kstlib/db/pool.py +302 -0
- kstlib/helpers/__init__.py +35 -0
- kstlib/helpers/exceptions.py +11 -0
- kstlib/helpers/time_trigger.py +396 -0
- kstlib/kstlib.conf.yml +890 -0
- kstlib/limits.py +963 -0
- kstlib/logging/__init__.py +108 -0
- kstlib/logging/manager.py +633 -0
- kstlib/mail/__init__.py +42 -0
- kstlib/mail/builder.py +626 -0
- kstlib/mail/exceptions.py +27 -0
- kstlib/mail/filesystem.py +248 -0
- kstlib/mail/transport.py +224 -0
- kstlib/mail/transports/__init__.py +19 -0
- kstlib/mail/transports/gmail.py +268 -0
- kstlib/mail/transports/resend.py +324 -0
- kstlib/mail/transports/smtp.py +326 -0
- kstlib/meta.py +72 -0
- kstlib/metrics/__init__.py +88 -0
- kstlib/metrics/decorators.py +1090 -0
- kstlib/metrics/exceptions.py +14 -0
- kstlib/monitoring/__init__.py +116 -0
- kstlib/monitoring/_styles.py +163 -0
- kstlib/monitoring/cell.py +57 -0
- kstlib/monitoring/config.py +424 -0
- kstlib/monitoring/delivery.py +579 -0
- kstlib/monitoring/exceptions.py +63 -0
- kstlib/monitoring/image.py +220 -0
- kstlib/monitoring/kv.py +79 -0
- kstlib/monitoring/list.py +69 -0
- kstlib/monitoring/metric.py +88 -0
- kstlib/monitoring/monitoring.py +341 -0
- kstlib/monitoring/renderer.py +139 -0
- kstlib/monitoring/service.py +392 -0
- kstlib/monitoring/table.py +129 -0
- kstlib/monitoring/types.py +56 -0
- kstlib/ops/__init__.py +86 -0
- kstlib/ops/base.py +148 -0
- kstlib/ops/container.py +577 -0
- kstlib/ops/exceptions.py +209 -0
- kstlib/ops/manager.py +407 -0
- kstlib/ops/models.py +176 -0
- kstlib/ops/tmux.py +372 -0
- kstlib/ops/validators.py +287 -0
- kstlib/py.typed +0 -0
- kstlib/rapi/__init__.py +118 -0
- kstlib/rapi/client.py +875 -0
- kstlib/rapi/config.py +861 -0
- kstlib/rapi/credentials.py +887 -0
- kstlib/rapi/exceptions.py +213 -0
- kstlib/resilience/__init__.py +101 -0
- kstlib/resilience/circuit_breaker.py +440 -0
- kstlib/resilience/exceptions.py +95 -0
- kstlib/resilience/heartbeat.py +491 -0
- kstlib/resilience/rate_limiter.py +506 -0
- kstlib/resilience/shutdown.py +417 -0
- kstlib/resilience/watchdog.py +637 -0
- kstlib/secrets/__init__.py +29 -0
- kstlib/secrets/exceptions.py +19 -0
- kstlib/secrets/models.py +62 -0
- kstlib/secrets/providers/__init__.py +79 -0
- kstlib/secrets/providers/base.py +58 -0
- kstlib/secrets/providers/environment.py +66 -0
- kstlib/secrets/providers/keyring.py +107 -0
- kstlib/secrets/providers/kms.py +223 -0
- kstlib/secrets/providers/kwargs.py +101 -0
- kstlib/secrets/providers/sops.py +209 -0
- kstlib/secrets/resolver.py +221 -0
- kstlib/secrets/sensitive.py +130 -0
- kstlib/secure/__init__.py +23 -0
- kstlib/secure/fs.py +194 -0
- kstlib/secure/permissions.py +70 -0
- kstlib/ssl.py +347 -0
- kstlib/ui/__init__.py +23 -0
- kstlib/ui/exceptions.py +26 -0
- kstlib/ui/panels.py +484 -0
- kstlib/ui/spinner.py +864 -0
- kstlib/ui/tables.py +382 -0
- kstlib/utils/__init__.py +48 -0
- kstlib/utils/dict.py +36 -0
- kstlib/utils/formatting.py +338 -0
- kstlib/utils/http_trace.py +237 -0
- kstlib/utils/lazy.py +49 -0
- kstlib/utils/secure_delete.py +205 -0
- kstlib/utils/serialization.py +247 -0
- kstlib/utils/text.py +56 -0
- kstlib/utils/validators.py +124 -0
- kstlib/websocket/__init__.py +97 -0
- kstlib/websocket/exceptions.py +214 -0
- kstlib/websocket/manager.py +1102 -0
- kstlib/websocket/models.py +361 -0
- kstlib-1.0.1.dist-info/METADATA +201 -0
- kstlib-1.0.1.dist-info/RECORD +163 -0
- {kstlib-0.0.1a0.dist-info → kstlib-1.0.1.dist-info}/WHEEL +1 -1
- kstlib-1.0.1.dist-info/entry_points.txt +2 -0
- kstlib-1.0.1.dist-info/licenses/LICENSE.md +9 -0
- kstlib-0.0.1a0.dist-info/METADATA +0 -29
- kstlib-0.0.1a0.dist-info/RECORD +0 -6
- kstlib-0.0.1a0.dist-info/licenses/LICENSE.md +0 -5
- {kstlib-0.0.1a0.dist-info → kstlib-1.0.1.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"""Logging module with Rich console output and async-friendly wrappers.
|
|
2
|
+
|
|
3
|
+
This module provides a LogManager class for structured logging with:
|
|
4
|
+
- Rich console output (colored, emoji icons, traceback with locals)
|
|
5
|
+
- File logging with rotation
|
|
6
|
+
- Preset configurations (dev, prod, debug)
|
|
7
|
+
- Async wrappers executed via thread pool
|
|
8
|
+
- Structured logging with context key=value pairs
|
|
9
|
+
|
|
10
|
+
Example:
|
|
11
|
+
>>> from kstlib.logging import get_logger
|
|
12
|
+
>>> logger = get_logger(__name__)
|
|
13
|
+
>>> logger.info("Server started") # doctest: +SKIP
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
import logging
|
|
19
|
+
from typing import Any
|
|
20
|
+
|
|
21
|
+
from kstlib.logging.manager import HAS_ASYNC, TRACE_LEVEL, LogManager
|
|
22
|
+
|
|
23
|
+
# Singleton root logger for kstlib
|
|
24
|
+
_root_logger: LogManager | None = None
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def init_logging(
|
|
28
|
+
*,
|
|
29
|
+
preset: str | None = None,
|
|
30
|
+
config: dict[str, Any] | None = None,
|
|
31
|
+
) -> LogManager:
|
|
32
|
+
"""Initialize the kstlib root logger.
|
|
33
|
+
|
|
34
|
+
This function should be called early in the application startup to
|
|
35
|
+
configure logging. If not called, loggers will use Python's default
|
|
36
|
+
configuration.
|
|
37
|
+
|
|
38
|
+
This also configures the standard "kstlib" logger in Python's logging
|
|
39
|
+
hierarchy so that child loggers (e.g., "kstlib.auth.providers.base")
|
|
40
|
+
properly propagate their messages to the LogManager's handlers.
|
|
41
|
+
|
|
42
|
+
Args:
|
|
43
|
+
preset: Logging preset ("dev", "prod", "debug", or custom from config).
|
|
44
|
+
config: Explicit configuration dict.
|
|
45
|
+
|
|
46
|
+
Returns:
|
|
47
|
+
The root LogManager instance.
|
|
48
|
+
|
|
49
|
+
Example:
|
|
50
|
+
>>> from kstlib.logging import init_logging
|
|
51
|
+
>>> logger = init_logging(preset="dev") # doctest: +SKIP
|
|
52
|
+
"""
|
|
53
|
+
global _root_logger
|
|
54
|
+
_root_logger = LogManager(name="kstlib", preset=preset, config=config)
|
|
55
|
+
|
|
56
|
+
# Also configure the standard "kstlib" logger so child loggers
|
|
57
|
+
# (created via logging.getLogger("kstlib.xxx")) propagate correctly
|
|
58
|
+
std_logger = logging.getLogger("kstlib")
|
|
59
|
+
std_logger.setLevel(TRACE_LEVEL) # Let handlers filter
|
|
60
|
+
|
|
61
|
+
# Clear existing handlers to prevent duplication on multiple init_logging() calls
|
|
62
|
+
std_logger.handlers.clear()
|
|
63
|
+
|
|
64
|
+
# Copy handlers from LogManager to standard logger
|
|
65
|
+
for handler in _root_logger.handlers:
|
|
66
|
+
std_logger.addHandler(handler)
|
|
67
|
+
|
|
68
|
+
# Propagate level to ALL existing child loggers under "kstlib.*"
|
|
69
|
+
# This ensures modules loaded before init_logging() also get the correct level
|
|
70
|
+
for logger_name in list(logging.Logger.manager.loggerDict):
|
|
71
|
+
if logger_name.startswith("kstlib."):
|
|
72
|
+
child_logger = logging.getLogger(logger_name)
|
|
73
|
+
child_logger.setLevel(TRACE_LEVEL)
|
|
74
|
+
|
|
75
|
+
return _root_logger
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def get_logger(name: str | None = None) -> logging.Logger:
|
|
79
|
+
"""Get a logger for the given module name.
|
|
80
|
+
|
|
81
|
+
Returns a child logger under the 'kstlib' namespace. When the root
|
|
82
|
+
logger is initialized via ``init_logging()`` or CLI ``--log-level``,
|
|
83
|
+
child loggers inherit its handlers and configuration.
|
|
84
|
+
|
|
85
|
+
Args:
|
|
86
|
+
name: Module name (typically ``__name__``). If None, returns
|
|
87
|
+
the root kstlib logger.
|
|
88
|
+
|
|
89
|
+
Returns:
|
|
90
|
+
A logger instance.
|
|
91
|
+
|
|
92
|
+
Example:
|
|
93
|
+
>>> from kstlib.logging import get_logger
|
|
94
|
+
>>> logger = get_logger(__name__)
|
|
95
|
+
>>> logger.debug("Processing item", extra={"item_id": 123}) # doctest: +SKIP
|
|
96
|
+
"""
|
|
97
|
+
if name is None:
|
|
98
|
+
# Return root logger (create if needed)
|
|
99
|
+
if _root_logger is not None:
|
|
100
|
+
return _root_logger
|
|
101
|
+
return logging.getLogger("kstlib")
|
|
102
|
+
|
|
103
|
+
# Ensure logger is under kstlib namespace for proper propagation
|
|
104
|
+
logger_name = name if name.startswith("kstlib.") else f"kstlib.{name}"
|
|
105
|
+
return logging.getLogger(logger_name)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
__all__ = ["HAS_ASYNC", "TRACE_LEVEL", "LogManager", "get_logger", "init_logging"]
|