Skip to main content

Code style: black Checks PyPI Release

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.

Metadata

Release files for deez 1.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for deez 1.0.4
File Size Uploaded
deez-1.0.4.tar.gz 11.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for deez 1.0.4
File Interpreter ABI Platform
deez-1.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 28.2 kB

Release files / deez-1.0.4.tar.gz

Download URL deez-1.0.4.tar.gz
Size 11.6 kB
Tags Source
SHA-256 checksum
How to use checksums
991246fee7e645ae44f9583cfb9d883cdd3888135c4d4906b705dc03db6028eb
BLAKE2b-256 checksum
How to use checksums
cc756e12027867117b684c80753854301001d87c328f9d8cd38a918d144cbb13
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.4

Release files / deez-1.0.4-py3-none-any.whl

Download URL deez-1.0.4-py3-none-any.whl
Size 16.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f7c434f9b5b218d274265f274b0da81f61ee0e2dba2ed52dedb0f4570fadb9b4
BLAKE2b-256 checksum
How to use checksums
d3e1bb811064ae61b588d1dd8d16131a3042e278099ac4171dd5c39369692739
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.4

Release history Release notifications | RSS feed

This release

1.0.4 This release

2 release files

1.0.3

2 release files

1.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page