Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kushagraindurkhya/pylambdapi
A lightweight API framework for AWS Lambda
https://github.com/kushagraindurkhya/pylambdapi
api apigateway apigateway-lambda aws cloud lambda python rest rest-api
Last synced: 6 days ago
JSON representation
A lightweight API framework for AWS Lambda
- Host: GitHub
- URL: https://github.com/kushagraindurkhya/pylambdapi
- Owner: KushagraIndurkhya
- License: agpl-3.0
- Created: 2023-08-16T05:59:41.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-05-12T21:25:02.000Z (6 months ago)
- Last Synced: 2024-10-07T13:06:18.227Z (about 1 month ago)
- Topics: api, apigateway, apigateway-lambda, aws, cloud, lambda, python, rest, rest-api
- Language: Python
- Homepage: https://pypi.org/project/PyLambdAPI/
- Size: 35.2 KB
- Stars: 2
- Watchers: 1
- Forks: 5
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PyLambdAPI
**PyLambdAPI** is a lightweight Python framework designed explicitly for AWS Lambda functions. It provides a streamlined approach to building serverless web services, offering the flexibility to create API endpoints accessible through either function URLs or API Gateway. If you're seeking a simplified alternative to complex web frameworks like Flask for Lambda-based microservices, PyLambdAPI is the solution you've been looking for.
## Why PyLambdAPI?
**AWS Lambda** is a potent and scalable serverless computing platform. However, building API endpoints with AWS Lambda often involves dealing with various input sources, request management, and response structuring. PyLambdAPI simplifies this process and stands out for these reasons:
- **Lightweight**: PyLambdAPI is intentionally kept minimal and user-friendly, without added complexities.
- **AWS Lambda Compatibility**: It's purpose-built for AWS Lambda, taking into account the unique characteristics of serverless environments.
- **Support for Function URL and API Gateway**: PyLambdAPI adeptly handles requests from both function URLs and API Gateway.
- **Middleware Support**: Easily incorporate middleware functions into your routes for custom request and response processing.
- **Logging**: PyLambdAPI comes with built-in request and response logging, simplifying troubleshooting.
- **Flexible Routing**: Define API routes with various HTTP methods using a straightforward and intuitive syntax.## Installation
To install PyLambdAPI using `pip`:
```bash
pip install pylambdapi
```## Getting Started
To create a serverless API with PyLambdAPI, follow these steps:
1. Import the `LambdaFlask` class from the library.
2. Create a `LambdaFlask` instance.
3. Define your routes and route handlers.
4. Deploy your Lambda function, and your API is ready to roll!```python
from pylambdapi import LambdaFlask# Create a LambdaFlask instance
app = LambdaFlask(source='function_url')# Define a route and a route handler
@app.route_decorator('/hello', http_methods=['GET'])
def hello():
return 'Hello, Lambda World!'# Deploy your Lambda function and configure your API Gateway or function URL to point to it.
```## Routing and Handlers
PyLambdAPI employs a straightforward route and handler definition. You can specify HTTP methods, create middleware, and structure your response with ease.
```python
# Define a route and a route handler
@app.route_decorator('/users', http_methods=['GET', 'POST'])
def users():
# Handle GET or POST requests here
# Return your response# Add middleware to a route
@app.route_decorator('/private', http_methods=['GET'], middlewares=[MyCustomMiddleware()])
def private_route():
# Middleware processes the request before reaching this handler
# Handle the request and return a response
```## Logging
PyLambdAPI offers built-in request and response logging for effortless troubleshooting. You can enable or disable request and response logging as needed.
```python
app = LambdaFlask(source='api_gateway_proxy', enable_request_logging=True, enable_response_logging=False)
```## Middleware
You can include custom middleware functions to process requests and responses before they reach the route handler. Middleware provides flexibility in managing various aspects of your API, such as authentication, data validation, or response formatting.
```python
class MyCustomMiddleware:
def process_request(self, req_params):
# Process the request before reaching the route handler
return req_paramsdef process_response(self, response):
# Process the response before returning it
return response
```## Route Access
PyLambdAPI supports both function URLs and API Gateway. You can choose the source that best suits your use case.
```python
# Initialize LambdaFlask for function URL
app = LambdaFlask(source='function_url')# Initialize LambdaFlask for API Gateway
app = LambdaFlask(source='api_gateway_proxy')
```## Contributing
This framework is open source and new; feel free to contribute by improving documentation, adding new features, requesting new features, or fixing bugs. To contribute, fork this repository and submit a pull request with your changes. Your contributions will be greatly appreciated!## License
PyLambdAPI is released under the GNU General Public License v3.0. See the [LICENSE](LICENSE) file for more details.
## Contact
For questions or issues, please feel free to open a GitHub issue or reach out at [[email protected]](mailto:[email protected]).
## Acknowledgments
I created PyLambdAPI to simplify the process of building APIs for AWS Lambda functions. I hope it makes your serverless development experience more enjoyable.
---
*Disclaimer: PyLambdAPI is not an official AWS product but a third-party library developed to simplify API creation for AWS Lambda.*