skillfed

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.

safe-init v2.0.0 198.4K downloads/30d#9,732 on PyPI6
Permissive license MIT Active released

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-init

uv

uv add safe-init

poetry

poetry add safe-init

Installing 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3.11Topic :: Software Development :: LibrariesTopic :: Software Development :: Libraries :: Python ModulesTopic :: System :: LoggingTopic :: System :: MonitoringTyping :: Typed

Tags

aws lambda error handlinglambda monitoring and loggingsentry datadog lambda integrationlambda timeout notificationsserverless error trackinglambda dead letter queuelambda execution tracing
aws-lambdaerror-handlingobservability

More Libraries packages