uv, un gestionnaire de paquets/projet.https://docs.astral.sh/uv/#installation
Attention à toujours se positionner au même niveau que le
pyproject.toml avant de lancer une commande :
$ uv sync # pour installer les dépendances
$ uv run archilog # lancement de l'applicationPlus d’info sur https://docs.astral.sh/uv/.
Click is a Python package for creating beautiful command line interfaces in a composable way with as little code as necessary.
import click
@click.command()
@click.option("--count", default=1)
@click.option("--name", prompt="Your name")
def hello(count, name):
print(name, count)$ uv run archilog hello --count=3
Your name: John
John 3SQLite is a C library that provides a lightweight disk-based database that doesn’t require a separate server process.
import sqlite3
db = sqlite3.connect("tutorial.db")
db.execute("CREATE TABLE movie(title, year, score)")
result = db.execute("SELECT title FROM movie").fetchone()sqlite ;click.SQLAlchemy est un toolkit open source SQL et un mapping objet-relationnel (ORM) écrit en Python et publié sous licence MIT.
engine = create_engine("sqlite:///data.db", echo=True)
metadata = MetaData()
users_table = Table(
"users",
metadata,
Column("id", Uuid, primary_key=True, default=uuid.uuid4),
Column("login", String, nullable=False)
)stmt = users_table.insert().values(login="john.doe")
with engine.begin() as conn:
result = conn.execute(stmt)$ uv add sqlalchemyFlask is a lightweight WSGI web application framework. It is designed to make getting started quick and easy, with the ability to scale up to complex applications.
# inside archilog/views.py
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello_world():
return "<p>Hello, World!</p>"$ uv run flask --app archilog.views --debug run
* Serving Flask app 'archilog.views'
* Debug mode: on
* Running on http://127.0.0.1:5000
Press CTRL+C to quitfrom flask import render_template
@app.route("/hello/")
@app.route("/hello/<name>")
def hello(name=None):
return render_template("hello.html", name=name)<!doctype html>
<title>Hello from Flask</title>
{% if name %}
<h1>Hello {{ name }}!</h1>
{% else %}
<h1>Hello, World!</h1>
{% endif %}.
├── pyproject.toml
├── README.md
└── src
└── archilog
├── __init__.py
├── data.py
├── domain.py
├── templates
│ └── home.html
└── views.py$ uv add flaskfrom flask import Blueprint, render_template
web_ui = Blueprint("web_ui", __name__)
@web_ui.route("/")
def show():
return render_template("index.html")def create_app():
app = Flask(__name__)
from archilog.views import api, web_ui
app.register_blueprint(web_ui, url_prefix="/")
app.register_blueprint(api, url_prefix="/api")
return appRien ne change, Flask cherche une fonction create_app
:
$ uv run flask --app archilog.views --debug run# engine = create_engine("sqlite:///data.db", echo=True)
from archilog import config
engine = create_engine(config.DATABASE_URL, echo=config.DEBUG)from dataclasses import dataclass
@dataclass
class Config:
DATABASE_URL: str
DEBUG: bool
config = Config(
DATABASE_URL="sqlite:///data.db",
DEBUG=True
)import os
config = Config(
DATABASE_URL=os.getenv(
"ARCHILOG_DATABASE_URL", "sqlite:///data.db"
),
DEBUG=os.getenv("ARCHILOG_DEBUG", "False") == "True"
)# inside dev.env
ARCHILOG_DATABASE_URL=sqlite:///data.db
ARCHILOG_DEBUG=TruePuis dans un terminal :
$ env $(cat dev.env | xargs) uv run ...