{"id":16614957,"url":"https://github.com/dschep/lambda-decorators","last_synced_at":"2025-04-04T15:08:33.207Z","repository":{"id":27788806,"uuid":"115207670","full_name":"dschep/lambda-decorators","owner":"dschep","description":"🐍λ✨ - A collection of useful decorators for making AWS Lambda handlers","archived":false,"fork":false,"pushed_at":"2023-07-20T14:13:36.000Z","size":121,"stargazers_count":247,"open_issues_count":18,"forks_count":34,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-19T06:02:55.843Z","etag":null,"topics":["aws-lambda","decorators","python","serverless"],"latest_commit_sha":null,"homepage":"http://lambda-decorators.rtfd.io","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dschep.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-12-23T16:25:06.000Z","updated_at":"2024-09-06T15:13:24.000Z","dependencies_parsed_at":"2024-06-18T15:24:04.488Z","dependency_job_id":null,"html_url":"https://github.com/dschep/lambda-decorators","commit_stats":{"total_commits":135,"total_committers":2,"mean_commits":67.5,"dds":0.007407407407407418,"last_synced_commit":"698f7dc2e95d4d22cb7373981315edd7ba5c2fe2"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dschep%2Flambda-decorators","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dschep%2Flambda-decorators/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dschep%2Flambda-decorators/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dschep%2Flambda-decorators/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dschep","download_url":"https://codeload.github.com/dschep/lambda-decorators/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247198460,"owners_count":20900080,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws-lambda","decorators","python","serverless"],"created_at":"2024-10-12T02:08:17.457Z","updated_at":"2025-04-04T15:08:33.190Z","avatar_url":"https://github.com/dschep.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n🐍λ✨ - lambda_decorators\n=========================\n|Version|_ |Docs|_ |Build|_ |SayThanks|_\n\nA collection of useful decorators for making AWS Lambda handlers\n\n``lambda_decorators`` is a collection of useful decorators for writing Python\nhandlers for `AWS Lambda \u003chttps://aws.amazon.com/lambda/\u003e`_. They allow you to\navoid boiler plate for common things such as CORS headers, JSON serialization,\netc.\n\nQuick example\n-------------\n.. code:: python\n\n    # handler.py\n\n    from lambda_decorators import json_http_resp, load_json_body\n\n    @json_http_resp\n    @load_json_body\n    def handler(event, context):\n        return {'hello': event['body']['name']}\n\nWhen deployed to Lambda behind API Gateway and cURL'd:\n\n.. code:: shell\n\n   $ curl -d '{\"name\": \"world\"}' https://example.execute-api.us-east-1.amazonaws.com/dev/hello\n   {\"hello\": \"world\"}\n\nInstall\n-------\nIf you are using `the serverless framework \u003chttps://github.com/serverless/serverless\u003e`_\nI recommend using\n`serverless-python-requirements \u003chttps://github.com/UnitedIncome/serverless-python-requirements\u003e`_\n\n.. code:: shell\n\n    sls plugin install -n serverless-python-requirements\n    echo lambda-decorators \u003e\u003e requirements.txt\n\nOr if using some other deployment method to AWS Lambda you can just download\nthe entire module because it's only one file.\n\n.. code:: shell\n\n    curl -O https://raw.githubusercontent.com/dschep/lambda-decorators/master/lambda_decorators.py\n\nIncluded Decorators:\n--------------------\n``lambda_decorators`` includes the following decorators to avoid boilerplate\nfor common usecases when using AWS Lambda with Python.\n\n* `async_handler \u003chttp://lambda-decorators.rtfd.io#lambda_decorators.async_handler\u003e`_ - support for async handlers\n* `cors_headers \u003chttp://lambda-decorators.rtfd.io#lambda_decorators.cors_headers\u003e`_ - automatic injection of CORS headers\n* `dump_json_body \u003chttp://lambda-decorators.rtfd.io#lambda_decorators.dump_json_body\u003e`_ - auto-serialization of http body to JSON\n* `load_json_body \u003chttp://lambda-decorators.rtfd.io#lambda_decorators.load_json_body\u003e`_ - auto-deserialize of http body from JSON\n* `json_http_resp \u003chttp://lambda-decorators.rtfd.io#lambda_decorators.json_http_resp\u003e`_ - automatic serialization of python object to HTTP JSON response\n* `json_schema_validator \u003chttp://lambda-decorators.rtfd.io#lambda_decorators.json_schema_validator\u003e`_ - use JSONSchema to validate request\u0026response payloads\n* `load_urlencoded_body \u003chttp://lambda-decorators.rtfd.io#lambda_decorators.load_urlencoded_body\u003e`_ - auto-deserialize of http body from a querystring encoded body\n* `no_retry_on_failure \u003chttp://lambda-decorators.rtfd.io#lambda_decorators.no_retry_on_failure\u003e`_ - detect and stop retry attempts for scheduled lambdas\n* `ssm_parameter_store \u003chttp://lambda-decorators.rtfd.io#lambda_decorators.ssm_parameter_store\u003e`_ - fetch parameters from the AWS SSM Parameter Store\n* `secret_manager \u003chttp://lambda-decorators.rtfd.io#lambda_decorators.secret_manager\u003e`_ - fetch secrets from the AWS Secrets Manager\n\nSee each individual decorators for specific usage details and the example_\nfor some more use cases. This library is also meant to serve as an example for how to write\ndecorators for use as lambda middleware. See the recipes_ page for some more niche examples of\nusing decorators as middleware for lambda.\n\n.. _example: https://github.com/dschep/lambda-decorators/tree/master/example\n.. _recipes: recipes.rst\n\nWriting your own\n----------------\n``lambda_decorators`` includes utilities to make building your own decorators\neasier. The `before \u003chttp://lambda-decorators.rtfd.io#lambda_decorators.before\u003e`_, `after \u003chttp://lambda-decorators.rtfd.io#lambda_decorators.after\u003e`_, and `on_exception \u003chttp://lambda-decorators.rtfd.io#lambda_decorators.on_exception\u003e`_ decorators\ncan be applied to your own functions to turn them into decorators for your\nhandlers. For example:\n\n\n.. code:: python\n\n    import logging\n    from lambda_decorators import before\n\n    @before\n    def log_event(event, context):\n        logging.debug(event)\n        return event, context\n\n    @log_event\n    def handler(event, context):\n        return {}\n\nAnd if you want to make a decorator that provides two or more of\nbefore/after/on_exception functionality, you can use\n`LambdaDecorator \u003chttp://lambda-decorators.rtfd.io#lambda_decorators.LambdaDecorator\u003e`_:\n\n.. code:: python\n\n    import logging\n    from lambda_decorators import LambdaDecorator\n\n    class log_everything(LambdaDecorator):\n        def before(self, event, context):\n            logging.debug(event, context)\n            return event, context\n        def after(self, retval):\n            logging.debug(retval)\n            return retval\n        def on_exception(self, exception):\n            logging.debug(exception)\n            return {'statusCode': 500}\n\n    @log_everything\n    def handler(event, context):\n        return {}\n\n\nWhy\n---\nInitially, I was inspired by `middy \u003chttps://github.com/middyjs/middy\u003e`_ which\nI like using in JavaScript. So naturally, I thought I'd like to have something similar in Python\ntoo. But then as I thought about it more, it seemed that when thinking of functions as the compute\nunit, when using python, `decorators \u003chttps://wiki.python.org/moin/PythonDecorators\u003e`_\npretty much are middleware! So instead of building a middleware engine and a few middlewares, I\njust built a few useful decorators and utilities to build them.\n\n-----\n\n.. |Version| image:: https://img.shields.io/pypi/v/lambda-decorators.svg\n.. _Version: https://pypi.org/project/lambda-decorators\n.. |Docs| image:: http://readthedocs.org/projects/lambda-decorators/badge/?version=latest\n.. _Docs: http://lambda-decorators.readthedocs.org/en/latest\n.. |Build| image:: https://img.shields.io/travis/dschep/lambda-decorators/master.svg\n.. _Build: https://travis-ci.org/dschep/lambda-decorators\n.. |SayThanks| image:: https://img.shields.io/badge/Say%20Thanks-!-1EAEDB.svg\n.. _SayThanks: https://saythanks.io/to/dschep\n\n\n`Full API Documentation \u003chttp://lambda-decorators.readthedocs.io/en/latest/\u003e`_\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdschep%2Flambda-decorators","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdschep%2Flambda-decorators","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdschep%2Flambda-decorators/lists"}