{"id":13611517,"url":"https://github.com/tanmoysrt/lumi","last_synced_at":"2025-04-13T04:34:44.482Z","repository":{"id":63708932,"uuid":"570063534","full_name":"tanmoysrt/lumi","owner":"tanmoysrt","description":"Lumi is an nano framework to convert your python functions into a REST API without any extra headache.","archived":true,"fork":false,"pushed_at":"2022-12-22T08:46:20.000Z","size":102,"stargazers_count":629,"open_issues_count":3,"forks_count":21,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-04-09T16:16:19.876Z","etag":null,"topics":["apps","framework","http","python","rpc","web"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/lumi/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tanmoysrt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.MD","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-11-24T08:56:22.000Z","updated_at":"2025-04-07T10:49:50.000Z","dependencies_parsed_at":"2023-01-30T06:16:53.976Z","dependency_job_id":null,"html_url":"https://github.com/tanmoysrt/lumi","commit_stats":null,"previous_names":["tanmoysrt/lumi","lumi-official/lumi","tanmoy741127/lumi"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanmoysrt%2Flumi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanmoysrt%2Flumi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanmoysrt%2Flumi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanmoysrt%2Flumi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tanmoysrt","download_url":"https://codeload.github.com/tanmoysrt/lumi/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248126362,"owners_count":21051909,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["apps","framework","http","python","rpc","web"],"created_at":"2024-08-01T19:01:56.877Z","updated_at":"2025-04-13T04:34:44.243Z","avatar_url":"https://github.com/tanmoysrt.png","language":"Python","funding_links":["https://www.buymeacoffee.com/tanmoysarkar"],"categories":["Python"],"sub_categories":[],"readme":"# Lumi 💧 \u003ca href=\"https://hits.seeyoufarm.com\"\u003e\u003cimg src=\"https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2FTanmoy741127%2Flumi\u0026count_bg=%2379C83D\u0026title_bg=%23555555\u0026icon=\u0026icon_color=%23E7E7E7\u0026title=hits\u0026edge_flat=false\"/\u003e\u003c/a\u003e\n\n\u003cimg align=\"right\" src=\"https://raw.githubusercontent.com/Tanmoy741127/cdn/main/lumi/lumi-logo.png\" height=\"100px\"/\u003e\n\nLumi is a nano framework to convert your python functions into a REST API without any extra headache.\n\n* This library is created by taking the concept of **RPC** and blended with **REST API** specs. \n* We need to just register the function and it will be available as a REST API. \n* Web-server written with **Gunicorn**\n* Local development server provided for rapid development and prototyping.\n\n## Installation\n\n```bash\npip install lumi\n```\n\n## Function \u003c--\u003e API mapping\n![function - API mapping](https://raw.githubusercontent.com/Tanmoy741127/cdn/main/lumi/function-api-map.png)\n\n\n## How to use 🤔\n\nLet's create a simple function to add two numbers.\n\n```python\ndef add(a, b):\n    return a + b\n\ndef subtract(a, b):\n    return a - b\n```\n\nNow, we want to expose this function as a REST API. We can do this by registering the function with Lumi.\n\n```python\n# app.py\n\nfrom lumi import Lumi\n\napp = Lumi()\n\napp.register(add) # Registering the function\napp.register(subtract)\n\napp.runServer(host=\"127.0.0.1\", port=8080)\n```\n\nNoice 🎉🎉  API has been generated\n\nRun the sever by\n```\npython app.py\n```\nYou are going to see this in your terminal \n```\n[2022-11-24 17:32:08 +0530] [10490] [INFO] Starting gunicorn 20.1.0\n[2022-11-24 17:32:08 +0530] [10490] [INFO] Listening at: http://127.0.0.1:8080 (10490)\n[2022-11-24 17:32:08 +0530] [10490] [INFO] Using worker: sync\n[2022-11-24 17:32:08 +0530] [10492] [INFO] Booting worker with pid: 10492\n...\n...\n[2022-11-24 17:32:08 +0530] [10500] [INFO] Booting worker with pid: 10500\n```\n\nCongratulations 👏. Our Server is online. \n\n\nThe above code will generate a REST API with the following details.\n\n- Endpoint : `127.0.0.1:8080`\n- Route : `/add`\n- Method : `POST`\n- Sample Request Body : `{\"a\": 1, \"b\": 2}`\n\nLet's run the API and test it.\n\n```curl\ncurl -X POST -H \"Content-Type: application/json\" -d '{\"a\": 1, \"b\": 2}' http://127.0.0.1:8080/add\n```\n\nOutput\n\n```json\n{\n    \"exit_code\": 0, \n    \"status_code\": 200, \n    \"result\": 3, \n    \"error\": \"\"\n}\n```\n\n## Custom Routing\nNow you may think, the function name will be always same as the route. But, you can change the route by passing the route parameter.\n\n```python\napp.register(add, route=\"/addition\")\n```\n## Custom Request Method\nBy default, the request method is `POST`. But, you can change it by passing the method parameter. Currently, it supports `GET`, `POST`, `PUT` and `PATCH` methods.\n\n```python\nfrom lumi import Lumi, RequestMethod\n\napp = Lumi()\n\ndef add(a, b):\n    return a+b\n\n# Default : Register function for POST method\napp.register(add)\n# Register function for GET method\napp.register(add, request_method=RequestMethod.GET)\n# Register function for POST method\napp.register(add, request_method=RequestMethod.POST)\n# Register function for PUT method\napp.register(add, request_method=RequestMethod.PUT)\n# Register function for PATCH method\napp.register(add, request_method=RequestMethod.PATCH)\n\napp.runServer()\n```\n\n🟡 **Pay attention before using GET request :**  If you are using `GET` method\n- You need to pass the parameters in the query string, as `GET` dont support request body.\n- All those arguments, that will be passed to function will be in **String** format. So take care to convert them to the desired type in your function.\n\n\n## Send File\nSend file to user by returning the file object.\n\n```python\nfrom lumi import Lumi, RequestMethod\napp = Lumi()\n\ndef download_file():\n    return open(\"file.txt\", \"rb\") # Return file object\n\napp.register(download_file) \n```\n\n## Debug Mode\nBy default, the debug mode is `True`. But, you can change it by passing the debug parameter.\n\n```python\n# app.py\n\nfrom lumi import Lumi\n\napp = Lumi(debug=False)\n...\n```\n\n## Status Codes\n\n| Status Code | Description |\n| --- | --- |\n| 200 | Request successfully executed and No Error happened during function execution |\n| 500 | Request was received but there was an error during function execution |\n| 400 | Bad Request (Possible Reason - The required parameters for the function has not provided) |\n| 405 | Method Not Allowed (Lumi only supports **POST** request) |\n| 404 | The route has no function associated with that |\n\n\n## Exit Codes\n| Exit Code | Description |\n| --- | --- |\n| 0 | No Error |\n| 1 | Error |\n\n\u003e Note : If the function has some error , you can expect the exit code to be 1 and the error message in the response.\n\n## Task Lists\n- [x] Base System\n- [x] Add support for default parameters that is provided in the function\n- [x] Debug mode  and logging support\n- [x] Make available GET request for the function\n- [x] Provide option to override POST with PUT if the user wants\n- [x] Add support to send file directly to user\n- [ ] Add support to serve files through a public folder [Customizable]\n- [ ] Add suport for middleware integration\n- [ ] Support nested routing of urls\n- [ ] For local development, create an file observer that can automatically reload the server when the file is changed.\n- [ ] Add support for object serialization and deserialization based on argument types of function\n\n## Contributing\n\nContributions are always welcome!\n## Our community\n\n\u003c!-- readme: contributors -start --\u003e\n\u003ctable\u003e\n\u003ctr\u003e\n    \u003ctd align=\"center\"\u003e\n        \u003ca href=\"https://github.com/Tanmoy741127\"\u003e\n            \u003cimg src=\"https://avatars.githubusercontent.com/u/57363826?v=4\" width=\"100;\" alt=\"Tanmoy741127\"/\u003e\n            \u003cbr /\u003e\n            \u003csub\u003e\u003cb\u003eTanmoy Sarkar\u003c/b\u003e\u003c/sub\u003e\n        \u003c/a\u003e\n    \u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\n        \u003ca href=\"https://github.com/AmirMGhanem\"\u003e\n            \u003cimg src=\"https://avatars.githubusercontent.com/u/55459991?v=4\" width=\"100;\" alt=\"AmirMGhanem\"/\u003e\n            \u003cbr /\u003e\n            \u003csub\u003e\u003cb\u003eAmir M. Ghanem\u003c/b\u003e\u003c/sub\u003e\n        \u003c/a\u003e\n    \u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\n        \u003ca href=\"https://github.com/matheusfelipeog\"\u003e\n            \u003cimg src=\"https://avatars.githubusercontent.com/u/50463866?v=4\" width=\"100;\" alt=\"matheusfelipeog\"/\u003e\n            \u003cbr /\u003e\n            \u003csub\u003e\u003cb\u003eMatheus Felipe\u003c/b\u003e\u003c/sub\u003e\n        \u003c/a\u003e\n    \u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\n        \u003ca href=\"https://github.com/0xflotus\"\u003e\n            \u003cimg src=\"https://avatars.githubusercontent.com/u/26602940?v=4\" width=\"100;\" alt=\"0xflotus\"/\u003e\n            \u003cbr /\u003e\n            \u003csub\u003e\u003cb\u003e0xflotus\u003c/b\u003e\u003c/sub\u003e\n        \u003c/a\u003e\n    \u003c/td\u003e\u003c/tr\u003e\n\u003c/table\u003e\n\u003c!-- readme: contributors -end --\u003e\n\n## Support\n\u003ca href=\"https://www.buymeacoffee.com/tanmoysarkar\" target=\"_blank\"\u003e\u003cimg src=\"https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png\" alt=\"Buy Me A Coffee\" style=\"height: 60px !important;width: 217px !important;\" \u003e\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftanmoysrt%2Flumi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftanmoysrt%2Flumi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftanmoysrt%2Flumi/lists"}