{"id":15321930,"url":"https://github.com/akmamun/mvc-flask-pymongo","last_synced_at":"2025-04-15T02:37:22.020Z","repository":{"id":51166344,"uuid":"180423948","full_name":"akmamun/mvc-flask-pymongo","owner":"akmamun","description":"Model-Based Python and Mongo DB Web Restful Service ","archived":false,"fork":false,"pushed_at":"2019-04-16T10:56:39.000Z","size":27,"stargazers_count":26,"open_issues_count":0,"forks_count":19,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T14:22:13.776Z","etag":null,"topics":["api-validator","flask","flask-model","flask-mongodb","flask-mongoengine","flask-validator","microservice","mongodb","mvc-pattern","python","python-mongodb","python-validator","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/akmamun.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":"2019-04-09T18:11:08.000Z","updated_at":"2025-01-24T09:47:16.000Z","dependencies_parsed_at":"2022-09-18T12:20:39.406Z","dependency_job_id":null,"html_url":"https://github.com/akmamun/mvc-flask-pymongo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akmamun%2Fmvc-flask-pymongo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akmamun%2Fmvc-flask-pymongo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akmamun%2Fmvc-flask-pymongo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akmamun%2Fmvc-flask-pymongo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/akmamun","download_url":"https://codeload.github.com/akmamun/mvc-flask-pymongo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248995101,"owners_count":21195497,"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":["api-validator","flask","flask-model","flask-mongodb","flask-mongoengine","flask-validator","microservice","mongodb","mvc-pattern","python","python-mongodb","python-validator","validation"],"created_at":"2024-10-01T09:13:40.529Z","updated_at":"2025-04-15T02:37:21.995Z","avatar_url":"https://github.com/akmamun.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Model Based Validator design for Flask (Python) and Mongo DB\n#### Model based custom validation for flask (python). Use Flask server and mongo db. Integrate with any SPA API development.  \n\u003cp align=\"center\"\u003e\n  \u003cimg width=\"340\" height=\"160\" src=\"https://miro.medium.com/max/1266/1*vB-cUmm1_dBBt-4JtL0u5g.jpeg\"\u003e\n\u003c/p\u003e\n\n### Create [virtual environment]('https://docs.python.org/3/library/venv.html) and install requirements \n```sh\npip install -r requirements.txt\n```\n### Configure Database\n#### From [db_config.json](src/db_config.json) configure datbase url, name, user and password \n```json\n {\n   \"db\": {\n            \"url\" : \"mongodb://localhost:27017/\",\n            \"name\" :\"db_name\",  \n            \"user\" :\"\",\n            \"password\" :\"\"\n    }\n }\n``` \n\n## In model update collection name and desire fields name and fields type. For example see todo [model](src/models/todo.py) file\n#### From [model](src/models) folder write your individual model and configure db collection name, fields name and fields type\n#### Example\n##### In todo [model](src/models/todo.py) update collection name, fields name and fields type\n```py\ncollection_name = 'todos'   # collection name\nfields = {   \n    \"title\"     : \"string\",\n    \"body\"      : \"string\",\n    \"created\"   : \"datatime\"\n} \n```\n\n##### Update required fields, optional fields from todo [model](src/models/todo.py)\n```py\ncreate_required_fields = []  # example create_required_fields = [\"title\", \"body\"]\ncreate_optional_fields = []  # example create_required_fields = [\"created\"]\nupdate_required_fields = []\nupdate_optional_fields = []\n```\n#### Example \n```py\ncreate_required_fields = [\"title\", \"body\"] \ncreate_optional_fields = []  \nupdate_required_fields = [\"title\", \"body\"]\nupdate_optional_fields = []\n```\n#### In [Database](src/factory/database.py) insert, find , find_by_id, update and delete methods are generalize methods.  \n#### Those methods are call from [model](src/models) \n- `insert` method store data to database after confirm validation from model \n- `find` method retries all data from mongo database \n- `find_by_id` method retries back a single search data\n- `update` method store updated data to database with corresponding id \n- and `delete` method delete data from database with corresponding id \n\n#### List of Todo Routes\n| Request | Endpoint |  Details |\n| --- | --- | --- |\n| `GET` | `http://127.0.0.1:5000/todos`| Get All|\n| `GET` | `http://127.0.0.1:5000/todos/todo_id`| Get Single Id|\n| `POST` | `http://127.0.0.1:5000/todos`| Insert One|\n| `PUT` | `http://127.0.0.1:5000/todos/todo_id`| Update One|\n| `DELETE` | `http://127.0.0.1:5000/todos/todo_id`| Delete One|\n\n- To see route list type cli `flask routes`\n\n### Lets run the App\n```sh\npython app.py \n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakmamun%2Fmvc-flask-pymongo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakmamun%2Fmvc-flask-pymongo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakmamun%2Fmvc-flask-pymongo/lists"}