{"id":13288982,"url":"https://github.com/Azure-Samples/msdocs-flask-postgresql-sample-app","last_synced_at":"2025-03-10T06:33:53.602Z","repository":{"id":39643648,"uuid":"464957938","full_name":"Azure-Samples/msdocs-flask-postgresql-sample-app","owner":"Azure-Samples","description":null,"archived":false,"fork":false,"pushed_at":"2025-01-20T12:27:21.000Z","size":137,"stargazers_count":48,"open_issues_count":0,"forks_count":577,"subscribers_count":19,"default_branch":"main","last_synced_at":"2025-01-20T13:35:21.231Z","etag":null,"topics":["azd-templates","flask","postgres","python"],"latest_commit_sha":null,"homepage":"","language":"Bicep","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/Azure-Samples.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-03-01T15:51:14.000Z","updated_at":"2025-01-20T11:41:06.000Z","dependencies_parsed_at":"2023-11-28T16:38:38.147Z","dependency_job_id":"e463061d-758b-406c-8c66-326ead9649e1","html_url":"https://github.com/Azure-Samples/msdocs-flask-postgresql-sample-app","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/Azure-Samples%2Fmsdocs-flask-postgresql-sample-app","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azure-Samples%2Fmsdocs-flask-postgresql-sample-app/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azure-Samples%2Fmsdocs-flask-postgresql-sample-app/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azure-Samples%2Fmsdocs-flask-postgresql-sample-app/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Azure-Samples","download_url":"https://codeload.github.com/Azure-Samples/msdocs-flask-postgresql-sample-app/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242805564,"owners_count":20187996,"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":["azd-templates","flask","postgres","python"],"created_at":"2024-07-29T17:00:17.751Z","updated_at":"2025-03-10T06:33:50.221Z","avatar_url":"https://github.com/Azure-Samples.png","language":"Bicep","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\npage_type: sample\nlanguages:\n- azdeveloper\n- python\n- bicep\n- html\nproducts:\n- azure\n- azure-app-service\n- azure-database-postgresql\n- azure-virtual-network\nurlFragment: msdocs-flask-postgresql-sample-app\nname: Deploy a Python (Flask) web app with PostgreSQL in Azure\ndescription: This is a Python web app using the Flask framework and the Azure Database for PostgreSQL relational database service. \n---\n\u003c!-- YAML front-matter schema: https://review.learn.microsoft.com/en-us/help/contribute/samples/process/onboarding?branch=main#supported-metadata-fields-for-readmemd --\u003e\n\n# Deploy a Python (Flask) web app with PostgreSQL in Azure\n\nThis is a Python web app using the Flask framework and the Azure Database for PostgreSQL relational database service. The Flask app is hosted in a fully managed Azure App Service. This app is designed to be be run locally and then deployed to Azure. You can either deploy this project by following the tutorial [*Deploy a Python (Django or Flask) web app with PostgreSQL in Azure*](https://docs.microsoft.com/azure/app-service/tutorial-python-postgresql-app) or by using the [Azure Developer CLI (azd)](https://learn.microsoft.com/azure/developer/azure-developer-cli/overview) according to the instructions below.\n\n## Requirements\n\nThe [requirements.txt](./requirements.txt) has the following packages, all used by a typical data-driven Flask application:\n\n| Package | Description |\n| ------- | ----------- |\n| [Flask](https://pypi.org/project/Flask/) | Web application framework. |\n| [SQLAlchemy](https://pypi.org/project/SQLAlchemy/) | Provides a database abstraction layer to communicate with PostgreSQL. |\n| [Flask-SQLAlchemy](https://pypi.org/project/Flask-SQLAlchemy/) | Adds SQLAlchemy support to Flask application by simplifying using SQLAlchemy. Requires SQLAlchemy. |\n| [Flask-Migrate](https://pypi.org/project/Flask-Migrate/) | SQLAlchemy database migrations for Flask applications using Alembic. Allows functionality parity with Django version of this sample app.|\n| [pyscopg2](https://pypi.org/project/psycopg2/) | PostgreSQL database adapter for Python. |\n| [python-dotenv](https://pypi.org/project/python-dotenv/) | Read key-value pairs from .env file and set them as environment variables. In this sample app, those variables describe how to connect to the database locally. \u003cbr\u003e\u003cbr\u003e Flask's [dotenv support](https://flask.palletsprojects.com/en/2.1.x/cli/#environment-variables-from-dotenv) sets environment variables automatically from an `.env` file. |\n| [flask_wtf](https://pypi.org/project/Flask-WTF/) | Form rendering, validation, and CSRF protection for Flask with WTForms. Uses CSRFProtect extension. |\n\n## Run the sample\n\nThis project has a [dev container configuration](.devcontainer/), which makes it easier to develop apps locally, deploy them to Azure, and monitor them. The easiest way to run this sample application is inside a GitHub codespace. Follow these steps:\n\n1. Fork this repository to your account. For instructions, see [Fork a repo](https://docs.github.com/get-started/quickstart/fork-a-repo).\n\n1. From the repository root of your fork, select **Code** \u003e **Codespaces** \u003e **+**.\n\n1. In the codespace terminal, run the following commands:\n\n    ```shell\n    # Install requirements\n    python3 -m pip install -r requirements.txt\n    # Create .env with environment variables\n    cp .env.sample.devcontainer .env\n    # Run database migrations\n    python3 -m flask db upgrade\n    # Start the development server\n    python3 -m flask run\n    ```\n\n1. When you see the message `Your application running on port 8000 is available.`, click **Open in Browser**.\n\n### Quick deploy\n\nThis project is designed to work well with the [Azure Developer CLI](https://learn.microsoft.com/azure/developer/azure-developer-cli/overview), which makes it easier to develop apps locally, deploy them to Azure, and monitor them. \n\n🎥 Watch a deployment of the code in [this screencast](https://www\n.youtube.com/watch?v=JDlZ4TgPKYc).\n\nSteps for deployment:\n\n1. Sign up for a [free Azure account](https://azure.microsoft.com/free/)\n2. Install the [Azure Dev CLI](https://learn.microsoft.com/azure/developer/azure-developer-cli/install-azd). (If you opened this repository in a Dev Container, it's already installed for you.)\n3. Initialize a new `azd` environment:\n\n    ```shell\n    azd init\n    ```\n\n    It will prompt you to provide a name (like \"flask-app\"), which will later be used in the name of the deployed resources.\n\n4. Provision and deploy all the resources:\n\n    ```shell\n    azd up\n    ```\n\n    It will prompt you to login, pick a subscription, and provide a location (like \"eastus\"). Then it will provision the resources in your account and deploy the latest code. If you get an error with deployment, changing the location (like to \"centralus\") can help, as there may be availability constraints for some of the resources.\n\n5. When `azd` has finished deploying, you'll see an endpoint URI in the command output. Visit that URI, and you should see the front page of the restaurant review app! 🎉 If you see an error, open the Azure Portal from the URL in the command output, navigate to the App Service, select Logstream, and check the logs for any errors.\n\n    ![Screenshot of Flask restaurants website](screenshot_website.png)\n\n6. When you've made any changes to the app code, you can just run:\n\n    ```shell\n    azd deploy\n    ```\n\n## Getting help\n\nIf you're working with this project and running into issues, please post in [Issues](/issues).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAzure-Samples%2Fmsdocs-flask-postgresql-sample-app","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FAzure-Samples%2Fmsdocs-flask-postgresql-sample-app","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAzure-Samples%2Fmsdocs-flask-postgresql-sample-app/lists"}