Skip to main content

Pydantic model and lambda event handler for AWS Lambda

Project description


Pydantic model and lambda event handler for AWS Lambda

Build Status PyPI version codecov

This project is an experimental phase.

What is Lambdantic ?

The name means AWS Lambda + pydantic

lambdantic dispatch handler function from aws lambda events and to assign attributes from event object.


To install lambdantic:

$ pip install lambdantic


API Gateway

The example is simple api which is invoked by API Gateway.

lambdantic parse Lambda Proxy Integration request.

The example should be deployed by Serverless, AWS CDK or other framework which supports Lambda Proxy Integration.

from typing import List, Optional

from pydantic import BaseModel, Schema

from lambdantic.apigateway import Handler

handler = Handler()

class Pet(BaseModel):
    pet_id: Optional[int] = Schema(..., alias='id')
    name: str
    age: int

# database
pets = [
        Pet(id=1, name='dog', age=3),
        Pet(id=2, name='cat', age=2)

def get_pets() -> List[Pet]:
    return pets

def get_pet(pet_id: int) -> Pet:
    for pet in pets:
        if pet.pet_id == pet_id:
            return pet'/pets', body_model=Pet, status_code=201)
def crate_pet(pet: Pet) -> Pet:
    pet.pet_id = max(p.pet_id for p in pets)

    return pet

If you use Serverless then, the handler is defined like this example.

    handler: handler.handler
      - http:
          method: any
          path: /{proxy+}

I show common parameters for Other framework

Handler: handler.handler
API Gateway API integration type : Lambda Proxy Integration
Path: /{proxy+}
method: ANY


  • API Gateway (WIP)

Not Implemented

  • S3
  • SNS ... and more


Install the package in editable mode:

$ git clone
$ pip install -e lambdantic


Source Code



lambdantic is released under the MIT License.

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

lambdantic-0.0.4.tar.gz (13.9 kB view hashes)

Uploaded Source

Built Distribution

lambdantic-0.0.4-py3-none-any.whl (14.9 kB view hashes)

Uploaded Python 3

Supported by

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