apifrom.adapters.aws_lambda

AWS Lambda adapter for APIFromAnything.

This module provides an adapter for running APIFromAnything applications on AWS Lambda with API Gateway integration.

Overview

Classes

Classes

class apifrom.adapters.aws_lambda.API(debug=False, title='APIFromAnything API', description='API created with APIFromAnything', version='1.0.0', docs_url='/docs', openapi_config=None, swagger_ui_config=None, enable_docs=True)[source]
Parameters:

Main application container for APIFromAnything.

This class serves as the central registry for all API endpoints, middleware, and configuration. It provides methods for registering endpoints, middleware, and starting the server.

apifrom.adapters.aws_lambda.router

The router instance for managing routes.

Type:

Router

apifrom.adapters.aws_lambda.middleware

List of middleware instances.

Type:

list

apifrom.adapters.aws_lambda.debug

Whether to run in debug mode.

Type:

bool

apifrom.adapters.aws_lambda.title

The title of the API.

Type:

str

apifrom.adapters.aws_lambda.description

The description of the API.

Type:

str

apifrom.adapters.aws_lambda.version

The version of the API.

Type:

str

apifrom.adapters.aws_lambda.docs_url

The URL for the API documentation.

Type:

str

Initialize a new API instance.

param debug:

Whether to run in debug mode.

param title:

The title of the API.

param description:

The description of the API.

param version:

The version of the API.

param docs_url:

The URL for the API documentation.

param openapi_config:

Configuration for OpenAPI documentation.

param swagger_ui_config:

Configuration for Swagger UI.

param enable_docs:

Whether to enable API documentation.

class apifrom.adapters.aws_lambda.LambdaAdapter(app)[source]
Parameters:

app (apifrom.core.app.API)

Adapter for running APIFromAnything applications on AWS Lambda.

This adapter translates between AWS Lambda event/context objects and APIFromAnything’s Request/Response objects.

Initialize the Lambda adapter.

param app:

The APIFromAnything application to adapt.

apifrom.adapters.aws_lambda._create_lambda_response(response)

Create a Lambda response from an APIFromAnything response.

param response:

The APIFromAnything response or a dictionary

returns:

A response object that Lambda can understand

apifrom.adapters.aws_lambda._create_request(event, context)

Create a Request object from a Lambda event.

param event:

The Lambda event.

param context:

The Lambda context.

returns:

A Request object.

apifrom.adapters.aws_lambda.handle(event, context)

Handle an AWS Lambda event.

param event:

The AWS Lambda event object.

param context:

The AWS Lambda context object.

returns:

A dictionary that can be returned to API Gateway.

class apifrom.adapters.aws_lambda.Request(request=None, path_params=None, method=None, path=None, query_params=None, headers=None, body=None, client_ip=None)[source]
Parameters:
  • request (Optional[starlette.requests.Request])

  • path_params (Optional[dict[Any, Any]])

  • method (Optional[str])

  • path (Optional[str])

  • query_params (Optional[dict[Any, Any]])

  • headers (Optional[dict[Any, Any]])

  • body (Optional[Union[str, bytes]])

  • client_ip (Optional[str])

Request class for APIFromAnything.

This class wraps a Starlette request and provides methods for accessing request data in a convenient way.

apifrom.adapters.aws_lambda._request

The underlying Starlette request.

apifrom.adapters.aws_lambda.path_params

Path parameters extracted from the URL.

apifrom.adapters.aws_lambda.query_params

Query parameters extracted from the URL.

apifrom.adapters.aws_lambda.headers

HTTP headers.

apifrom.adapters.aws_lambda.method

HTTP method.

apifrom.adapters.aws_lambda.path

Request path.

apifrom.adapters.aws_lambda._body

Cached request body.

Initialize a new Request instance.

param request:

The underlying Starlette request.

param path_params:

Path parameters extracted from the URL.

param method:

The HTTP method.

param path:

The request path.

param query_params:

Query parameters.

param headers:

HTTP headers.

param body:

Request body.

param client_ip:

Client IP address.

class apifrom.adapters.aws_lambda.Response(content=None, status_code=200, headers=None, content_type='application/json')[source]
Parameters:
  • content (Any)

  • status_code (int)

  • headers (Optional[Dict[str, str]])

  • content_type (str)

Response class for APIFromAnything.

This class represents an HTTP response and provides methods for setting response data, status code, and headers.

apifrom.adapters.aws_lambda.content

The response content.

apifrom.adapters.aws_lambda.status_code

The HTTP status code.

apifrom.adapters.aws_lambda.headers

HTTP headers.

apifrom.adapters.aws_lambda.content_type

The content type of the response.

Initialize a new Response instance.

param content:

The response content.

param status_code:

The HTTP status code.

param headers:

HTTP headers.

param content_type:

The content type of the response.