{"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":[{"wrong":"from safe_init import SafeInit","symbol":"handler","correct":"from safe_init import handler"},{"symbol":"LazyHandler","correct":"from safe_init import LazyHandler"},{"symbol":"Any","correct":"from safe_init import Any"}],"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,"search_vec":"'-02':28 '-04':27 '1.4.0':24 '2025':26 '3.11':46 '3.12':44 'add':29 'advanc':15 'automat':30 'aw':11,52,58 'aws-lambda':57 'check':33 'depend':38 'enhanc':10 'error':16,61 'error-handl':60 'featur':22 'function':13 'handl':17,62 'init':2,4 'integr':48 'json':31 'lambda':12,59 'librari':8,41 'log':18 'manag':39,54,68 'monitor':19,63 'python':7,43 'redi':56 'releas':25 'requir':42 'resili':21 'safe':1,3 'secret':53,67 'secrets-manag':66 'sentri':50,64 'serial':32 'slack':51,65 'use':35 'uv':36 'version':23","created_at":"2026-05-01T08:13:41.661707+00:00","updated_at":"2026-05-01T08:13:41.661707+00:00","problems":null,"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"1.4.0","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/kalepa/safe-init","docs":"https://safe-init.readthedocs.io/en/latest/","changelog":null,"pypi":"https://pypi.org/project/safe-init/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["aws","observability"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-07-03","last_verified":"2026-07-03","next_check":"2026-08-02","install_tag":null}}