{"id":101688,"date":"2021-04-19T11:00:00","date_gmt":"2021-04-19T08:00:00","guid":{"rendered":"https:\/\/examples.javacodegeeks.com\/?p=101688"},"modified":"2021-04-12T15:09:37","modified_gmt":"2021-04-12T12:09:37","slug":"create-a-web-app-with-python-flask-and-postgresql","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/create-a-web-app-with-python-flask-and-postgresql\/","title":{"rendered":"Create a Web App with Python Flask and PostgreSQL"},"content":{"rendered":"<p>Hello in this tutorial, I\u2019ll should you how to create RESTful web services in python by using the Flask framework and PostgreSQL.<\/p>\n<p><strong>Flask<\/strong> is a micro-framework as it does not require any particular tools or libraries. It has no database layer, form validations, or any other third-party library that provides common functions.<\/p>\n<h2>1. Introduction<\/h2>\n<p><strong>REST<\/strong> stands for Representational state transfer and it fits in the HTTP protocol designed worldwide for the users. RESTful is \u2013<\/p>\n<ul>\n<li>Uniform interface for client-server communication<\/li>\n<li>Stateless in nature meaning each request coming from the client should contain all the information required by the server in order to process the incoming request<\/li>\n<li>Cacheable in nature<\/li>\n<li>Support the HATEOAS principle in order to drive the links from the server-side rather than client hardcoding it<\/li>\n<li>RESTful web services provide different HTTP request methods. Out of all these, the most common ones are \u2013\n<ul>\n<li>GET \u2013 Obtaining information about the entity<\/li>\n<li>POST \u2013 Creating a new entity<\/li>\n<li>PUT \u2013 Updating the existing entity (if found) or creating a new one<\/li>\n<li>DELETE \u2013 Deleting an entity<\/li>\n<\/ul>\n<\/li>\n<li>Does not restrict user for a specific format of the request. However in general the request is provided in the JSON format<\/li>\n<\/ul>\n<p>To start with this tutorial we will need to install Python and set up some of the python libraries. Let us go ahead and install them one by one.<\/p>\n<h3>1.1 Setting up Python<\/h3>\n<p>If someone needs to go through the Python installation on Windows, please watch <a href=\"https:\/\/www.youtube.com\/watch?v=i-MuSAwgwCU\" target=\"_blank\" rel=\"noopener\">this<\/a> link. You can download the Python from <a href=\"https:\/\/www.python.org\/downloads\/\" target=\"_blank\" rel=\"noopener\">this<\/a> link.<\/p>\n<h3>1.2 Setting up Flask-SQLAchdemy<\/h3>\n<p>Once the python is successfully installed on your system you can install the <strong>Flask-SQLAchdemy<\/strong> using a simple <code>pip<\/code> command. You can fire the below command from the command prompt and it will successfully download the module from <a href=\"https:\/\/pypi.org\/project\/Flask-SQLAchdemy\/\" target=\"_blank\" rel=\"noopener\">pypi.org<\/a> and install it.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Installation command<\/em><\/span><\/p>\n<pre class=\"brush:python;\">pip install -U Flask-SQLAchdemy\n<\/pre>\n<p>Once you trigger this command the installation will be started as shown in Fig. 1.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/04\/pip-install-flask-sqlalchemy.jpg\"><img decoding=\"async\" width=\"781\" height=\"413\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/04\/pip-install-flask-sqlalchemy.jpg\" alt=\"Flask PostgreSQL - download\" class=\"wp-image-101689\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/04\/pip-install-flask-sqlalchemy.jpg 781w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/04\/pip-install-flask-sqlalchemy-300x160.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/04\/pip-install-flask-sqlalchemy-768x406.jpg 768w\" sizes=\"(max-width: 781px) 100vw, 781px\" \/><\/a><figcaption>Fig. 1: Downloading and installing Flask-SQLAchdemy<\/figcaption><\/figure>\n<\/div>\n<h3>1.3 Setting up Psycopg2<\/h3>\n<p>Once the python is successfully installed on your system you can install the <strong>psycopg2<\/strong> using a simple <code>pip<\/code> command. You can fire the below command from the command prompt and it will successfully download the module from <a href=\"https:\/\/pypi.org\/project\/psycopg2\/\" target=\"_blank\" rel=\"noopener\">pypi.org<\/a> and install it.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Installation command<\/em><\/span><\/p>\n<pre class=\"brush:python;\">pip install psycopg2\n<\/pre>\n<h3>1.4 Setting up Postgres database<\/h3>\n<p>To start with the tutorial, I am hoping that you have the Postgres up and running in your local host environment. For easy setup, I have the database up and running on the docker environment. You can execute the below command to get the container running on docker in minutes.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Docker container run command<\/em><\/span><\/p>\n<pre class=\"brush:plain; wrap-lines:false;\">docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=password --name postgres postgres\n<\/pre>\n<p>If everything goes well the container would be started successfully as shown in Fig. 2. You can use the <code>docker ps -a<\/code> command to confirm that the container is started successfully. For further information on docker basics, you can navigate to this <a href=\"https:\/\/examples.javacodegeeks.com\/docker-basic-commands\/\" target=\"_blank\" rel=\"noopener\">tutorial<\/a>.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/04\/docker-postgres-container-img1.jpg\"><img decoding=\"async\" width=\"818\" height=\"112\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/04\/docker-postgres-container-img1.jpg\" alt=\"Flask PostgreSQL - on docker\" class=\"wp-image-101690\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/04\/docker-postgres-container-img1.jpg 818w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/04\/docker-postgres-container-img1-300x41.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/04\/docker-postgres-container-img1-768x105.jpg 768w\" sizes=\"(max-width: 818px) 100vw, 818px\" \/><\/a><figcaption>Fig. 2: Postgres container on Docker<\/figcaption><\/figure>\n<\/div>\n<p>Once the docker container is successfully started we need to create a database. Connect with the server on port 5433 using the <a href=\"https:\/\/www.pgadmin.org\/download\/\" target=\"_blank\" rel=\"noopener\">pgAdmin<\/a> tool and create a new database named &#8211; <code>library<\/code>. To create a database you will use the following SQL command.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p><span style=\"text-decoration: underline;\"><em>Create database sql command<\/em><\/span><\/p>\n<pre class=\"brush:plain; wrap-lines:false;\">CREATE DATABASE library\n<\/pre>\n<h2>2. Create a Web App with Python Flask and PostgreSQL<\/h2>\n<p>Before going any deeper in the practice I am assuming that you are aware of the Python and SQL basics. Let us dive in with the programming stuff now.<\/p>\n<h3>2.1 Creating a Configuration<\/h3>\n<p>Add the following code to the python script containing the configuration wherein we will specify the database identifier containing the user, password, host, port, and database name information (In the ideal case this information will be fetched from some configuration file and <em>not<\/em> directly hard coded here). This information will be used by the <code>flask-sqlachemy<\/code> module to work with the database from the python application.<\/p>\n<ul>\n<li><strong>user<\/strong> \u2013 Identity user to work with the postgresql database. Default postgresql user is <code>postgres<\/code><\/li>\n<li><strong>password<\/strong> \u2013 Credential of the identity user<\/li>\n<li><strong>host<\/strong> \u2013 Address of the database server. If running on localhost then you can either use localhost or 127.0.0.1<\/li>\n<li><strong>port<\/strong> &#8211; The port number. Default postgresql port is <code>5432<\/code><\/li>\n<li><strong>database<\/strong> \u2013 Database to which you want to connect. It can be left blank<\/li>\n<\/ul>\n<p>The python script contains the <code>create_app()<\/code> method that returns the Flask app instance. You are free to change these details as per your configuration setup.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>config.py<\/em><\/span><\/p>\n<pre class=\"brush:plain;\">from flask import Flask\n\n\ndef create_app():\n    app = Flask(__name__)\n    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False\n    # sql config params\n    app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql:\/\/postgres:password@localhost:5433\/library'\n    return app\n<\/pre>\n<h3>2.2 Creating a Database Model<\/h3>\n<p>To build a simple web application and manipulate the data we need to map the database columns with the request model. With <code>libaray<\/code> database in place we will use the <code>Flask-SQLAlchemy<\/code> extension in python to add the database layer capabilities. The file consists of the <code>Flask-SQLAlchemy<\/code> instance called <code>db<\/code> and will be used for database-related operations like create the table structure in the database and defining the data that we will store.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>model.py<\/em><\/span><\/p>\n<pre class=\"brush:python;\">from flask_sqlalchemy import SQLAlchemy\n\nfrom config import create_app\n\ndb = SQLAlchemy(create_app())\n\n\n# model class to create table structure in db\nclass Book(db.Model):\n    __tablename__ = 'books'\n\n    id = db.Column(db.Integer, primary_key=True)\n    title = db.Column(db.String(100), nullable=False)\n    genre = db.Column(db.String())\n    author = db.Column(db.String(), nullable=False)\n    quantity = db.Column(db.Integer, nullable=False, default=0)\n\n    def __init__(self, title, genre, author, quantity):\n        self.title = title\n        self.genre = genre\n        self.author = author\n        self.quantity = quantity\n\n    def __repr__(self):\n        return f'{self.id}'\n<\/pre>\n<p>To automatically create the model structure we will need to run this file from the python console. Open the command prompt terminal and go to the project location. From the project, location write <code>python<\/code> and click enter. Once you enter the python console trigger the following commands to <em>automatically create the table schema<\/em> inside the <code>library<\/code> table based on the model specified above.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Db migrate commands<\/em><\/span><\/p>\n<pre class=\"brush:plain;\">from model import db\n\ndb.create_all()\n\nexit()\n<\/pre>\n<p>If everything goes well the table will be created and can be verified from the <a href=\"https:\/\/www.pgadmin.org\/download\/\" target=\"_blank\" rel=\"noopener\">pgAdmin<\/a> console as shown in Fig. 3.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/04\/book-table-pgadmin-img1.jpg\"><img decoding=\"async\" width=\"307\" height=\"612\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/04\/book-table-pgadmin-img1.jpg\" alt=\"Flask PostgreSQL - books table\" class=\"wp-image-101691\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/04\/book-table-pgadmin-img1.jpg 307w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/04\/book-table-pgadmin-img1-150x300.jpg 150w\" sizes=\"(max-width: 307px) 100vw, 307px\" \/><\/a><figcaption>Fig. 3: Books Table<\/figcaption><\/figure>\n<\/div>\n<h3>2.3 Creating and Reading Entities<\/h3>\n<p>Now that we have the database and table connected with our flask application so let us implement the CRUD operations. In the below python script we will create the four HTTP operations i.e. POST, PUT, DELETE, and GET. The file consists of the \u2013<\/p>\n<ul>\n<li>Flask app instance called <code>app<\/code><\/li>\n<li><code>Flask-SQLAlchemy<\/code> instance called <code>db<\/code> and will be required for CRUD operations<\/li>\n<\/ul>\n<p>Let us write some API resource implementation i.e.<\/p>\n<ul>\n<li><code>save_book()<\/code>: HTTP POST operation to save the new book in the table<\/li>\n<li><code>get_books(\u2026)<\/code>: HTTP GET operation to get all the books from the table<\/li>\n<li><code>handle_book(book_id)<\/code>: HTTP GET\/PUT\/DELETE\/ operation on a book in the table<\/li>\n<\/ul>\n<p><span style=\"text-decoration: underline;\"><em>app.py<\/em><\/span><\/p>\n<pre class=\"brush:python;\">from flask import request, jsonify\nfrom flask_sqlalchemy import SQLAlchemy\n\nfrom config import create_app\nfrom model import Book\n\napp = create_app()\ndb = SQLAlchemy(app)\n\n\n# creating the rest endpoints\n\n# index\n# url = http:\/\/127.0.0.1:5000\/\n@app.route('\/', methods=['GET'])\ndef index():\n    return {'message': 'Hello world!'}\n\n\n# save new book\n# url = http:\/\/127.0.0.1:5000\/book\n@app.route('\/book', methods=['POST'])\ndef save_book():\n    if request.is_json:\n        print('Saving new book')\n        data = request.get_json()\n        new_book = Book(title=data['title'], genre=data['genre'], author=data['author'], quantity=data['quantity'])\n        db.session.add(new_book)  # adding new data\n        db.session.commit()  # persisting the data\n        db.session.refresh(new_book)  # refresh the inserted object to get the primary key\n        return {'message': f'Book {new_book.id} saved successfully'}  # returning response\n    else:\n        return {'message': 'Payload is incorrect'}\n\n\n# get all books\n# url = http:\/\/127.0.0.1:5000\/books\n@app.route('\/books', methods=['GET'])\ndef get_books():\n    print('Getting all books')\n    books = Book.query.all()\n    if not books:\n        return {'items': [], 'count': 0, 'message': 'success'}  # returning empty response\n    else:\n        result = [\n            {\n                'id': b.id,\n                'title': b.title,\n                'genre': b.genre,\n                'author': b.author,\n                'quantity': b.quantity\n            } for b in books]\n        return {'items': result, 'count': len(books), 'message': 'success'}  # returning response\n\n\n# get\/update\/book by id\n# url = http:\/\/127.0.0.1:5000\/book\/\n@app.route('\/book\/', methods=['GET', 'PUT', 'DELETE'])\ndef handle_book(book_id):\n    print('Getting book id = {}'.format(book_id))\n    book = Book.query.get_or_404(book_id)\n    if request.method == 'GET':\n        response = {\n            'id': book.id,\n            'title': book.title,\n            'genre': book.genre,\n            'author': book.author,\n            'quantity': book.quantity\n        }\n        return {'message': 'success', 'book': response}  # returning response\n    elif request.method == 'PUT':\n        if request.is_json:\n            print('Performing update')\n            data = request.get_json()\n            # updating the data\n            db.session.query(Book).filter(Book.id == book_id).update({\n                'title': data['title'],\n                'genre': data['genre'],\n                'author': data['author'],\n                'quantity': data['quantity']\n            })\n            db.session.commit()  # persisting the data\n            return {'message': f'Book {book_id} updated successfully'}  # returning response\n        else:\n            return {'message': 'Payload is incorrect'}\n    elif request.method == 'DELETE':\n        print('Performing delete')\n        db.session.query(Book).filter(Book.id == book_id).delete()  # deleting the data\n        db.session.commit()  # persisting the data\n        return {'message': f'Book {book_id} deleted successfully'}  # persisting the data\n\n\n# exception handler\n@app.errorhandler(405)\ndef method_not_allowed(e):\n    return jsonify({'message': 'Request method not supported'}), 405\n\n\n# driver code\nif __name__ == '__main__':\n    app.run(debug=False)\n<\/pre>\n<p>Run this python script and let us try adding a new book using a tool like <a href=\"https:\/\/www.getpostman.com\/\" target=\"_blank\" rel=\"noopener\">Postman<\/a>.<\/p>\n<h2>4. Application Endpoints<\/h2>\n<p>Once the <code>app.py<\/code> is successfully started it would expose the following application endpoints which you can use for performing the different CRUD operations.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Application Endpoints<\/em><\/span><\/p>\n<pre class=\"brush:plain;\"># save new book\n# url = http:\/\/127.0.0.1:5000\/book\n# sample request body\n# {\n#    \"title\": \"{{$randomJobTitle}}\",\n#   \"genre\": \"{{$randomBsBuzz}}\",\n#    \"author\": \"{{$randomFullName}}\",\n#   \"quantity\": \"{{$randomInt}}\"\n# }\n\n\n# get all books\n# url = http:\/\/127.0.0.1:5000\/books\n\n\n# get\/update\/book by id\n# url = http:\/\/127.0.0.1:5000\/book\/\n<\/pre>\n<p>You can also download the postman collection from the <a href=\"#projectDownload\">Downloads<\/a> section. That is all for this tutorial and I hope the article served you with whatever you were looking for. Happy Learning and do not forget to share!<\/p>\n<h2>5. Summary<\/h2>\n<p>In this tutorial, we learned:<\/p>\n<ul>\n<li>Introduction to Flask micro-framework in python programming<\/li>\n<li>Sample program create a web application in python via flask and PostgreSQL<\/li>\n<\/ul>\n<p>You can download the source code of this tutorial from the <a href=\"#projectDownload\">Downloads<\/a> section.<\/p>\n<h2>6. Related articles<\/h2>\n<ul>\n<li>\n<p><a href=\"https:\/\/examples.javacodegeeks.com\/introduction-to-the-flask-python-web-app-framework\/\">Introduction to the Flask Python Web App Framework<\/a><\/p>\n<\/li>\n<\/ul>\n<h2>7<a name=\"projectDownload\"><\/a>. Download the Project<\/h2>\n<p>This was a python programming tutorial to understand the flask micro-framework in python programming with the help of a web application and PostgreSQL.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>You can download the full source code of this example here: <a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/04\/Create-a-Web-App-with-Python-Flask-and-PostgreSQL.zip\" target=\"_blank\" rel=\"noopener\"><strong>Create a Web App with Python Flask and PostgreSQL<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Hello in this tutorial, I\u2019ll should you how to create RESTful web services in python by using the Flask framework and PostgreSQL. Flask is a micro-framework as it does not require any particular tools or libraries. It has no database layer, form validations, or any other third-party library that provides common functions. 1. Introduction REST &hellip;<\/p>\n","protected":false},"author":119,"featured_media":99891,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46689],"tags":[719,1716],"class_list":["post-101688","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-postgresql","tag-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Create a Web App with Python Flask and PostgreSQL - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Hello in this tutorial, I\u2019ll should you how to create RESTful web services in python by using the Flask framework and PostgreSQL. Flask is a\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/create-a-web-app-with-python-flask-and-postgresql\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Create a Web App with Python Flask and PostgreSQL - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Hello in this tutorial, I\u2019ll should you how to create RESTful web services in python by using the Flask framework and PostgreSQL. Flask is a\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/create-a-web-app-with-python-flask-and-postgresql\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2021-04-19T08:00:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/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=\"Yatin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Yatin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/create-a-web-app-with-python-flask-and-postgresql\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/create-a-web-app-with-python-flask-and-postgresql\/\"},\"author\":{\"name\":\"Yatin\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/9874407a37b028e8be3276e2b5960d13\"},\"headline\":\"Create a Web App with Python Flask and PostgreSQL\",\"datePublished\":\"2021-04-19T08:00:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/create-a-web-app-with-python-flask-and-postgresql\/\"},\"wordCount\":1146,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/create-a-web-app-with-python-flask-and-postgresql\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/python-logo.jpg\",\"keywords\":[\"PostgreSQL\",\"python\"],\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/create-a-web-app-with-python-flask-and-postgresql\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/create-a-web-app-with-python-flask-and-postgresql\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/create-a-web-app-with-python-flask-and-postgresql\/\",\"name\":\"Create a Web App with Python Flask and PostgreSQL - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/create-a-web-app-with-python-flask-and-postgresql\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/create-a-web-app-with-python-flask-and-postgresql\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/python-logo.jpg\",\"datePublished\":\"2021-04-19T08:00:00+00:00\",\"description\":\"Hello in this tutorial, I\u2019ll should you how to create RESTful web services in python by using the Flask framework and PostgreSQL. Flask is a\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/create-a-web-app-with-python-flask-and-postgresql\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/create-a-web-app-with-python-flask-and-postgresql\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/create-a-web-app-with-python-flask-and-postgresql\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/python-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/python-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"set python\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/create-a-web-app-with-python-flask-and-postgresql\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Web Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/web-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Python\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/web-development\/python\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Create a Web App with Python Flask and PostgreSQL\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/9874407a37b028e8be3276e2b5960d13\",\"name\":\"Yatin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/09\/cropped-Yatin-Batra_avatar_1515758148-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/09\/cropped-Yatin-Batra_avatar_1515758148-96x96.jpg\",\"caption\":\"Yatin\"},\"description\":\"An experience full-stack engineer well versed with Core Java, Spring\/Springboot, MVC, Security, AOP, Frontend (Angular &amp; React), and cloud technologies (such as AWS, GCP, Jenkins, Docker, K8).\",\"sameAs\":[\"https:\/\/www.javacodegeeks.com\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/yatin-batra\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Create a Web App with Python Flask and PostgreSQL - Java Code Geeks","description":"Hello in this tutorial, I\u2019ll should you how to create RESTful web services in python by using the Flask framework and PostgreSQL. Flask is a","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:\/\/examples.javacodegeeks.com\/create-a-web-app-with-python-flask-and-postgresql\/","og_locale":"en_US","og_type":"article","og_title":"Create a Web App with Python Flask and PostgreSQL - Java Code Geeks","og_description":"Hello in this tutorial, I\u2019ll should you how to create RESTful web services in python by using the Flask framework and PostgreSQL. Flask is a","og_url":"https:\/\/examples.javacodegeeks.com\/create-a-web-app-with-python-flask-and-postgresql\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2021-04-19T08:00:00+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/python-logo.jpg","type":"image\/jpeg"}],"author":"Yatin","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Yatin","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/create-a-web-app-with-python-flask-and-postgresql\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/create-a-web-app-with-python-flask-and-postgresql\/"},"author":{"name":"Yatin","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/9874407a37b028e8be3276e2b5960d13"},"headline":"Create a Web App with Python Flask and PostgreSQL","datePublished":"2021-04-19T08:00:00+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/create-a-web-app-with-python-flask-and-postgresql\/"},"wordCount":1146,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/create-a-web-app-with-python-flask-and-postgresql\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/python-logo.jpg","keywords":["PostgreSQL","python"],"articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/create-a-web-app-with-python-flask-and-postgresql\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/create-a-web-app-with-python-flask-and-postgresql\/","url":"https:\/\/examples.javacodegeeks.com\/create-a-web-app-with-python-flask-and-postgresql\/","name":"Create a Web App with Python Flask and PostgreSQL - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/create-a-web-app-with-python-flask-and-postgresql\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/create-a-web-app-with-python-flask-and-postgresql\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/python-logo.jpg","datePublished":"2021-04-19T08:00:00+00:00","description":"Hello in this tutorial, I\u2019ll should you how to create RESTful web services in python by using the Flask framework and PostgreSQL. Flask is a","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/create-a-web-app-with-python-flask-and-postgresql\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/create-a-web-app-with-python-flask-and-postgresql\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/create-a-web-app-with-python-flask-and-postgresql\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/python-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/python-logo.jpg","width":150,"height":150,"caption":"set python"},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/create-a-web-app-with-python-flask-and-postgresql\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Web Development","item":"https:\/\/examples.javacodegeeks.com\/category\/web-development\/"},{"@type":"ListItem","position":3,"name":"Python","item":"https:\/\/examples.javacodegeeks.com\/category\/web-development\/python\/"},{"@type":"ListItem","position":4,"name":"Create a Web App with Python Flask and PostgreSQL"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/9874407a37b028e8be3276e2b5960d13","name":"Yatin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/09\/cropped-Yatin-Batra_avatar_1515758148-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/09\/cropped-Yatin-Batra_avatar_1515758148-96x96.jpg","caption":"Yatin"},"description":"An experience full-stack engineer well versed with Core Java, Spring\/Springboot, MVC, Security, AOP, Frontend (Angular &amp; React), and cloud technologies (such as AWS, GCP, Jenkins, Docker, K8).","sameAs":["https:\/\/www.javacodegeeks.com"],"url":"https:\/\/examples.javacodegeeks.com\/author\/yatin-batra\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/101688","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/119"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=101688"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/101688\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/99891"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=101688"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=101688"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=101688"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}