Skip to main content

Lambda API Decorators

Declare AWS Lambda API routes, authentication, and configuration directly in Python.

Lambda API Decorators is a small, CDK-free Python library. Its decorators record API and Lambda configuration on your handler without wrapping or replacing the callable. An infrastructure tool such as Lambda API Decorators CDK can consume those declarations to build AWS Lambda and API Gateway resources.

Installation

Install the decorators package from PyPI:

pip install lambda-api-decorators

If you want to generate AWS infrastructure from the declarations, install the optional CDK integration separately:

pip install lambda-api-decorators-cdk

The package supports Python 3.9 through Python 3.14 and has no runtime CDK dependency.

Quick start

import json

from lambda_api_decorators import GET, memory_size, runtime, timeout


@GET("/dogs")
@runtime("python3.12")
@timeout(30)
@memory_size(256)
def lambda_handler(event, context):
    return {
        "statusCode": 200,
        "body": json.dumps({"message": "Hello from /dogs"}),
    }

The decorators retain their normal function behavior. They only attach an ordered collection of declarations for an infrastructure consumer to inspect. You can stack multiple route and configuration decorators on one handler.

API routes

The route decorators are:

  • GET(path)
  • POST(path)
  • PUT(path)
  • DELETE(path)
  • ANY(path)
@GET("/dogs")
def list_dogs(event, context):
    ...


@POST("/dogs")
def create_dog(event, context):
    ...

Lambda configuration

The following decorators declare Lambda properties or references to resources defined by the infrastructure integration:

  • runtime(value)
  • timeout(seconds)
  • memory_size(megabytes)
  • name(value)
  • description(value)
  • role(resource_key)
  • vpc(resource_key)
  • environment(*resource_keys, **values)
  • layer(*resource_keys, **values)
  • security_group(*resource_keys)

For example:

from lambda_api_decorators import (
    GET,
    environment,
    layer,
    name,
    role,
    security_group,
    vpc,
)


@GET("/orders")
@name("orders-api")
@role("api-role")
@vpc("application-vpc")
@security_group("lambda-security-group")
@environment("database", "application")
@layer("common-dependencies")
def get_orders(event, context):
    ...

The meaning of resource keys is defined by the infrastructure consumer. This package does not create or look up AWS resources itself.

Authentication

Use authorizer(key) to associate a route with an authorizer configuration, or use the bare @public decorator for a public route. A handler can have only one authentication declaration.

from lambda_api_decorators import GET, authorizer, public


@GET("/profile")
@authorizer("users")
def profile(event, context):
    ...


@GET("/health")
@public
def health(event, context):
    ...

current_user(event) extracts an already-validated identity from API Gateway authorizer claims. It supports REST API claims and HTTP API JWT claims:

from lambda_api_decorators import current_user


def profile(event, context):
    user = current_user(event)
    return {"statusCode": 200, "body": user.subject}

The returned CurrentUser contains subject, an optional username, and a read-only snapshot of claims. current_user does not authenticate tokens or authorize actions; malformed or missing identity data raises CurrentUserError.

Permissions

Declare resource access with the convenience decorators grant_dynamodb and grant_s3. Address a resource by its logical resource_key or by its physical name, and choose read or write access:

from lambda_api_decorators import GET, grant_dynamodb, grant_s3


@GET("/documents")
@grant_dynamodb("orders", "read")
@grant_s3(bucket_name="documents-prod", access="read")
def documents(event, context):
    ...

For an explicit IAM action/resource statement, use permission:

from lambda_api_decorators import permission


@permission(
    actions=["events:PutEvents"],
    resources=["arn:aws:events:us-east-1:123456789012:event-bus/orders"],
)
def publish_order(event, context):
    ...

grant_dynamodb, grant_s3, and permission only declare intent. The infrastructure integration is responsible for translating that intent into IAM policies.

How it fits together

Python handler
    │  @GET, @authorizer, @runtime, @permission, ...
    ▼
Lambda API Decorators
    │  ordered, CDK-free declarations
    ▼
Infrastructure consumer (for example Lambda API Decorators CDK)
    ▼
AWS Lambda, API Gateway, IAM, VPC, and other resources

Releasing

The Git tag is the source of truth for this package's version. Maintainers create and push a semantic-version tag from main:

git checkout main
git pull

git tag v0.2.0
git push origin v0.2.0

Pushing the tag starts the release workflow, and v0.2.0 becomes Python package version 0.2.0. Versions in this repository are independent from lambda-api-decorators-cdk.

Publishing uses PyPI trusted publishing. The PyPI project must have a trusted publisher configured for this repository, the release.yml workflow, and the pypi GitHub environment.

License

See LICENSE for details.

Release files for lambda-api-decorators 0.3.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lambda-api-decorators 0.3.2
File Size Uploaded
lambda_api_decorators-0.3.2.tar.gz 23.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lambda-api-decorators 0.3.2
File Interpreter ABI Platform
lambda_api_decorators-0.3.2-py3-none-any.whl Python 3 none any Details

Total release size: 32.2 kB

Release files / lambda_api_decorators-0.3.2.tar.gz

Download URL lambda_api_decorators-0.3.2.tar.gz
Size 23.0 kB
Tags Source
SHA-256 checksum
How to use checksums
b6c1044cde230f52cf8a4951b2f8c63928f6e93e247030003cd3e97302db715a
BLAKE2b-256 checksum
How to use checksums
68d601f2533b3c6f9483df82c6f88bdfa46bb9af908ddd9da0054d428f38f259
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 22, 2026.

Transparency log

Release files / lambda_api_decorators-0.3.2-py3-none-any.whl

Download URL lambda_api_decorators-0.3.2-py3-none-any.whl
Size 9.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
14866e481b01c00e01733dd32b1912e4276727c52d8941e6eee0c2257e24cbf6
BLAKE2b-256 checksum
How to use checksums
933f7a4b37927cc7c893bcf1037fab6efff13d76b14e4aa3733cbd60e165c6db
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 22, 2026.

Transparency log

Release history Release notifications | RSS feed

0.3.3

2 release files

This release

0.3.2 This release

2 release files

0.3.1

2 release files

0.3.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page