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.3.tar.gz (6.7 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.3-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: easylambda-0.2.3.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.13.2 Darwin/24.5.0

File hashes

Hashes for easylambda-0.2.3.tar.gz
Algorithm Hash digest
SHA256 298d63c0f26cf097348240c8c162d2528b8667c316ebea19c0c595ed7ca84df4
MD5 47061ca54d15a8c79adb87df763334e6
BLAKE2b-256 ecb777ba3efb0c61140215c4a6a8f2a229b9ce65f91a22ef3afec106c485e4b9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: easylambda-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 10.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.13.2 Darwin/24.5.0

File hashes

Hashes for easylambda-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 93b5bbbd1e8401d00dcbd710bbd7d972ea704f2431e38b5774526d658a5cd430
MD5 b8b7288a31a8788ed66a9fbdd24d40af
BLAKE2b-256 9d837f04cbd534b4ba0665d881d22d412956e11ef3edf48986a605a9ef8760e6

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