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.1

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.1
File Size Uploaded
lambda_api_decorators-0.3.1.tar.gz 22.0 kB Details

Built distribution (wheel)

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

Total release size: 30.9 kB

Release files / lambda_api_decorators-0.3.1.tar.gz

Download URL lambda_api_decorators-0.3.1.tar.gz
Size 22.0 kB
Tags Source
SHA-256 checksum
How to use checksums
d79c6db5db39bbe541dd8f6614c8b3398c44c0a6f82081b9db091540ec56c274
BLAKE2b-256 checksum
How to use checksums
797dcf50b1d824714384b396d7ad74ae52ff5b3f7bb7bdc854e054a844834325
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 17, 2026.

Transparency log

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

Download URL lambda_api_decorators-0.3.1-py3-none-any.whl
Size 9.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4aa45c2c6fa2106388e4b87573b67c393212dfcad019e1682c9c6a800d98689c
BLAKE2b-256 checksum
How to use checksums
32efa0a5855d131ce95f82fe860f04753b42328a09c952b8ecf8808775af3d07
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 17, 2026.

Transparency log

Release history Release notifications | RSS feed

0.3.3

2 release files

0.3.2

2 release files

This release

0.3.1 This release

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