An async and lightweight API framework for python
Clone or download
Latest commit 113a192 Sep 30, 2018

README.md

Lemon logo

Build Status Coverage Status Codacy Badge

PyPi Version Python Version PyPI license FOSSA Status

Lemon is an async and lightweight API framework for python . Inspired by Koa and Sanic .

Documentation

https://pylemon.com

Installation

pip install -U pylemon

Hello Lemon

from lemon.app import Lemon
from lemon.context import Context

async def middleware(ctx: Context, nxt):
    ctx.body = {
        'msg': 'hello lemon'
    }
    await nxt()


async def handler(ctx: Context):
    ctx.body['ack'] = 'yeah !'

app = Lemon()

app.use(middleware, handler)

app.listen(port=9999)

Hello Lemon Router

from random import random

from lemon.app import Lemon
from lemon.context import Context
from lemon.router import Router


async def middleware(ctx: Context, nxt):
    ctx.body = {
        'msg': 'hello lemon'
    }
    await nxt()


async def handler1(ctx: Context):
    ctx.body['ack'] = 'yeah !'
    ctx.body['random'] = random()


async def handler2(ctx: Context):
    ctx.body = ctx.req.json


app = Lemon(debug=True)

router = Router()
router.get('/handler1', middleware, handler1)
router.post('/handler2', middleware, handler2)

app.use(router.routes())

app.listen()