flask-file-router


Nameflask-file-router JSON
Version 0.0.5 PyPI version JSON
download
home_pagehttps://github.com/kaush26/flask-file-router
SummaryFile Based Routing for Flask Server
upload_time2024-03-27 15:28:37
maintainerNone
docs_urlNone
authorKaushal Prasad Balmiki
requires_python>=3.7
licenseNone
keywords file router flask api python server
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # DISCLAIMER

> This Library currently supports only static routing. The dynamic routing will be added in the future release

# Usage

## Basic Usage

- Create a folder with a name `home` in the root dir of your project. You can rename `home` folder to custom name in `router.config.json` which should be created in the root dir.
- The folder `home` is gonna be workspace directory of your all api routes.
- e.g. for path `home/api.py` the route will `http://localhost:<PORT>/api`
- create and open `app.py` in the root dir of your project.

### app.py

```python
    # app.py
    from flask import Flask
    from flask.cors import CORS
    from flask_file_router.router import Router

    app = Flask(__name__)
    CORS(app)
    app.config['CORS_HEADERS'] = "Content-Type"

    Router(app).run()

    if __name__=="main":
        app.run(host="0.0.0.0", port=4000, debug=True)
```

### home/api.py

```python
   # home/api.py
   from flask import request

   methods = ["POST"]  # put GET for GET request

   def main():  # This function have to be named as main. This gets triggered Whenever it hits api
        body = request['json']
        return ""
```

# Configurations

```json
{
  "root_dir": "./home", // name of the workspace home dir
  "default_index": "__main__.py", // This is the default index route for the given folder
  "ext_exclude_list": ["pyc"], // file with this extension will be ignored
  "ext_include_list": ["py"] //file with this extension will be considered for api router and rest are ignored
}
```

> **Note**: `ext_exclude_list` and `ext_include_list` are exclusive porps. e.g. if `ext_include_list` provided `ext_exclude_list` will be ignored.

## File Structure examples

Consider the following file system structure

- `home/v1/api.py`
- `home/v1/__main__.py`
- `home/v1/get_user.py`

The api router for the above file structure will be as follows

- `https://localhost:4000/v1/api`
- `https://localhost:4000/v1`
- `https://localhost:4000/v1/get_user`

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/kaush26/flask-file-router",
    "name": "flask-file-router",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "File Router, Flask, API, Python, Server",
    "author": "Kaushal Prasad Balmiki",
    "author_email": "kaushalprasad2611@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/dd/80/ff4f62854f079974b45a6752f3fa21b00aa8a72d0445dc8012dcc23b7b59/flask_file_router-0.0.5.tar.gz",
    "platform": null,
    "description": "# DISCLAIMER\n\n> This Library currently supports only static routing. The dynamic routing will be added in the future release\n\n# Usage\n\n## Basic Usage\n\n- Create a folder with a name `home` in the root dir of your project. You can rename `home` folder to custom name in `router.config.json` which should be created in the root dir.\n- The folder `home` is gonna be workspace directory of your all api routes.\n- e.g. for path `home/api.py` the route will `http://localhost:<PORT>/api`\n- create and open `app.py` in the root dir of your project.\n\n### app.py\n\n```python\n    # app.py\n    from flask import Flask\n    from flask.cors import CORS\n    from flask_file_router.router import Router\n\n    app = Flask(__name__)\n    CORS(app)\n    app.config['CORS_HEADERS'] = \"Content-Type\"\n\n    Router(app).run()\n\n    if __name__==\"main\":\n        app.run(host=\"0.0.0.0\", port=4000, debug=True)\n```\n\n### home/api.py\n\n```python\n   # home/api.py\n   from flask import request\n\n   methods = [\"POST\"]  # put GET for GET request\n\n   def main():  # This function have to be named as main. This gets triggered Whenever it hits api\n        body = request['json']\n        return \"\"\n```\n\n# Configurations\n\n```json\n{\n  \"root_dir\": \"./home\", // name of the workspace home dir\n  \"default_index\": \"__main__.py\", // This is the default index route for the given folder\n  \"ext_exclude_list\": [\"pyc\"], // file with this extension will be ignored\n  \"ext_include_list\": [\"py\"] //file with this extension will be considered for api router and rest are ignored\n}\n```\n\n> **Note**: `ext_exclude_list` and `ext_include_list` are exclusive porps. e.g. if `ext_include_list` provided `ext_exclude_list` will be ignored.\n\n## File Structure examples\n\nConsider the following file system structure\n\n- `home/v1/api.py`\n- `home/v1/__main__.py`\n- `home/v1/get_user.py`\n\nThe api router for the above file structure will be as follows\n\n- `https://localhost:4000/v1/api`\n- `https://localhost:4000/v1`\n- `https://localhost:4000/v1/get_user`\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "File Based Routing for Flask Server",
    "version": "0.0.5",
    "project_urls": {
        "Homepage": "https://github.com/kaush26/flask-file-router",
        "repository": "https://github.com/kaush26/flask-file-router"
    },
    "split_keywords": [
        "file router",
        " flask",
        " api",
        " python",
        " server"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "40d71cb0577cfdd80f6a84e34fc8db6c7e0b03c11c831e0c2390fd0df3ce319b",
                "md5": "f81a45ec80642e58122fc815ded43a99",
                "sha256": "d46b32e4ae48760aaf5fa583c1af568c374e38c19eaba55604710e6d1213e402"
            },
            "downloads": -1,
            "filename": "flask_file_router-0.0.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f81a45ec80642e58122fc815ded43a99",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 4848,
            "upload_time": "2024-03-27T15:28:35",
            "upload_time_iso_8601": "2024-03-27T15:28:35.580141Z",
            "url": "https://files.pythonhosted.org/packages/40/d7/1cb0577cfdd80f6a84e34fc8db6c7e0b03c11c831e0c2390fd0df3ce319b/flask_file_router-0.0.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "dd80ff4f62854f079974b45a6752f3fa21b00aa8a72d0445dc8012dcc23b7b59",
                "md5": "18c9b9c9beb316ba31eb1ce92b1c55cd",
                "sha256": "c26e96cc72296ea914ba44104f65b997ef6def1fd30278719554e474cff891c6"
            },
            "downloads": -1,
            "filename": "flask_file_router-0.0.5.tar.gz",
            "has_sig": false,
            "md5_digest": "18c9b9c9beb316ba31eb1ce92b1c55cd",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 7925,
            "upload_time": "2024-03-27T15:28:37",
            "upload_time_iso_8601": "2024-03-27T15:28:37.939734Z",
            "url": "https://files.pythonhosted.org/packages/dd/80/ff4f62854f079974b45a6752f3fa21b00aa8a72d0445dc8012dcc23b7b59/flask_file_router-0.0.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-27 15:28:37",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "kaush26",
    "github_project": "flask-file-router",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "flask-file-router"
}
        
Elapsed time: 1.44756s