{"id":17161648,"url":"https://github.com/eastwu5788/pre-request","last_synced_at":"2025-04-13T13:23:53.581Z","repository":{"id":23959828,"uuid":"100257925","full_name":"Eastwu5788/pre-request","owner":"Eastwu5788","description":"✨  Powerful python framework for validate request params, designed for Flask","archived":false,"fork":false,"pushed_at":"2023-05-23T03:10:19.000Z","size":473,"stargazers_count":56,"open_issues_count":5,"forks_count":7,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-11T18:45:54.515Z","etag":null,"topics":["filter","flask","request","translation","validation"],"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/Eastwu5788.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGES.rst","contributing":"CONTRIBUTING.rst","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-08-14T10:56:59.000Z","updated_at":"2024-11-22T01:58:21.000Z","dependencies_parsed_at":"2022-07-11T06:32:36.290Z","dependency_job_id":null,"html_url":"https://github.com/Eastwu5788/pre-request","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Eastwu5788%2Fpre-request","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Eastwu5788%2Fpre-request/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Eastwu5788%2Fpre-request/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Eastwu5788%2Fpre-request/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Eastwu5788","download_url":"https://codeload.github.com/Eastwu5788/pre-request/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248718837,"owners_count":21150642,"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":["filter","flask","request","translation","validation"],"created_at":"2024-10-14T22:43:33.986Z","updated_at":"2025-04-13T13:23:53.558Z","avatar_url":"https://github.com/Eastwu5788.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":".. raw:: html\n\n    \u003cp align=\"center\"\u003e\n        \u003ca href=\"#readme\"\u003e\n            \u003cimg alt=\"Pre-request logo\" src=\"https://pre-request.readthedocs.io/en/master/_images/logo.jpg\"\u003e\n        \u003c/a\u003e\n    \u003c/p\u003e\n    \u003cp align=\"center\"\u003e\n        \u003ca href=\"https://github.com/Eastwu5788/pre-request/actions/workflows/intergration.yml\"\u003e\u003cimg alt=\"CI\" src=\"https://github.com/Eastwu5788/pre-request/actions/workflows/intergration.yml/badge.svg\"\u003e\u003c/a\u003e\n        \u003ca href=\"https://codecov.io/gh/Eastwu5788/pre-request\"\u003e\u003cimg alt=\"Coveralls\" src=\"https://codecov.io/gh/Eastwu5788/pre-request/branch/master/graph/badge.svg?token=KAB3VL6B7J\"\u003e\u003c/a\u003e\n        \u003ca href=\"https://github.com/Eastwu5788/pre-request/blob/master/LICENSE\"\u003e\u003cimg alt=\"License\" src=\"https://img.shields.io/pypi/l/pre-request?color=brightgreen\"\u003e\u003c/a\u003e\n        \u003ca href=\"https://pre-request.readthedocs.io/en/master/\"\u003e\u003cimg alt=\"Docs\" src=\"https://readthedocs.org/projects/pre-request/badge/?version=master\"\u003e\u003c/a\u003e\n        \u003ca href=\"https://pypi.org/project/pre-request/\"\u003e\u003cimg alt=\"PyPI\" src=\"https://img.shields.io/pypi/v/pre-request?color=brightgreen\"\u003e\u003c/a\u003e\n        \u003ca href=\"https://gitter.im/pre-request/community?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\"\u003e\u003cimg alt=\"IM\" src=\"https://badges.gitter.im/pre-request/community.svg\"/\u003e\u003c/a\u003e\n    \u003c/p\u003e\n\n\n========\n\nThis framework is designed to validate request params for `Flask` web framework.\n\nIt has the following `unique` features:\n\n* Cross Field and Cross Struct validations\n* Array and Map diving, which allows any or all levels of a multidimensional field to be validated\n* Customizable error response\n\n\nInstall\n-----------\n\nyou can simply install it by PyPi:\n\n::\n\n    pip install pre-request\n\n\nDocument\n----------\n\n`pre-request` manual could be found at: https://pre-request.readthedocs.io/en/master/index.html\n\n\nA Simple Example\n------------------\n\nThis is very easy to use `pre-request` in your project\n\n.. code-block:: python\n\n   from flask import Flask\n\n   from pre_request import pre, Rule\n\n   app = Flask(__name__)\n\n   args = {\n      \"userId\": Rule(type=int, required=True)\n   }\n\n   @app.route(\"/\")\n   @pre.catch(args)\n   def hello_world(params):\n      from flask import g\n      return str(params == g.params)\n\nwhat happened in this code ?\n\n1. Use `pre-request` library to import a global object `pre`\n2. Define request params rule, e.g. `userId` must be type of `int` and required\n3. Use `@pre.catch(req_params)` to filter input value\n4. Use `~flask.g` or `def hello_world(params)` to get formatted input value。\n\n\nComplex Example\n-----------------\n\nWe use a very complex example to show the powerful of this framework. Otherwise you can find amount of examples at: `https://github.com/Eastwu5788/pre-request/tree/master/examples`\n\n.. code-block:: python\n\n    from flask import Flask\n    from pre_request import pre, Rule\n\n    args = {\n        \"userFirst\": {\n            \"userId\": Rule(type=int, required=False),\n            \"socialInfo\": {\n                \"gender\": Rule(type=int, enum=[1, 2], default=1),\n                \"age\": Rule(type=int, gte=18, lt=80),\n                \"country\": Rule(required=True, deep=False)\n            }\n        },\n        \"userSecond\": {\n            \"userId\": Rule(type=int, required=False, neq_key=\"userFirst.userId\"),\n            \"friends\": Rule(type=dict, required=True, multi=True, structure={\n                \"userId\": Rule(type=int, required=True, dest=\"user_id\"),\n                \"userName\": Rule(type=str, required=True, dest=\"user_name\")\n            })\n        }\n    }\n\n\n    app = Flask(__name__)\n    app.config[\"TESTING\"] = True\n    client = app.test_client()\n\n    @app.route(\"/structure\", methods=[\"GET\", \"POST\"])\n    @pre.catch(args)\n    def structure_handler(params):\n        return str(params)\n\n\n    if __name__ == \"__main__\":\n        resp = app.test_client().post(\"/structure\", json={\n            \"userFirst\": {\n                \"userId\": \"13\",\n                \"socialInfo\": {\n                    \"age\": 20,\n                }\n            },\n            \"userSecond\": {\n                \"userId\": 14,\n                \"friends\": [\n                    {\n                        \"userId\": 13,\n                        \"userName\": \"Trump\"\n                    }\n                ]\n            },\n            \"country\": \"CN\",\n            \"userFirst.socialInfo.gender\": 1\n        })\n\n        print(resp.get_data(as_text=True))\n\n\nUse parse\n-------------\n\nWe can use function `pre.parse` instead of decorator `@pre.catch()`\n\n.. code-block:: python\n\n    args = {\n        \"params\": Rule(email=True)\n    }\n\n    @app.errorhandler(ParamsValueError)\n    def params_value_error(e):\n        return pre.fmt_resp(e)\n\n\n    @app.route(\"/index\")\n    def example_handler():\n        rst = pre.parse(args)\n        return str(rst)\n\n\nContributing\n--------------\n\nHow to make a contribution to Pre-request, see the `contributing`_.\n\n.. _contributing: https://github.com/Eastwu5788/pre-request/blob/master/CONTRIBUTING.rst\n\n\nCoffee\n---------\n\nPlease give me a cup of coffee, thank you!\n\nBTC: 1657DRJUyfMyz41pdJfpeoNpz23ghMLVM3\n\nETH: 0xb098600a9a4572a4894dce31471c46f1f290b087\n\n\nLinks\n------------\n* Documentaion: https://pre-request.readthedocs.io/en/master/index.html\n* Release: https://pypi.org/project/pre-request/\n* Code: https://github.com/Eastwu5788/pre-request\n* Issue tracker: https://github.com/Eastwu5788/pre-request/issues\n* Test status: https://coveralls.io/github/Eastwu5788/pre-request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feastwu5788%2Fpre-request","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feastwu5788%2Fpre-request","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feastwu5788%2Fpre-request/lists"}