Skip to main content

No project description provided

Project description

EasyLambda

A lightweight, FastAPI-inspired framework for building AWS Lambda functions with Python.

Installation

You can install the library using pip:

pip install easylambda

Quick Start

from easylambda import get

@get("/")
def lambda_handler() -> dict:
    return {"message": "Hello World!"}

Features

Request Parameters

EasyLambda supports various ways to handle request parameters:

Path Parameters

from typing import Annotated
from easylambda import get
from easylambda.path import Path

@get("/items/{item_id}")
def lambda_handler(item_id: Annotated[int, Path("item_id")]) -> dict:
    return {"item_id": item_id}

Query Parameters

from typing import Annotated
from easylambda import get
from easylambda.query import Query

items = [
    {"item_name": "Foo"},
    {"item_name": "Bar"},
    {"item_name": "Baz"},
]


@get("/items")
def lambda_handler(
    skip: Annotated[int, Query("skip")] = 0,
    limit: Annotated[int, Query("limit")] = 10,
) -> list[dict]:
    return items[skip : skip + limit]

Request Body

from typing import Annotated
from easylambda import post
from easylambda.body import Body
from pydantic import BaseModel

class Item(BaseModel):
    name: str
    description: str | None = None
    price: float
    tax: float | None = None

@post("/items")
def lambda_handler(item: Annotated[Item, Body]) -> dict:
    return item.model_dump()

Headers

from typing import Annotated
from easylambda import get
from easylambda.header import Header

@get("/items")
def lambda_handler(
    user_agent: Annotated[str | None, Header("user-agent")] = None,
) -> dict:
    return {"User-Agent": user_agent}

Response Handling

EasyLambda provides flexible response handling options:

Dictionary Response

The simplest way to return a response:

from easylambda import get

@get("/")
def lambda_handler() -> dict:
    return {"message": "Hello World!"}

Pydantic Model Response

For type-safe responses:

from easylambda import get
from pydantic import BaseModel

class HandlerResponse(BaseModel):
    message: str

@get("/")
def lambda_handler() -> HandlerResponse:
    return HandlerResponse(message="Hello World!")

Custom Response

For full control over the response:

from easylambda import get
from easylambda.aws import Response

@get("/")
def lambda_handler() -> Response:
    return Response(
        statusCode=418,
        body="I'm a teapot",
    )

Key Features

  • FastAPI-inspired syntax
  • Type hints and validation using Pydantic
  • Support for path parameters, query parameters, request body, and headers
  • Flexible response handling
  • Lightweight and optimized for AWS Lambda environment
  • No heavy web framework dependencies

Best Practices

  1. Use type hints consistently for better code clarity and automatic validation
  2. Leverage Pydantic models for request/response validation
  3. Keep functions focused and single-purpose
  4. Use meaningful parameter names that match your API design
  5. Provide default values for optional parameters

Limitations

  • When using as a Lambda Layer:
    • Only available in us-east-2 region
    • Requires Python 3.11 or 3.12
    • Must be used as a Lambda Layer

Contributing

The project is available on GitHub at: https://github.com/leandropls/easylambda

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

easylambda-0.2.1.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

easylambda-0.2.1-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file easylambda-0.2.1.tar.gz.

File metadata

  • Download URL: easylambda-0.2.1.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.0 Darwin/23.4.0

File hashes

Hashes for easylambda-0.2.1.tar.gz
Algorithm Hash digest
SHA256 5e38f28f3c8bc82b90adf8310ba8f400e38a83a1e58406f41b2f8701b4a2575c
MD5 3fc294d19f1db48c46c0476ec0808943
BLAKE2b-256 2993a32f99dace0c2dc238ea3bb10bb506813c9885f9afc0cdbad414a8e09b82

See more details on using hashes here.

File details

Details for the file easylambda-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: easylambda-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.0 Darwin/23.4.0

File hashes

Hashes for easylambda-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 15f004244bd5619668106c4e397305367564c7627112beccb8b1a65bd8e3c5b7
MD5 ccdbd8cca7c8d96bd347837533c88841
BLAKE2b-256 d7674ba5b4b0308a7605037aafd328b2ba63f3564cc93bbee22d111e09f697b0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page