Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions copier.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@ project_description:
type: str
help: Your project description

project_type:
type: str
choices:
- cli
- service
default: cli
help: Type of the project

service_framework:
type: str
choices:
- fastapi
- flask
default: fastapi
when: "{{ project_type == 'service' }}"
help: Web framework to use

repository_namespace:
type: str
help: Your repository namespace
Expand Down
7 changes: 7 additions & 0 deletions template/Makefile → template/Makefile.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,10 @@ help:
[[print(f'\033[36m{m[0]:<20}\033[0m {m[1]}') for m in re.findall(r'^([a-zA-Z_-]+):.*?## (.*)$$', open(makefile).read(), re.M)] for makefile in ('$(MAKEFILE_LIST)').strip().split()]"

.DEFAULT_GOAL := help

{% if project_type == 'service' %}
.PHONY: serve
serve: ## Run the service
@echo "🚀 Running service"
@uv run python -m {{package_name}}.main
{% endif %}
14 changes: 13 additions & 1 deletion template/pyproject.toml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,26 @@ license = "AGPL-3.0"
license-files = ["LICENSE"]

dependencies = [
"typer>=0.20"
{%- if project_type == 'cli' %}
"typer>=0.20",
{%- elif project_type == 'service' %}
{%- if service_framework == 'fastapi' %}
"fastapi>=0.110.0",
{%- elif service_framework == 'flask' %}
"flask>=3.0.0",
{%- endif %}
"uvicorn>=0.27.0",
"pydantic-settings>=2.2.0",
{%- endif %}
]

[project.urls]
Repository = "https://github.com/trobz/{{project_name}}"

{%- if project_type == 'cli' %}
[project.scripts]
{{ project_name }} = "{{ package_name }}.main:app"
{%- endif %}

[dependency-groups]
dev = [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ENVIRONMENT=local
DEBUG=false

SERVER_HOST=0.0.0.0
SERVER_PORT=8000
3 changes: 0 additions & 3 deletions template/{{package_name}}/main.py

This file was deleted.

61 changes: 61 additions & 0 deletions template/{{package_name}}/main.py.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{% if project_type == 'cli' -%}
import typer

app = typer.Typer()


@app.command()
def hello(name: str):
print(f"Hello {name}")


if __name__ == "__main__":
app()

{%- elif project_type == 'service' -%}
{%- if service_framework == 'fastapi' -%}
from fastapi import FastAPI
from .settings import settings
import uvicorn

app = FastAPI(title="{{ project_name }}")


@app.get("/")
def read_root():
return {"Hello": "World", "env": settings.environment}

@app.get("/health")
def health_check():
return {"status": "ok"}


if __name__ == "__main__":
uvicorn.run(
"{{ package_name }}.main:app",
host=settings.server_host,
port=settings.server_port,
reload=settings.debug,
)

{%- elif service_framework == 'flask' -%}
from flask import Flask
from .settings import settings

app = Flask(__name__)


@app.route("/")
def hello_world():
return {"Hello": "World", "env": settings.environment}

@app.route("/health")
def health_check():
return {"status": "ok"}


if __name__ == "__main__":
# For development only. Use a production WSGI server for deployment.
app.run(host=settings.server_host, port=settings.server_port, debug=settings.debug)
{%- endif -%}
{%- endif -%}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from pydantic_settings import BaseSettings, SettingsConfigDict


class Settings(BaseSettings):
model_config = SettingsConfigDict(
env_file=".env", env_ignore_empty=True, extra="ignore"
)

environment: str = "local"
debug: bool = False
server_host: str = "0.0.0.0"
server_port: int = 8000


settings = Settings()