Registry / aws / safe-init

safe-init

JSON →
library1.4.0pypypi✓ verified 80d ago

Safe Init is a Python library that enhances AWS Lambda functions with advanced error handling, logging, monitoring, and resilience features. Version 1.4.0 (released 2025-04-02) adds automatic JSON serialization checks and uses uv for dependency management. The library requires Python <3.12 and >=3.11, and integrates with Sentry, Slack, AWS Secrets Manager, and Redis.

pip install safe-init
INSTALL
IMPORT
SIG · SAFE-INIT
S
safe-init
awspythonv1.4.0
Install
12.2s avg
Import
Disk
115MB
Pass rate
1/ 10
Env Coverage1 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.4.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✕ build_error
✕ build_error
py 3.11
✕ build_error
✓ 12.2s
py 3.12
✕ build_error
✕ build_error
py 3.13
✕ build_error
✕ build_error
py 3.9
✕ build_error
✕ build_error
115MB installed
● package 115MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

handler
from safe_init import handler
from safe_init import SafeInit
LazyHandler
from safe_init import LazyHandler
Any
from safe_init import Any

Wrap your Lambda handler with the @safe_init.lambda_handler decorator to automatically capture errors and report to Sentry.

from safe_init import SafeInit # Initialize with Sentry DSN (use environment variable) safe_init = SafeInit(dsn=os.environ.get('SENTRY_DSN', '')) @safe_init.lambda_handler def lambda_handler(event, context): return {'statusCode': 200, 'body': 'Hello from Safe Init!'}
Debug
Known issues
breakingSlack webhook URLs and custom loggers via monkey patching removed in v1.2.0. Use ContextVars instead.
fix
Use safe_init.set_slack_webhook() and safe_init.set_custom_logger() via context variables instead of monkey patching.
affects: >=1.2.0
gotchaLambda return value JSON serialization check introduced in v1.4.0 may cause unexpected behavior if you rely on non-serializable objects like UUIDs. The check reports to Sentry but does not break execution.
fix
Ensure your Lambda returns JSON-serializable objects, or configure the check if you need different behavior.
affects: >=1.4.0
gotchaThe .env.json file feature (v1.3.0) reads environment variables from a JSON file. This file must be deployed with your Lambda and correctly formatted.
fix
Create a .env.json file in your Lambda deployment package with key-value pairs.
affects: >=1.3.0
deprecatedPython 3.11 support is required; Python >=3.12 is not supported. The project may not work with newer Python runtimes.
fix
Use Python 3.11 runtime in AWS Lambda.
affects: >=1.4.0
gotchaAWS Secrets Manager secret ARN prefix feature: Safe Init will not add the configured prefix if the value already contains a prefix. This can lead to double-prefix if not careful.
fix
Ensure your secret ARN either includes the full ARN or only the name without prefix.
affects: >=1.2.1
Upgrade
Version history
1.4.0latest on PyPI · released Apr 2, 2025
Audit
Dependencies
sentry-sdkoptionalError reporting to Sentry.
slack-sdkoptionalSlack notifications.
boto3optionalAWS Secrets Manager integration.
redisoptionalRedis-based secret caching.
Agent activity
23 hits · last 30 days
node
18
OpenAI (training)
2
Amazon
1
Resources