{"id":24553,"library":"safe-init","title":"Safe Init","description":"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.","status":"active","version":"1.4.0","language":"python","source_language":"en","source_url":"https://github.com/kalepa/safe-init","tags":["aws-lambda","error-handling","monitoring","sentry","slack","secrets-manager"],"install":[{"cmd":"pip install safe-init","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"Error reporting to Sentry.","package":"sentry-sdk","optional":true},{"reason":"Slack notifications.","package":"slack-sdk","optional":true},{"reason":"AWS Secrets Manager integration.","package":"boto3","optional":true},{"reason":"Redis-based secret caching.","package":"redis","optional":true}],"imports":[{"note":"","wrong":"","symbol":"SafeInit","correct":"from safe_init import SafeInit"},{"note":"","wrong":"","symbol":"SafeInitWrapper","correct":"from safe_init import SafeInitWrapper"}],"quickstart":{"code":"from safe_init import SafeInit\n\n# Initialize with Sentry DSN (use environment variable)\nsafe_init = SafeInit(dsn=os.environ.get('SENTRY_DSN', ''))\n\n@safe_init.lambda_handler\ndef lambda_handler(event, context):\n    return {'statusCode': 200, 'body': 'Hello from Safe Init!'}","lang":"python","description":"Wrap your Lambda handler with the @safe_init.lambda_handler decorator to automatically capture errors and report to Sentry."},"warnings":[{"fix":"Use safe_init.set_slack_webhook() and safe_init.set_custom_logger() via context variables instead of monkey patching.","message":"Slack webhook URLs and custom loggers via monkey patching removed in v1.2.0. Use ContextVars instead.","severity":"breaking","affected_versions":">=1.2.0"},{"fix":"Ensure your Lambda returns JSON-serializable objects, or configure the check if you need different behavior.","message":"Lambda 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.","severity":"gotcha","affected_versions":">=1.4.0"},{"fix":"Create a .env.json file in your Lambda deployment package with key-value pairs.","message":"The .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.","severity":"gotcha","affected_versions":">=1.3.0"},{"fix":"Use Python 3.11 runtime in AWS Lambda.","message":"Python 3.11 support is required; Python >=3.12 is not supported. The project may not work with newer Python runtimes.","severity":"deprecated","affected_versions":">=1.4.0"},{"fix":"Ensure your secret ARN either includes the full ARN or only the name without prefix.","message":"AWS 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.","severity":"gotcha","affected_versions":">=1.2.1"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use safe_init.set_slack_webhook('https://hooks.slack.com/...') before calling the handler.","cause":"Slack notifications are enabled but no webhook URL is set via context variable.","error":"safe_init.exceptions.SafeInitConfigurationError: Slack webhook URL not configured"},{"fix":"Convert the return value to a JSON-serializable format, e.g., str(uuid).","cause":"Lambda handler returns an object like UUID that is not JSON serializable.","error":"safe_init.exceptions.SafeInitSerializationError: Return value is not JSON serializable: UUID('...')"},{"fix":"Run 'pip install safe-init' and ensure version >=1.0.0.","cause":"Safe Init is not installed or version does not export the class.","error":"ImportError: cannot import name 'SafeInit' from 'safe_init'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}