{"id":18020661,"url":"https://github.com/shangsky/flask-seek","last_synced_at":"2025-12-30T08:32:19.721Z","repository":{"id":57430708,"uuid":"375385565","full_name":"ShangSky/flask-seek","owner":"ShangSky","description":"自动发现并注册蓝图和全局异常处理等一系列装饰器，避免循环导入","archived":true,"fork":false,"pushed_at":"2022-04-15T12:17:11.000Z","size":17,"stargazers_count":23,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-19T23:18:22.013Z","etag":null,"topics":["flask","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ShangSky.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-06-09T14:32:38.000Z","updated_at":"2025-03-14T01:56:22.000Z","dependencies_parsed_at":"2022-09-13T15:21:00.367Z","dependency_job_id":null,"html_url":"https://github.com/ShangSky/flask-seek","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShangSky%2Fflask-seek","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShangSky%2Fflask-seek/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShangSky%2Fflask-seek/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShangSky%2Fflask-seek/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ShangSky","download_url":"https://codeload.github.com/ShangSky/flask-seek/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245738893,"owners_count":20664364,"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":["flask","python"],"created_at":"2024-10-30T06:07:00.475Z","updated_at":"2025-12-14T18:21:48.473Z","avatar_url":"https://github.com/ShangSky.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# flask-seek\n\n- [简体中文](README_zh.md)\n\nAn flask extension to make your code more elegant.\n\nAutomatically discover and register  Blueprint and decorators (such as before_request).\n\n## Requirements\n\n- Python 3.6+\n- Flask 1.1.0+\n\n## Installation\n\n```shell\n$ pip install flask-seek\n```\n\n## A Simple Example\n\n- Project structure and content\n\n```shell\nproject\n    hello.py\n    main.py\n```\n\n```python\n# main.py\nfrom flask import Flask\nfrom flask_seek import seek\n\napp = Flask(__name__)\n\n\nseek(app, blueprint_modules=[\"hello\"])\n\nif __name__ == \"__main__\":\n    app.run()\n```\n\n```python\n# hello.py\nfrom flask import Blueprint\n\nhello_bp = Blueprint(\"hello\", __name__)\n\n\n@hello_bp.route(\"/\")\ndef hello():\n    return {\"msg\": \"Hello\"}\n```\n\n- start\n\n```\n$ python main.py\n * Serving Flask app 'main' (lazy loading)\n * Environment: production\n   WARNING: This is a development server. Do not use it in a production deployment.\n   Use a production WSGI server instead.\n * Debug mode: off\n * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)\n```\n\n```shell\n$ curl -s http://127.0.0.1:5000/\n{\"msg\":\"Hello\"}\n```\n\n## Example upgrade\n\n```python\nproject\n\tcommon\n        __init__.py\n        error_handler.py\n        middleware.py\n\tcontroller\n        __init__.py\n        hello.py\n\tmain.py\n```\n\n```python\n# main.py\nfrom flask import Flask\nfrom flask_seek import seek\n\napp = Flask(__name__)\n\n\nseek(app, blueprint_deep_modules=[\"controller\"], decorator_modules=[\"common\"])\n\nif __name__ == \"__main__\":\n    app.run()\n```\n\n```python\n# hello.py\nfrom flask import Blueprint\n\nhello_bp = Blueprint(\"hello\", __name__)\n\n\n@hello_bp.route(\"/\")\ndef hello():\n    print(\"hello\")\n    return {\"msg\": \"Hello\"}\n\n@hello_bp.route(\"/error\")\ndef error():\n    a = 1 / 0\n    return {\"msg\": \"Hello\"}\n```\n\n```python\n# error_handler.py\nfrom flask_seek import ff\n\n\n@ff.errorhandler(Exception)\ndef err(e):\n    return {\"msg\": \"Server Error\"}\n```\n\n```python\n# middlerware.py\nfrom flask_seek import df\n\n\n@df.before_request\ndef before():\n    print(\"before_request\")\n\n\n@df.after_request\ndef after(resp):\n    print(\"after_request\")\n    return resp\n```\n\n- start\n\n```shell\n$ python main.py\n * Serving Flask app 'main' (lazy loading)\n * Environment: production\n   WARNING: This is a development server. Do not use it in a production deployment.\n   Use a production WSGI server instead.\n * Debug mode: off\n * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)\n```\n\n- Blueprint registered automatically\n\n```shell\n$ curl -s http://127.0.0.1:5000/\n{\"msg\":\"Hello\"}\n```\n\n- before_request, after_request take effect\n\n```shell\n$ python main.py \n * Serving Flask app 'main' (lazy loading)\n * Environment: production\n   WARNING: This is a development server. Do not use it in a production deployment.\n   Use a production WSGI server instead.\n * Debug mode: off\n * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)\nbefore_request\nhello\nafter_request\n127.0.0.1 - - [11/Jun/2021 00:06:13] \"GET / HTTP/1.1\" 200 -\n```\n\n- errorhandler take effect\n\n```shell\n$ curl -s http://127.0.0.1:5000/error\n{\"msg\":\"Server Error\"}\n```\n\n## Guide\n\n### seek\n\n- parameters\n\n  - instance - flask or buleprint instance \n\n  - blueprint_modules - List of blueprint modules path  such as `[\"common\", \"common.demo\"]`\n\n  - blueprint_deep_modules - It will recursively query all blueprint modules of the package\n\n  - decorator_modules - List of flask decorator modules path\n\n  - decorator_deep_modules - It will recursively query all decorator modules of the package\n\n- example\n\n```\nproject\n\tcommon\n        __init__.py\n        error_handler.py\n        middleware.py\n        demo\n        \t__init__.py\n        \ta.py   \t\n\tmain.py\n```\n\n```python\n# main.py\nfrom flask import Flask\nfrom flask_seek import seek\n\napp = Flask(__name__)\n\n\nseek(app, decorator_modules=[\"common\"]) # will search error_handler.py, middleware.py\nseek(app, decorator_modules=[\"common.middleware\"]) # will search middleware.py\nseek(app, decorator_deep_modules=[\"common\"]) # will search error_handler.py, middleware.py, a.py\nseek(app, decorator_modules=[\"common.demo\"]) # will search a.py\n```\n\n### df\n\ndecorator without parameters\n\n```python\nfrom flask_seek import df\n\n\n@df.before_request\ndef before():\n    print(\"before_request\")\n```\n\n### ff\n\ndecorator with parameters\n\n```python\nfrom flask_seek import ff\n\n\n@ff.errorhandler(Exception)\ndef err(e):\n    return {\"msg\": \"Server Error\"}\n```\n\n## License\n\nThis project is licensed under the terms of the MIT license.\n\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshangsky%2Fflask-seek","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshangsky%2Fflask-seek","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshangsky%2Fflask-seek/lists"}