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.4.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.4-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: easylambda-0.2.4.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.4.tar.gz
Algorithm Hash digest
SHA256 cc1d33dcaa1746d810e80b9cb27c165bf78bc1b1ed2f3c9600fede467c3fda1d
MD5 245141d8bd47347e12d78ecba3b67477
BLAKE2b-256 7a896854a4461518d53c9af435d9c4243b7b78bf9ebd0996dca97f4cb62cdb26

See more details on using hashes here.

File details

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

File metadata

  • Download URL: easylambda-0.2.4-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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 64e1c4c6ae3283bc807cb3e798ae8c8c1b2e4e8b91e013ea98df3f7c984d4dd1
MD5 4829b27e51c1ab7dbc7cecd6ea8b475e
BLAKE2b-256 469cf01e97a774417c77890f50e5ccf18684a5d5c3e547ddcf3cf0cd041a6a9c

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