A little library to simplify building small APIs on top of API Gateway and Lambda.
Project description
Deez
A little library to simplify building small APIs on top of AWS Lambda and API Gateway.
This library is still in development. It is sufficient for ProdPerfect's needs but it may not be for yours. Use at your own risk.
Getting Started
Requirements
- Python 3.9+
- Blinker 1.4+
Installation
pip install deez
Creating a resource
Your resource must implement at least one HTTP verb (get, post, put, etc.,)
from deez.resource import Resource
from deez.response import JsonResponse
class MyResource(Resource):
def get(self, request, *args, **kwargs):
return JsonResponse(data={'message': 'hello world'})
Example of how to use
app.py
from deez import Deez
from deez.resource import Resource
from deez.response import JsonResponse
from deez.urls import path
class HelloWorldView(Resource):
def get(self, request, *args, **kwargs):
return JsonResponse(data={'message': 'hello world'})
app = Deez()
app.register_route(path("hello/world", HelloWorldView))
# or you can use regex
app.register_route(r'^hello/world$', HelloWorldView)
`middleware.py`
```python
from deez.middleware import Middleware
class User:
# fake user object
pass
class AuthMiddleware(Middleware):
def before_request(self, request):
# perhaps you want to authenticate the user and attach it to the request object
request.user = User()
return request
settings.py
# middleware runs before views are called and before the response is returned
# so you can manipulate the response and requests objects.
MIDDLEWARE = ['middleware.AuthMiddleware']
handler.py
from app import app
def handle_event(event, context):
return app.process_request(event, context)
Signals
Deez supports signals. Signals are a way to hook into the request/response lifecycle. This can be useful for logging metrics or doing other things such as managing database connections.
from deez.core.signals import request_finished, request_started
@request_started.connect
def my_callback(sender, **kwargs):
print('request started')
@request_finished.connect
def my_other_callback(sender, **kwargs):
print('request finished')
Project Structure
See the examples
directory for a working example.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file deez-1.0.4.tar.gz
.
File metadata
- Download URL: deez-1.0.4.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 991246fee7e645ae44f9583cfb9d883cdd3888135c4d4906b705dc03db6028eb |
|
MD5 | 7bcd3d1a51a6c6016348c7f21005184f |
|
BLAKE2b-256 | cc756e12027867117b684c80753854301001d87c328f9d8cd38a918d144cbb13 |
File details
Details for the file deez-1.0.4-py3-none-any.whl
.
File metadata
- Download URL: deez-1.0.4-py3-none-any.whl
- Upload date:
- Size: 16.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7c434f9b5b218d274265f274b0da81f61ee0e2dba2ed52dedb0f4570fadb9b4 |
|
MD5 | 59def872f67c877e1a66771e7c93775c |
|
BLAKE2b-256 | d3e1bb811064ae61b588d1dd8d16131a3042e278099ac4171dd5c39369692739 |