Common¶
Shared kernel used by other domains. Narrative guide: Common. Tracing how-to: Tracing.
Config¶
pypepper.common.config
¶
YAML config loading and typed configuration models.
ConfHTTPServer
¶
ConfHTTPSServer
¶
Source code in pypepper/common/config.py
ConfNetwork
¶
ConfLog
¶
ConfSSEAuthentication
¶
ConfSSERateLimit
¶
ConfSSE
¶
Source code in pypepper/common/config.py
ConfTracingOTLP
¶
ConfTracing
¶
Source code in pypepper/common/config.py
ConfSchedulerJobStore
¶
Source code in pypepper/common/config.py
ConfScheduler
¶
YmlConfig
¶
Source code in pypepper/common/config.py
Config
¶
Source code in pypepper/common/config.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |
load_config
¶
Source code in pypepper/common/config.py
refresh_scheduler_job_store_deferred
¶
Re-read durable scheduler.jobStore from the current YAML into the deferred flag.
Counterpart to :meth:mark_scheduler_job_store_applied (used by reset_job_store
and load_config). Memory / missing backends clear the flag.
Source code in pypepper/common/config.py
mark_scheduler_job_store_applied
¶
Clear the deferred durable jobStore flag (called after setup/configure).
ensure_scheduler_job_store_applied
¶
Raise if YAML declared a durable jobStore that has not been applied yet.
When a non-memory store is already installed (using_default_memory_store=False),
treat the deferred declaration as satisfied so configure-before-load and reload
after setup do not false-positive.
Source code in pypepper/common/config.py
Log¶
pypepper.common.log
¶
Loguru-based process logger helpers.
log_fmt
module-attribute
¶
log_fmt = "[<green>{time:YYYY-MM-DDTHH:mm:ss.SSSZ}</green>][<level>{level:<8}</level>][<cyan>$host:$user</cyan>][<cyan>pid:{process}|tid:{thread}</cyan>][<cyan>{file.path}:{line}</cyan>][<cyan>{module}.{function}</cyan>][<magenta>{extra[req_id]}</magenta>][<level>{message}</level>]"
log_format_template
module-attribute
¶
log_format_template = Template(log_fmt).substitute(
host=socket.gethostname(), user=getpass.getuser()
)
config
module-attribute
¶
config = {
"handlers": [
{
"sink": sys.stdout,
"format": log_format_template,
"level": LogLevel.TRACE,
"colorize": True,
"enqueue": True,
"filter": default_log_filter,
}
],
"levels": [
dict(
name="FATAL",
no=60,
icon="☠",
color="<RED><bold>",
)
],
"extra": {"req_id": 0},
}
LogLevel
¶
Bases: str, Enum
Log level
Source code in pypepper/common/log.py
has_name
classmethod
¶
Check if the name is in LogLevel
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
log level name |
required |
Returns:
| Type | Description |
|---|---|
bool
|
result |
has_value
classmethod
¶
Check if the value is in LogLevel
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
log level value |
required |
Returns:
| Type | Description |
|---|---|
bool
|
result |
LogLevelFilter
¶
Log level filter
Source code in pypepper/common/log.py
Logger
¶
Source code in pypepper/common/log.py
Options¶
pypepper.common.options
¶
Functional options pattern helpers.
IOptions
¶
Options interface
Source code in pypepper/common/options.py
new
¶
with_context
¶
With context options
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
IContext
|
context |
required |
Returns:
| Type | Description |
|---|---|
Callable[[IOptions], Any]
|
init context function |
Context¶
pypepper.common.context
¶
Chained request/job context exports.
Context
¶
Bases: IContext
Context
Source code in pypepper/common/context/context.py
with_value
¶
Set context key/value
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Any
|
key |
required |
value
|
Any
|
value |
required |
Returns:
| Type | Description |
|---|---|
IContext
|
Context |
trace
¶
Trace to the context by index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
context index. |
required |
Returns:
| Type | Description |
|---|---|
IContext
|
Context. |
Raises:
| Type | Description |
|---|---|
InternalException
|
if the index is not present in the chain |
Source code in pypepper/common/context/context.py
length
¶
born
¶
born(
length: int,
parent: Context | None = None,
id_provider: Callable[P, T] | None = None,
) -> Context
Born the context chain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length
|
int
|
chain length. |
required |
parent
|
Context | None
|
parent context. |
None
|
id_provider
|
Callable[P, T] | None
|
context ID provider. |
None
|
Returns:
| Type | Description |
|---|---|
Context
|
context. |
Source code in pypepper/common/context/context.py
Cache¶
pypepper.common.cache
¶
Thread-safe TTL cache set.
Cache
¶
Bases: TTLCache
Thread safe TTL cache
Source code in pypepper/common/cache.py
set
¶
Set key/value
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Any
|
cache key |
required |
value
|
Any
|
cache value |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
get
¶
Get value
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Any
|
cache key |
required |
default
|
Any
|
default value when missing |
None
|
Returns:
| Type | Description |
|---|---|
Any | None
|
cache value |
Source code in pypepper/common/cache.py
CacheSet
¶
A thread safe TTL cache-set
Source code in pypepper/common/cache.py
new
¶
new(
name: str,
maxsize: int = Cache.default_cache_maxsize,
ttl: float = Cache.default_cache_ttl,
) -> Cache
Return a named cache, creating it on first use.
maxsize / ttl apply only when the name is created. If the name
already exists, the existing cache is returned and those params are ignored.
Source code in pypepper/common/cache.py
new_cache
¶
Tracing¶
pypepper.common.tracing
¶
OpenTelemetry tracing setup and HTTP middleware exports.
TracingMiddleware
¶
Bases: BaseHTTPMiddleware
Create a SERVER span per HTTP request; attach request_id when present.
Source code in pypepper/common/tracing/middleware.py
dispatch
async
¶
Source code in pypepper/common/tracing/middleware.py
get_tracer
¶
setup_for_tests
¶
Install a TracerProvider that exports to the given span exporter (tests only).
Uses SimpleSpanProcessor so spans are available immediately after the request.
Source code in pypepper/common/tracing/setup.py
setup_from_config
¶
Configure OpenTelemetry from YAML config.
Expected shape (all optional; missing section disables tracing)::
tracing:
enabled: false
serviceName: pypepper
console: false
otlp:
enabled: false
endpoint: http://127.0.0.1:4318
Source code in pypepper/common/tracing/setup.py
shutdown
¶
Flush and shut down the configured TracerProvider, if any.
Source code in pypepper/common/tracing/setup.py
Crypto¶
pypepper.common.security.crypto.digest
¶
Hash digest helpers (bytes and hex).
get
¶
Get hash (bytes)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
BinaryLike
|
data in BinaryLike style |
required |
alg
|
str
|
algorithm ( |
required |
Returns:
| Type | Description |
|---|---|
bytes
|
hash (bytes) |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
Source code in pypepper/common/security/crypto/digest.py
get_hex_str
¶
Get hash string (hex)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
BinaryLike
|
data in BinaryLike style |
required |
alg
|
str
|
algorithm ( |
required |
Returns:
| Type | Description |
|---|---|
str
|
hash string (hex) |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
Source code in pypepper/common/security/crypto/digest.py
pypepper.common.security.crypto.salt
¶
Random salt generation.
new
¶
Generates a random salt of the specified size. The salt should be as unique as possible. It is recommended that a salt is random and at least 16 bytes long. See NIST SP 800-132 for details. Ref: https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-132.pdf
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
number of bytes |
DEFAULT_SALT_SIZE
|
Returns:
| Type | Description |
|---|---|
bytes
|
a random salt |
Source code in pypepper/common/security/crypto/salt.py
pypepper.common.security.crypto.elliptic.ecdsa
¶
ECDSA sign and verify on secp256k1.
ECDSA
¶
Bases: IElliptic
Source code in pypepper/common/security/crypto/elliptic/ecdsa.py
new_key_pair
¶
sign
¶
Source code in pypepper/common/security/crypto/elliptic/ecdsa.py
verify
¶
Source code in pypepper/common/security/crypto/elliptic/ecdsa.py
get_private_key_pem
staticmethod
¶
get_private_key_pem(
private_key: EllipticCurvePrivateKey,
passphrase: bytes | None = None,
) -> bytes