{"id":19099821,"url":"https://github.com/Azure-Samples/azure-fastapi-postgres-flexible-aca","last_synced_at":"2025-04-18T17:32:04.361Z","repository":{"id":188282036,"uuid":"652790600","full_name":"Azure-Samples/azure-fastapi-postgres-flexible-aca","owner":"Azure-Samples","description":"Web app using Python FastAPI backend, set up for deployment to Azure Container Apps with Azure PostgreSQL Flexible Server.","archived":false,"fork":false,"pushed_at":"2024-07-15T07:42:05.000Z","size":64839,"stargazers_count":7,"open_issues_count":1,"forks_count":3,"subscribers_count":14,"default_branch":"main","last_synced_at":"2024-07-16T07:35:17.592Z","etag":null,"topics":["azure","fastapi","postgresql","python"],"latest_commit_sha":null,"homepage":"","language":"CSS","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":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-06-12T20:01:47.000Z","updated_at":"2024-07-15T07:42:06.000Z","dependencies_parsed_at":"2023-08-14T18:13:36.777Z","dependency_job_id":"275dcc75-0c54-4468-86ba-205fa01668cd","html_url":"https://github.com/Azure-Samples/azure-fastapi-postgres-flexible-aca","commit_stats":null,"previous_names":["azure-samples/azure-fastapi-postgres-aca","azure-samples/azure-fastapi-postgres-flexible-aca"],"tags_count":0,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azure-Samples%2Fazure-fastapi-postgres-flexible-aca","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azure-Samples%2Fazure-fastapi-postgres-flexible-aca/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azure-Samples%2Fazure-fastapi-postgres-flexible-aca/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azure-Samples%2Fazure-fastapi-postgres-flexible-aca/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Azure-Samples","download_url":"https://codeload.github.com/Azure-Samples/azure-fastapi-postgres-flexible-aca/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223783108,"owners_count":17201903,"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":["azure","fastapi","postgresql","python"],"created_at":"2024-11-09T03:52:18.556Z","updated_at":"2024-11-09T03:52:26.597Z","avatar_url":"https://github.com/Azure-Samples.png","language":"CSS","funding_links":[],"categories":["python","azure"],"sub_categories":[],"readme":"---\npage_type: sample\nlanguages:\n- azdeveloper\n- python\n- bicep\n- html\nproducts:\n- azure\n- azure-container-apps\n- azure-database-postgresql\nurlFragment: azure-fastapi-postgres-flexible-aca\nname: Deploy FastAPI Application with PostgreSQL on Azure Container Apps (Python)\ndescription: This project deploys a web application for a space travel agency using FastAPI with Python, and is set up for easy deployment with the Azure Developer CLI.\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 FastAPI Application with PostgreSQL via Azure Container Apps\n\nThis project deploys a web application for a space travel agency using FastAPI. The application can be deployed to Azure with Azure Container Apps using the [Azure Developer CLI](https://learn.microsoft.com/azure/developer/azure-developer-cli/overview).\n\n## Opening the project\n\nThis project has [Dev Container support](https://code.visualstudio.com/docs/devcontainers/containers), so it will be setup automatically if you open it in Github Codespaces or in local VS Code with the [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers).\n\nIf you're *not* using one of those options for opening the project, then you'll need to:\n\n1. Start up a local PostgreSQL server, create a database for the app, and set the following environment variables according to your database configuration.\n\n```shell\nexport POSTGRES_HOST=localhost\nexport POSTGRES_PORT=5432\nexport POSTGRES_DATABASE=\u003cYOUR DATABASE\u003e\nexport POSTGRES_USERNAME=\u003cYOUR USERNAME\u003e\nexport POSTGRES_PASSWORD=\u003cYOUR PASSWORD\u003e\n```\n\n1. Create a [Python virtual environment](https://docs.python.org/3/tutorial/venv.html#creating-virtual-environments) and activate it.\n\n1. Install production requirements:\n\n    ```sh\n    python3 -m pip install -r src/requirements.txt\n    ```\n\n\n1. Install the app as an editable package:\n\n    ```sh\n    python3 -m pip install -e src\n    ```\n\n\n1. Apply database migrations and seed initial data:\n\n    ```sh\n    python3 src/fastapi_app/seed_data.py\n    ```\n\n## Running locally\n\nIf you're running the app inside VS Code or GitHub Codespaces, you can use the \"Run and Debug\" button to start the app.\n\n```sh\npython3 -m uvicorn fastapi_app:app --reload --port=8000\n```\n\n\n## Running tests\n\n1. Install the development requirements:\n\n    ```sh\n    python3 -m pip install -r requirements-dev.txt\n    python3 -m playwright install chromium --with-deps\n    ```\n\n2. Run the tests:\n\n    ```sh\n    python3 -m pytest\n    ```\n\n## Deployment\n\nThis repo is set up for deployment on Azure via Azure Container Apps.\n\nSteps for deployment:\n\n1. Sign up for a [free Azure account](https://azure.microsoft.com/free/) and create an Azure Subscription.\n2. Install the [Azure Developer CLI](https://learn.microsoft.com/azure/developer/azure-developer-cli/install-azd). (If you open this repository in Codespaces or with the VS Code Dev Containers extension, that part will be done for you.)\n3. Login to Azure:\n\n    ```shell\n    azd auth login\n    ```\n\n4. Provision and deploy all the resources:\n\n    ```shell\n    azd up\n    ```\n\n    It will prompt you to provide an `azd` environment name (like \"myapp\"), select a subscription from your Azure account, and select 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 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 app! 🎉\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### CI/CD pipeline\n\nThis project includes a Github workflow for deploying the resources to Azure\non every push to main. That workflow requires several Azure-related authentication secrets\nto be stored as Github action secrets. To set that up, run:\n\n```shell\nazd pipeline config\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAzure-Samples%2Fazure-fastapi-postgres-flexible-aca","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FAzure-Samples%2Fazure-fastapi-postgres-flexible-aca","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAzure-Samples%2Fazure-fastapi-postgres-flexible-aca/lists"}