safe-init
Safe Init is a Python library that enhances AWS Lambda functions with advanced error handling, logging, monitoring, and resilience features, providing comprehensive observability and reliability for serverless applications.
What it is and what it does
Safe Init is a wrapper library for AWS Lambda handlers that intercepts execution to add error handling, logging, and monitoring without requiring changes to your handler code. You point your Lambda's entry point to `safe_init.handler.handler`, set an environment variable to your original handler, and the library takes over—capturing unhandled exceptions, tracing function call execution times, and forwarding errors to Sentry, Datadog, or Slack depending on your configuration.
The library integrates with AWS Secrets Manager for automatic secret resolution, supports dead-letter queues for failed events, detects JSON serialization failures, and sends pre-timeout notifications. It is designed as a safety net rather than a replacement for in-code error handling. Runtime dependencies include boto3 for AWS API access, Datadog and Sentry SDKs for monitoring, Redis for caching, and structlog for structured logging.
Use it for:
- Wrap existing Lambda functions with centralized error tracking and Sentry integration without modifying handler code
- Send Slack alerts when Lambda functions encounter errors or approach timeout limits
- Automatically push failed Lambda events to a dead-letter queue for asynchronous retry or analysis
- Trace execution time of function calls within Lambda to identify performance bottlenecks
- Automatically resolve AWS Secrets Manager secrets from environment variables during Lambda initialization
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Safe Init wraps AWS Lambda handlers to provide automatic error handling, execution tracing, and integration with monitoring services like Sentry, Datadog, and Slack.
Yes, if you run AWS Lambda functions and want centralized error handling and monitoring without modifying your handler code. The library is actively maintained, has no known vulnerabilities, and low install friction. Suitable for production use. Caveat: requires Python 3.11 specifically, so verify your Lambda runtime version before adoption.
Install
safe-init on PyPI
pip
pip install safe-inituv
uv add safe-initpoetry
poetry add safe-initInstalling safe-init
Before you install
Low install friction with a pure-Python wheel. Active maintenance with a recent release. Depends on 9 runtime packages including boto3, Datadog, Sentry, and Redis; all are widely used and stable.
License in practice
MIT license is permissive and imposes no restrictions on use or redistribution, making it suitable for both open and closed-source projects.
Quickstart
pip install safe-init
# Set Lambda handler to: safe_init.handler.handler
# Set environment variable: SAFE_INIT_HANDLER=mymodule.lambda_handler
# Safe Init wraps your handler automatically with error handling and monitoring
Requires Python 3.11 (capped at <3.12); Lambda runtime must support this version.
Verify before relying
- Performance overhead of execution time tracing on Lambda cold starts and warm invocations
- Compatibility with Lambda layers and custom runtimes beyond standard AWS Lambda environments
- Behavior when multiple monitoring integrations (Sentry, Datadog, Slack) are configured simultaneously
Package facts
| License | MIT (permissive) |
| Python support | capped below the current Python release (<3.12,>=3.11) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 9 — awslambdaric, boto3-type-annotations, boto3, datadog-lambda, ddtrace, redis, requests, sentry-sdk, structlog |
| Maintenance | actively maintained — 0 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 198,378/month — #9,732 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: safe_init-2.0.0-py3-none-any.whl
Tags
More Libraries packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
python-dateutilProvides parsing, arithmetic, and recurrence…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
aiocopDetects and logs blocking I/O and CPU calls in…
permissive · top 15,000 on PyPI
django-datadog-loggerIntegrates Django applications with Datadog…
permissive · top 15,000 on PyPI
dagster-datadogIntegrates Datadog monitoring and observability…
permissive · top 15,000 on PyPI
datadog-cdk-constructs-v2Provides AWS CDK constructs to automatically…
permissive · top 15,000 on PyPI
datadog-loggerSends Python log messages to Datadog as Events…
permissive · top 15,000 on PyPI
sentry-sdkSentry SDK captures and reports Python…
permissive · top 1,000 on PyPI
ravenRaven is a legacy Python client for Sentry that…
permissive · top 5,000 on PyPI
cdk-events-notifyAn AWS CDK Construct Library that automatically…
permissive · top 15,000 on PyPI
policy-sentryPolicy Sentry generates least-privilege AWS IAM…
permissive · top 5,000 on PyPI