Package: lumi
Lumi 💧Lumi is a nano framework to convert your python functions into a REST API without any extra headache.This library is created by taking the concept ofRPCand blended withREST APIspecs.We need to just register the function and it will be available as a REST API.Web-server written withGunicornLocal development server provided for rapid development and prototyping.InstallationpipinstalllumiFunction <--> API mappingHow to use 🤔Let's create a simple function to add two numbers.defadd(a,b):returna+bdefsubtract(a,b):returna-bNow, we want to expose this function as a REST API. We can do this by registering the function with Lumi.# app.pyfromlumiimportLumiapp=Lumi()app.register(add)# Registering the functionapp.register(subtract)app.runServer(host="127.0.0.1",port=8080)Noice 🎉🎉  API has been generatedRun the sever bypython app.pyYou are going to see this in your terminal[2022-11-24 17:32:08 +0530] [10490] [INFO] Starting gunicorn 20.1.0
[2022-11-24 17:32:08 +0530] [10490] [INFO] Listening at: http://127.0.0.1:8080 (10490)
[2022-11-24 17:32:08 +0530] [10490] [INFO] Using worker: sync
[2022-11-24 17:32:08 +0530] [10492] [INFO] Booting worker with pid: 10492
...
...
[2022-11-24 17:32:08 +0530] [10500] [INFO] Booting worker with pid: 10500Congratulations 👏. Our Server is online.The above code will generate a REST API with the following details.Endpoint :127.0.0.1:8080Route :/addMethod :POSTSample Request Body :{"a": 1, "b": 2}Let's run the API and test it.curl -X POST -H "Content-Type: application/json" -d '{"a": 1, "b": 2}' http://127.0.0.1:8080/addOutput{"exit_code":0,"status_code":200,"result":3,"error":""}Custom RoutingNow you may think, the function name will be always same as the route. But, you can change the route by passing the route parameter.app.register(add,route="/addition")Custom Request MethodBy default, the request method isPOST. But, you can change it by passing the method parameter. Currently, it supportsGET,POST,PUTandPATCHmethods.fromlumiimportLumi,RequestMethodapp=Lumi()defadd(a,b):returna+b# Default : Register function for POST methodapp.register(add)# Register function for GET methodapp.register(add,request_method=RequestMethod.GET)# Register function for POST methodapp.register(add,request_method=RequestMethod.POST)# Register function for PUT methodapp.register(add,request_method=RequestMethod.PUT)# Register function for PATCH methodapp.register(add,request_method=RequestMethod.PATCH)app.runServer()🟡Pay attention before using GET request :If you are usingGETmethodYou need to pass the parameters in the query string, asGETdont support request body.All those arguments, that will be passed to function will be inStringformat. So take care to convert them to the desired type in your function.Send FileSend file to user by returning the file object.fromlumiimportLumi,RequestMethodapp=Lumi()defdownload_file():returnopen("file.txt","rb")# Return file objectapp.register(download_file)Debug ModeBy default, the debug mode isTrue. But, you can change it by passing the debug parameter.# app.pyfromlumiimportLumiapp=Lumi(debug=False)...Status CodesStatus CodeDescription200Request successfully executed and No Error happened during function execution500Request was received but there was an error during function execution400Bad Request (Possible Reason - The required parameters for the function has not provided)405Method Not Allowed (Lumi only supportsPOSTrequest)404The route has no function associated with thatExit CodesExit CodeDescription0No Error1ErrorNote : If the function has some error , you can expect the exit code to be 1 and the error message in the response.Task ListsBase SystemAdd support for default parameters that is provided in the functionDebug mode  and logging supportMake available GET request for the functionProvide option to override POST with PUT if the user wantsAdd support to send file directly to userAdd support to serve files through a public folder [Customizable]Add suport for middleware integrationSupport nested routing of urlsFor local development, create an file observer that can automatically reload the server when the file is changed.Add support for object serialization and deserialization based on argument types of functionContributingContributions are always welcome!Our communityTanmoy SarkarAmir M. GhanemMatheus Felipe0xflotusSupport