{"id":18712,"date":"2017-09-20T12:15:06","date_gmt":"2017-09-20T09:15:06","guid":{"rendered":"http:\/\/www.webcodegeeks.com\/?p=18712"},"modified":"2017-09-19T11:46:54","modified_gmt":"2017-09-19T08:46:54","slug":"flask-recipe-restful-crud-using-sqlalchemy","status":"publish","type":"post","link":"https:\/\/www.webcodegeeks.com\/python\/flask-recipe-restful-crud-using-sqlalchemy\/","title":{"rendered":"Flask Recipe \u2013 RESTful CRUD using sqlalchemy"},"content":{"rendered":"<p>RESTful apps are a thing these days. When your application\u2019s userbase gets quite large and the client could vary from a laptop to an android device to an iOS device, it pays to keep the backend code separate and use the server only for making RESTful calls using HTTP methods that pertain to basic OLTP transactions: SELECT, INSERT, UPDATE and DELETE.<span id=\"more-204\"><\/span><\/p>\n<p>Popular third-party apps like\u00a0<a href=\"https:\/\/en.wikipedia.org\/wiki\/Firebase#Realtime_Database\">Firebase<\/a>\u00a0essentially provide you this same thing \u2013 A REST based front to a database that could be accessed online using simple HTTP methods. But in this tutorial, we will learn how to create such a backend ourselves using Python\u2019s\u00a0<code class=\"highlighter-rouge\">flask<\/code>framework and\u00a0<code class=\"highlighter-rouge\">sqlalchemy<\/code>, a light-weight but powerful ORM library that can access ANY database using its flexible\u00a0<em>sql expression language<\/em>.<\/p>\n<p><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/09\/restful-crud.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-18713\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/09\/restful-crud.png\" alt=\"\" width=\"624\" height=\"380\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/09\/restful-crud.png 624w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/09\/restful-crud-300x183.png 300w\" sizes=\"(max-width: 624px) 100vw, 624px\" \/><\/a><\/p>\n<p>Rather than using firebase, if you develop your own implementation of your back-end, not only will it help you learn and become a better programmer, but also give you a flexible solution that you can scale and change as per your needs. Its also much cheaper to host your own solution on Amazon EC2 (or Lambda) compared to other costlier alternatives.<\/p>\n<p>Contrary to popular thinking, its not very difficult to create a database agnostic backend such as the one represented in the above diagram. With a minimal and powerful web framework such as\u00a0<code class=\"highlighter-rouge\">flask<\/code>, combined with the power of\u00a0<code class=\"highlighter-rouge\">sqlalchemy<\/code>, you can get up and running within minutes. In fact, I\u2019ve developed a prototype version called\u00a0<a href=\"https:\/\/github.com\/prahladyeri\/tiddly\">Tiddly<\/a>\u00a0that essentially does the same thing as above using just 172 lines of Python code. You can refer to that github repository for reference as we proceed through this tutorial, or directly start using it. But make sure you install the following dependencies before running it:<\/p>\n<pre class=\"brush:py\">pip install flask\r\npip install sqlalchemy<\/pre>\n<p>The first step towards creating the app is creating your database models. Once you\u2019ve done the brainstorming and decided what tables and fields you are going to need, you can create a\u00a0<code class=\"highlighter-rouge\">models.py<\/code>\u00a0source file with something like this:<\/p>\n<pre class=\"brush:py\">import sqlalchemy\r\nfrom sqlalchemy import create_engine\r\nfrom sqlalchemy import Column, String, Integer\r\nfrom sqlalchemy.orm import sessionmaker\r\nfrom sqlalchemy.ext.declarative import declarative_base\r\n\r\n#TODO: Change as needed:\r\nengine = create_engine(\"sqlite:\/\/\/tiddly.db\", echo=True)\r\nBase = declarative_base()\r\n\r\nSession = sessionmaker(bind=engine)\r\ndbsession = Session()\r\n\r\nclass User(Base):\r\n\t__tablename__ = \"user\"\r\n\tid = Column(Integer, primary_key=True)\r\n\temail = Column(String)\r\n\tpassword = Column(String)\r\n\tname = Column(String)\r\n\tdef repr(self):\r\n\t\treturn \"&lt;User(name=%s, email=%s, )&gt;\" % (name, email)\r\n\t\t\r\nclass Dual(Base):\r\n\t__tablename__ = \"dual\"\r\n\tid = Column(Integer, primary_key=True)\r\n\ttext = Column(String)\r\n\tdef repr(self):\r\n\t\treturn \"&lt;Dual(id=%s, text=%s, )&gt;\" % (id, text)<\/pre>\n<p>I\u2019m using sqlite database for example here, but you can use any one of your choice. A\u00a0<code class=\"highlighter-rouge\">user<\/code>table is a pretty basic one in almost every app as it is used for authentication. Apart from that, I\u2019ve also created a\u00a0<code class=\"highlighter-rouge\">dual<\/code>\u00a0table just to play around with.<\/p>\n<p>After that, create the second file\u00a0<code class=\"highlighter-rouge\">app.py<\/code>\u00a0that contains our application code. Define the following import statements along with your models as they will come very handy:<\/p>\n<pre class=\"brush:py\">import flask\r\nfrom flask import request, jsonify, session\r\nimport sqlalchemy\r\nfrom sqlalchemy import inspect, desc\r\nimport json\r\nimport models\r\nfrom models import engine, dbsession<\/pre>\n<p>Now, the only thing that remains to be done is the plumbing the\u00a0<code class=\"highlighter-rouge\">HTTP<\/code>\u00a0methods to their respective database operations. You can either create a separate view function for each one or use a single one for all of them. In this example, I\u2019m using a single function for simplicity.<\/p>\n<pre class=\"brush:py; wrap-lines:false\">@app.route(\"\/&lt;table_name&gt;\", methods=[\"POST\", \"PUT\", \"DELETE\", \"FETCH\"])\r\ndef fetch(table_name):\r\n\tprint(\"verb: %s, tablename: %s\" % (request.method, table_name))\r\n\tif request.method == \"POST\" or request.method == \"PUT\":\r\n\t\tdata = request.get_json(force=True)\r\n\t\tprint(\"data:\", data)\r\n\t\ttry:\r\n\t\t\tTableClass = models.get_class_by_tablename(table_name)\r\n\t\t\tif TableClass == None: raise Exception(\"Table not found: %s\" % table_name)\r\n\t\t\tif request.method == \"POST\": #insert data\r\n\t\t\t\tobject = TableClass(**data)\r\n\t\t\t\tdbsession.add(object)\r\n\t\t\t\tdbsession.commit()\r\n\t\t\telse: #update data\r\n\t\t\t\tobject = dbsession.query(TableClass).filter_by(**{\"id\":id}).first()\r\n\t\t\t\tif object == None: raise Exception(\"No data found.\")\r\n\t\t\t\t#object.update(**data)\r\n\t\t\t\tfor key in data.keys():\r\n\t\t\t\t\tsetattr(object, key, data[key])\r\n\t\t\t\t#dbsession.add(object)\r\n\t\t\t\tdbsession.commit()\r\n\t\t\treturn jsonify({\r\n\t\t\t\t\"status\": \"success\",\r\n\t\t\t\t\"id\": object.id,\r\n\t\t\t\t})\r\n\t\texcept Exception as e:\r\n\t\t\treturn jsonify({\r\n\t\t\t\t\"status\": \"error\",\r\n\t\t\t\t\"error\": str(e),\r\n\t\t\t\t})\r\n\telif request.method == \"DELETE\":\r\n\t\ttry:\r\n\t\t\tTableClass = models.get_class_by_tablename(table_name)\r\n\t\t\tif TableClass == None: raise Exception(\"Table not found: %s\" % table_name)\r\n\t\t\tobject = dbsession.query(TableClass).filter_by(**{\"id\":id}).first()\r\n\t\t\tif object == None: raise Exception(\"No data found.\")\r\n\t\t\tdbsession.delete(object)\r\n\t\t\tdbsession.commit()\r\n\t\t\treturn jsonify({\r\n\t\t\t\t\"status\": \"success\",\r\n\t\t\t\t\"id\": object.id,\r\n\t\t\t\t})\r\n\t\texcept Exception as e:\r\n\t\t\treturn jsonify({\r\n\t\t\t\t\"status\": \"error\",\r\n\t\t\t\t\"error\": str(e),\r\n\t\t\t\t})\r\n\telif request.method == \"FETCH\":\r\n\t\ttry:\r\n\t\t\tdata = request.get_json(force=True)\r\n\t\t\tdata = json.loads(data)\r\n\t\t\tprint(\"data: \", data)\r\n\t\t\tprint(\"data-type: \", type(data))\r\n\t\t\tTableClass = models.get_class_by_tablename(table_name)\r\n\t\t\tif TableClass == None: raise Exception(\"Table not found: %s\" % table_name)\r\n\t\t\t\r\n\t\t\tquery = dbsession.query(TableClass).filter_by(**data['where'])\r\n\t\t\tif 'orderby' in data:\r\n\t\t\t\tfor cname in data['orderby'].split(','):\r\n\t\t\t\t\treverse = False\r\n\t\t\t\t\tif cname.endswith(' desc'):\r\n\t\t\t\t\t\treverse = True\r\n\t\t\t\t\t\tcname = cname[:-5]\r\n\t\t\t\t\telif cname.endswith(' asc'):\r\n\t\t\t\t\t\tcname = cname[:-4]\r\n\t\t\t\t\tprint(\"cname: \", cname)\r\n\t\t\t\t\tcolumn = getattr(TableClass, cname)\r\n\t\t\t\t\tif reverse: column = desc(column)\r\n\t\t\t\t\tquery = query.order_by(column)\r\n\t\t\tif 'limit' in data:\r\n\t\t\t\tquery = query.limit(data['limit'])\r\n\t\t\t\tquery = query.offset(data['offset'])\r\n\t\t\tobject = query.all()\r\n\t\t\tdata = [object_as_dict(t) for t in object]\r\n\t\t\treturn jsonify({\r\n\t\t\t\t\"status\": \"success\", \r\n\t\t\t\t\"data\": data\r\n\t\t\t\t})\r\n\t\texcept Exception as e:\r\n\t\t\treturn jsonify({\r\n\t\t\t\t\"status\": \"error\",\r\n\t\t\t\t\"error\": str(e),\r\n\t\t\t\t})\r\n\telse:\r\n\t\treturn jsonify({\r\n\t\t\t\"status\": \"error\", \"error\": \"Unrecognized verb.\",\r\n\t\t\t})<\/pre>\n<p>I\u2019ve used a non-standard HTTP method,\u00a0<code class=\"highlighter-rouge\">FETCH<\/code>\u00a0for the\u00a0<code class=\"highlighter-rouge\">SELECT<\/code>\u00a0action. That\u2019s because if you use the\u00a0<code class=\"highlighter-rouge\">GET<\/code>\u00a0method, you aren\u2019t allowed to actually post data (as in actual posting, don\u2019t confuse with\u00a0<code class=\"highlighter-rouge\">POST<\/code>\u00a0method) as per the HTTP specification. The other methods, viz\u00a0<code class=\"highlighter-rouge\">POST<\/code>,\u00a0<code class=\"highlighter-rouge\">PUT<\/code>and\u00a0<code class=\"highlighter-rouge\">DELETE<\/code>\u00a0are self-apparent and they stand for\u00a0<code class=\"highlighter-rouge\">INSERT<\/code>,\u00a0<code class=\"highlighter-rouge\">UPDATE<\/code>\u00a0and\u00a0<code class=\"highlighter-rouge\">DELETE<\/code>\u00a0actions respectively.<\/p>\n<p>As you can see, the app makes good use of the sql expression language of sqlalchemy to dynamically query any kind of data, not only using the usual\u00a0<code class=\"highlighter-rouge\">where<\/code>\u00a0clause, but also using ordering and pagination (limit\/offset) parameters:<\/p>\n<pre class=\"brush:py\">if 'orderby' in data:\r\n\tfor cname in data['orderby'].split(','):\r\n\t\treverse = False\r\n\t\tif cname.endswith(' desc'):\r\n\t\t\treverse = True\r\n\t\t\tcname = cname[:-5]\r\n\t\telif cname.endswith(' asc'):\r\n\t\t\tcname = cname[:-4]\r\n\t\tprint(\"cname: \", cname)\r\n\t\tcolumn = getattr(TableClass, cname)\r\n\t\tif reverse: column = desc(column)\r\n\t\tquery = query.order_by(column)\r\nif 'limit' in data:\r\n\tquery = query.limit(data['limit'])\r\n\tquery = query.offset(data['offset'])<\/pre>\n<p>The front-end sends whatever it needs to the back-end using JSON format and the result is also in JSON. For example, the following JSON when posted to\u00a0<code class=\"highlighter-rouge\">\/user<\/code>\u00a0endpoint using\u00a0<code class=\"highlighter-rouge\">FETCH<\/code>method, returns the record from user table where\u00a0<code class=\"highlighter-rouge\">name<\/code>\u00a0field matches\u00a0<code class=\"highlighter-rouge\">admin<\/code>\u00a0and orders the results by email in descending order.<\/p>\n<pre class=\"brush:py\">{\"where\": {\"name\":\"admin\"}, \"orderby\": \"email desc\"}<\/pre>\n<p>Adding the\u00a0<code class=\"highlighter-rouge\">limit<\/code>\u00a0and\u00a0<code class=\"highlighter-rouge\">offset<\/code>\u00a0clauses to the same can help the front-end with pagination.<\/p>\n<pre class=\"brush:py\">{\"where\": {\"name\":\"admin\"}, \"orderby\": \"email desc\", \"limit\":2, \"offset\": 2}<\/pre>\n<p>Its also pretty trivial to implement user authentication with this design. I haven\u2019t done it in this example for simplicity, but you can find it in the\u00a0<a href=\"https:\/\/github.com\/prahladyeri\/tiddly\">github code<\/a>.<\/p>\n<p>All code in this tutorial and on github is\u00a0<code class=\"highlighter-rouge\">MIT<\/code>\u00a0licensed and free to use. So, enjoy coding, build your own RESTful CRUD app, and let me know how it goes via comments below!<\/p>\n<div class=\"attribution\">\n<table>\n<tbody>\n<tr>\n<td><span class=\"reference\">Reference: <\/span><\/td>\n<td><a href=\"https:\/\/www.prahladyeri.com\/blog\/2017\/06\/flask-recipe-restful-crud-using-sqlalchemy.html\">Flask Recipe \u2013 RESTful CRUD using sqlalchemy<\/a> from our <a href=\"http:\/\/www.javacodegeeks.com\/jcg\">WCG partner<\/a> Prahlad Yeri at the <a href=\"http:\/\/www.prahladyeri.com\/\">Prahlad Yeri<\/a> blog.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>RESTful apps are a thing these days. When your application\u2019s userbase gets quite large and the client could vary from a laptop to an android device to an iOS device, it pays to keep the backend code separate and use the server only for making RESTful calls using HTTP methods that pertain to basic OLTP &hellip;<\/p>\n","protected":false},"author":20,"featured_media":1651,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[53],"tags":[],"class_list":["post-18712","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Flask Recipe \u2013 RESTful CRUD using sqlalchemy - Web Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"RESTful apps are a thing these days. When your application\u2019s userbase gets quite large and the client could vary from a laptop to an android device to an\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.webcodegeeks.com\/python\/flask-recipe-restful-crud-using-sqlalchemy\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Flask Recipe \u2013 RESTful CRUD using sqlalchemy - Web Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"RESTful apps are a thing these days. When your application\u2019s userbase gets quite large and the client could vary from a laptop to an android device to an\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webcodegeeks.com\/python\/flask-recipe-restful-crud-using-sqlalchemy\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webcodegeeks\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/prahlad1981\" \/>\n<meta property=\"article:published_time\" content=\"2017-09-20T09:15:06+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Prahlad Yeri\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/prahladyeri\" \/>\n<meta name=\"twitter:site\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prahlad Yeri\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/flask-recipe-restful-crud-using-sqlalchemy\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/flask-recipe-restful-crud-using-sqlalchemy\/\"},\"author\":{\"name\":\"Prahlad Yeri\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/adbf41ec03855cdb1730dd42f2725bfd\"},\"headline\":\"Flask Recipe \u2013 RESTful CRUD using sqlalchemy\",\"datePublished\":\"2017-09-20T09:15:06+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/flask-recipe-restful-crud-using-sqlalchemy\/\"},\"wordCount\":689,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/flask-recipe-restful-crud-using-sqlalchemy\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg\",\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.webcodegeeks.com\/python\/flask-recipe-restful-crud-using-sqlalchemy\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/flask-recipe-restful-crud-using-sqlalchemy\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/python\/flask-recipe-restful-crud-using-sqlalchemy\/\",\"name\":\"Flask Recipe \u2013 RESTful CRUD using sqlalchemy - Web Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/flask-recipe-restful-crud-using-sqlalchemy\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/flask-recipe-restful-crud-using-sqlalchemy\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg\",\"datePublished\":\"2017-09-20T09:15:06+00:00\",\"description\":\"RESTful apps are a thing these days. When your application\u2019s userbase gets quite large and the client could vary from a laptop to an android device to an\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/flask-recipe-restful-crud-using-sqlalchemy\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webcodegeeks.com\/python\/flask-recipe-restful-crud-using-sqlalchemy\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/flask-recipe-restful-crud-using-sqlalchemy\/#primaryimage\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/flask-recipe-restful-crud-using-sqlalchemy\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.webcodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/python\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Flask Recipe \u2013 RESTful CRUD using sqlalchemy\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"name\":\"Web Code Geeks\",\"description\":\"Web Developers Resource Center\",\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.webcodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webcodegeeks\",\"https:\/\/x.com\/webcodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/adbf41ec03855cdb1730dd42f2725bfd\",\"name\":\"Prahlad Yeri\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/70a8e7bba939c7539943aa1191374d2504d95a2a95acb04a1e44adc3b4c72fe3?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/70a8e7bba939c7539943aa1191374d2504d95a2a95acb04a1e44adc3b4c72fe3?s=96&d=mm&r=g\",\"caption\":\"Prahlad Yeri\"},\"description\":\"Prahlad is a freelance software developer working on web and mobile application development. He also likes to blog about programming and contribute to opensource.\",\"sameAs\":[\"http:\/\/www.prahladyeri.com\/\",\"https:\/\/www.facebook.com\/prahlad1981\",\"http:\/\/in.linkedin.com\/pub\/prahlad-yeri\/16\/a53\/243\/\",\"https:\/\/x.com\/https:\/\/twitter.com\/prahladyeri\"],\"url\":\"https:\/\/www.webcodegeeks.com\/author\/prahlad-yeri\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Flask Recipe \u2013 RESTful CRUD using sqlalchemy - Web Code Geeks - 2026","description":"RESTful apps are a thing these days. When your application\u2019s userbase gets quite large and the client could vary from a laptop to an android device to an","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.webcodegeeks.com\/python\/flask-recipe-restful-crud-using-sqlalchemy\/","og_locale":"en_US","og_type":"article","og_title":"Flask Recipe \u2013 RESTful CRUD using sqlalchemy - Web Code Geeks - 2026","og_description":"RESTful apps are a thing these days. When your application\u2019s userbase gets quite large and the client could vary from a laptop to an android device to an","og_url":"https:\/\/www.webcodegeeks.com\/python\/flask-recipe-restful-crud-using-sqlalchemy\/","og_site_name":"Web Code Geeks","article_publisher":"https:\/\/www.facebook.com\/webcodegeeks","article_author":"https:\/\/www.facebook.com\/prahlad1981","article_published_time":"2017-09-20T09:15:06+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg","type":"image\/jpeg"}],"author":"Prahlad Yeri","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/prahladyeri","twitter_site":"@webcodegeeks","twitter_misc":{"Written by":"Prahlad Yeri","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webcodegeeks.com\/python\/flask-recipe-restful-crud-using-sqlalchemy\/#article","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/python\/flask-recipe-restful-crud-using-sqlalchemy\/"},"author":{"name":"Prahlad Yeri","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/adbf41ec03855cdb1730dd42f2725bfd"},"headline":"Flask Recipe \u2013 RESTful CRUD using sqlalchemy","datePublished":"2017-09-20T09:15:06+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/python\/flask-recipe-restful-crud-using-sqlalchemy\/"},"wordCount":689,"commentCount":0,"publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/python\/flask-recipe-restful-crud-using-sqlalchemy\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg","articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webcodegeeks.com\/python\/flask-recipe-restful-crud-using-sqlalchemy\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webcodegeeks.com\/python\/flask-recipe-restful-crud-using-sqlalchemy\/","url":"https:\/\/www.webcodegeeks.com\/python\/flask-recipe-restful-crud-using-sqlalchemy\/","name":"Flask Recipe \u2013 RESTful CRUD using sqlalchemy - Web Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/python\/flask-recipe-restful-crud-using-sqlalchemy\/#primaryimage"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/python\/flask-recipe-restful-crud-using-sqlalchemy\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg","datePublished":"2017-09-20T09:15:06+00:00","description":"RESTful apps are a thing these days. When your application\u2019s userbase gets quite large and the client could vary from a laptop to an android device to an","breadcrumb":{"@id":"https:\/\/www.webcodegeeks.com\/python\/flask-recipe-restful-crud-using-sqlalchemy\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webcodegeeks.com\/python\/flask-recipe-restful-crud-using-sqlalchemy\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/python\/flask-recipe-restful-crud-using-sqlalchemy\/#primaryimage","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.webcodegeeks.com\/python\/flask-recipe-restful-crud-using-sqlalchemy\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webcodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Python","item":"https:\/\/www.webcodegeeks.com\/category\/python\/"},{"@type":"ListItem","position":3,"name":"Flask Recipe \u2013 RESTful CRUD using sqlalchemy"}]},{"@type":"WebSite","@id":"https:\/\/www.webcodegeeks.com\/#website","url":"https:\/\/www.webcodegeeks.com\/","name":"Web Code Geeks","description":"Web Developers Resource Center","publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webcodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.webcodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.webcodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webcodegeeks","https:\/\/x.com\/webcodegeeks"]},{"@type":"Person","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/adbf41ec03855cdb1730dd42f2725bfd","name":"Prahlad Yeri","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/70a8e7bba939c7539943aa1191374d2504d95a2a95acb04a1e44adc3b4c72fe3?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/70a8e7bba939c7539943aa1191374d2504d95a2a95acb04a1e44adc3b4c72fe3?s=96&d=mm&r=g","caption":"Prahlad Yeri"},"description":"Prahlad is a freelance software developer working on web and mobile application development. He also likes to blog about programming and contribute to opensource.","sameAs":["http:\/\/www.prahladyeri.com\/","https:\/\/www.facebook.com\/prahlad1981","http:\/\/in.linkedin.com\/pub\/prahlad-yeri\/16\/a53\/243\/","https:\/\/x.com\/https:\/\/twitter.com\/prahladyeri"],"url":"https:\/\/www.webcodegeeks.com\/author\/prahlad-yeri\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/18712","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/users\/20"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/comments?post=18712"}],"version-history":[{"count":0,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/18712\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media\/1651"}],"wp:attachment":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media?parent=18712"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/categories?post=18712"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/tags?post=18712"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}