This is a template for a Flask application using Poetry for dependency management.
- Python 3.10+
- Poetry
poetry new --name=app --src backend-flask
cd backend-flask
git init
cat pyproject.toml
[tool.poetry]
name = "app"
version = "0.1.0"
description = ""
authors = ["fbrcode <[email protected]>"]
readme = "README.md"
packages = [{include = "app", from = "src"}]
[tool.poetry.dependencies]
python = "^3.10"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
poetry config virtualenvs.in-project true --local
cat poetry.toml
[virtualenvs]
in-project = true
poetry config --list
poetry shell
poetry add [email protected]
echo ".venv" >> .gitignore
tree -a
.
├── .git
│ └── ...
├── .gitignore
├── .venv
│ └── ...
├── README.md
├── poetry.lock
├── poetry.toml
├── pyproject.toml
├── src
│ └── app
│ └── __init__.py
└── tests
└── __init__.py
Run server
poetry shell # enable venv
python -m src.app # run app
# or
poetry run python -m src.app
# or
export FLASK_APP=src.app && export FLASK_DEBUG=1 && flask run # not working
Check endpoints
curl https://localhost:5000/health -vvv
OK
curl https://localhost:5000/users -vvv
[
{
"name": "John Doe"
},
{
"name": "Jane Doe"
}
]
curl https://localhost:5000/users \
-H 'Content-Type: application/json' \
-d '{ "name": "Fabio Test" }' -vvv