oe-python-template 0.3.5__py3-none-any.whl → 0.3.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- oe_python_template/api.py +87 -0
- oe_python_template/cli.py +33 -0
- {oe_python_template-0.3.5.dist-info → oe_python_template-0.3.7.dist-info}/METADATA +3 -2
- oe_python_template-0.3.7.dist-info/RECORD +10 -0
- oe_python_template-0.3.5.dist-info/RECORD +0 -9
- {oe_python_template-0.3.5.dist-info → oe_python_template-0.3.7.dist-info}/WHEEL +0 -0
- {oe_python_template-0.3.5.dist-info → oe_python_template-0.3.7.dist-info}/entry_points.txt +0 -0
- {oe_python_template-0.3.5.dist-info → oe_python_template-0.3.7.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"""FastAPI application with REST API endpoints.
|
|
2
|
+
|
|
3
|
+
This module provides a FastAPI application with several endpoints:
|
|
4
|
+
- A hello-world endpoint that returns a greeting message
|
|
5
|
+
- An echo endpoint that echoes back the provided text
|
|
6
|
+
|
|
7
|
+
The endpoints use Pydantic models for request and response validation.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from fastapi import FastAPI
|
|
11
|
+
from pydantic import BaseModel, Field
|
|
12
|
+
|
|
13
|
+
from oe_python_template import Service
|
|
14
|
+
|
|
15
|
+
HELLO_WORLD_EXAMPLE = "Hello, world!"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
app = FastAPI(
|
|
19
|
+
version="1.0.0",
|
|
20
|
+
title="OE Python Template",
|
|
21
|
+
contact={
|
|
22
|
+
"name": "Helmut Hoffer von Ankershoffen",
|
|
23
|
+
"email": "helmuthva@gmail.com",
|
|
24
|
+
"url": "https://github.com/helmut-hoffer-von-ankershoffen",
|
|
25
|
+
},
|
|
26
|
+
terms_of_service="https://oe-python-template.readthedocs.io/en/latest/",
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class HelloWorldResponse(BaseModel):
|
|
31
|
+
"""Response model for hello-world endpoint."""
|
|
32
|
+
|
|
33
|
+
message: str = Field(
|
|
34
|
+
...,
|
|
35
|
+
description="The hello world message",
|
|
36
|
+
examples=[HELLO_WORLD_EXAMPLE],
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class EchoResponse(BaseModel):
|
|
41
|
+
"""Response model for echo endpoint."""
|
|
42
|
+
|
|
43
|
+
message: str = Field(
|
|
44
|
+
...,
|
|
45
|
+
min_length=1,
|
|
46
|
+
description="The message content",
|
|
47
|
+
examples=[HELLO_WORLD_EXAMPLE],
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class EchoRequest(BaseModel):
|
|
52
|
+
"""Request model for echo endpoint."""
|
|
53
|
+
|
|
54
|
+
text: str = Field(
|
|
55
|
+
...,
|
|
56
|
+
min_length=1,
|
|
57
|
+
description="The text to echo back",
|
|
58
|
+
examples=[HELLO_WORLD_EXAMPLE],
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@app.get("/hello-world", tags=["Basics"])
|
|
63
|
+
async def hello_world() -> HelloWorldResponse:
|
|
64
|
+
"""
|
|
65
|
+
Return a hello world message.
|
|
66
|
+
|
|
67
|
+
Returns:
|
|
68
|
+
HelloWorldResponse: A response containing the hello world message.
|
|
69
|
+
"""
|
|
70
|
+
return HelloWorldResponse(message=Service.get_hello_world())
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
@app.post("/echo", tags=["Basics"])
|
|
74
|
+
async def echo(request: EchoRequest) -> EchoResponse:
|
|
75
|
+
"""
|
|
76
|
+
Echo back the provided text.
|
|
77
|
+
|
|
78
|
+
Args:
|
|
79
|
+
request (EchoRequest): The request containing the text to echo back.
|
|
80
|
+
|
|
81
|
+
Returns:
|
|
82
|
+
EchoResponse: A response containing the echoed text.
|
|
83
|
+
|
|
84
|
+
Raises:
|
|
85
|
+
422 Unprocessable Entity: If text is not provided or empty.
|
|
86
|
+
"""
|
|
87
|
+
return EchoResponse(message=request.text)
|
oe_python_template/cli.py
CHANGED
|
@@ -3,9 +3,12 @@
|
|
|
3
3
|
from typing import Annotated
|
|
4
4
|
|
|
5
5
|
import typer
|
|
6
|
+
import uvicorn
|
|
7
|
+
import yaml
|
|
6
8
|
from rich.console import Console
|
|
7
9
|
|
|
8
10
|
from oe_python_template import Service, __version__
|
|
11
|
+
from oe_python_template.api import app as api
|
|
9
12
|
|
|
10
13
|
console = Console()
|
|
11
14
|
|
|
@@ -37,6 +40,36 @@ def hello_world() -> None:
|
|
|
37
40
|
console.print(Service.get_hello_world())
|
|
38
41
|
|
|
39
42
|
|
|
43
|
+
@cli.command()
|
|
44
|
+
def serve(
|
|
45
|
+
host: Annotated[str, typer.Option(help="Host to bind the server to")] = "127.0.0.1",
|
|
46
|
+
port: Annotated[int, typer.Option(help="Port to bind the server to")] = 8000,
|
|
47
|
+
reload: Annotated[bool, typer.Option(help="Enable auto-reload")] = True,
|
|
48
|
+
) -> None:
|
|
49
|
+
"""Start the API server."""
|
|
50
|
+
console.print(f"Starting API server at http://{host}:{port}")
|
|
51
|
+
uvicorn.run(
|
|
52
|
+
"oe_python_template.api:app",
|
|
53
|
+
host=host,
|
|
54
|
+
port=port,
|
|
55
|
+
reload=reload,
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@cli.command()
|
|
60
|
+
def openapi(
|
|
61
|
+
output_format: Annotated[
|
|
62
|
+
str, typer.Option(help="Output format (yaml or json), defaults to yaml", case_sensitive=False)
|
|
63
|
+
] = "yaml",
|
|
64
|
+
) -> None:
|
|
65
|
+
"""Dump the OpenAPI specification to stdout (YAML by default)."""
|
|
66
|
+
schema = api.openapi()
|
|
67
|
+
if output_format.lower() == "json":
|
|
68
|
+
console.print_json(data=schema)
|
|
69
|
+
else:
|
|
70
|
+
console.print(yaml.dump(schema, default_flow_style=False), end="")
|
|
71
|
+
|
|
72
|
+
|
|
40
73
|
def _apply_cli_settings(cli: typer.Typer, epilog: str) -> None:
|
|
41
74
|
"""Add epilog to all typers in the tree and configure default behavior."""
|
|
42
75
|
cli.info.epilog = epilog
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: oe-python-template
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.7
|
|
4
4
|
Summary: 🧠 Copier template to scaffold Python projects compliant with best practices and modern tooling.
|
|
5
5
|
Project-URL: Homepage, https://oe-python-template.readthedocs.io/en/latest/
|
|
6
6
|
Project-URL: Documentation, https://oe-python-template.readthedocs.io/en/latest/
|
|
@@ -48,6 +48,7 @@ Classifier: Programming Language :: Python :: 3.12
|
|
|
48
48
|
Classifier: Programming Language :: Python :: 3.13
|
|
49
49
|
Classifier: Typing :: Typed
|
|
50
50
|
Requires-Python: <4.0,>=3.11
|
|
51
|
+
Requires-Dist: fastapi[all,standard]>=0.115.11
|
|
51
52
|
Requires-Dist: pydantic>=2.10.6
|
|
52
53
|
Requires-Dist: python-dotenv>=1.0.1
|
|
53
54
|
Requires-Dist: typer>=0.15.1
|
|
@@ -183,7 +184,7 @@ uvx oe-python-template hello-world --help # help for specific command
|
|
|
183
184
|
|
|
184
185
|
* Copier template to scaffold Python projects compliant with best practices and modern tooling.
|
|
185
186
|
* Various Examples:
|
|
186
|
-
- [Simple Python script]
|
|
187
|
+
- [Simple Python script]({ github_repository_url_https }/blob/main/examples/script.py)
|
|
187
188
|
- [Streamlit web application](https://oe-python-template.streamlit.app/) deployed on [Streamlit Community Cloud](https://streamlit.io/cloud)
|
|
188
189
|
- [Jupyter](https://github.com/helmut-hoffer-von-ankershoffen/oe-python-template/blob/main/examples/notebook.ipynb) and [Marimo](https://github.com/helmut-hoffer-von-ankershoffen/oe-python-template/blob/main/examples/notebook.py) notebook
|
|
189
190
|
* [Complete reference documenation](https://oe-python-template.readthedocs.io/en/latest/reference.html) on Read the Docs
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
oe_python_template/__init__.py,sha256=XJAycUgDI2K8T0jVcXbaGfx2UAQJZbYcvJ_SYSqFyDA,315
|
|
2
|
+
oe_python_template/api.py,sha256=NbjvA9_VWzOASi31SY62DFQBrzcMpwxzWoqcuiQ6LZs,2179
|
|
3
|
+
oe_python_template/cli.py,sha256=t6nV6jHzYmrwz_PkNDj7njSElqd3jeQc0wqELBxxuBw,2351
|
|
4
|
+
oe_python_template/constants.py,sha256=Z1c06l5DeRuFxYVLHihHHTYvr8_Qh0nyzVKOe5X3ZNs,350
|
|
5
|
+
oe_python_template/service.py,sha256=p59ch0g81LpsRvL-m-vLPuk0Rf6EYsZfZJ_OCA9vWzQ,500
|
|
6
|
+
oe_python_template-0.3.7.dist-info/METADATA,sha256=qBlv1KLbMAUOKncNmBHsVoS0nOg9iiSGm1POexk5JTY,19227
|
|
7
|
+
oe_python_template-0.3.7.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
8
|
+
oe_python_template-0.3.7.dist-info/entry_points.txt,sha256=IroSSWhLGxus9rxcashkYQda39TTvf7LbUMYtOKXUBE,66
|
|
9
|
+
oe_python_template-0.3.7.dist-info/licenses/LICENSE,sha256=5H409K6xzz9U5eUaoAHQExNkoWJRlU0LEj6wL2QJ34s,1113
|
|
10
|
+
oe_python_template-0.3.7.dist-info/RECORD,,
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
oe_python_template/__init__.py,sha256=XJAycUgDI2K8T0jVcXbaGfx2UAQJZbYcvJ_SYSqFyDA,315
|
|
2
|
-
oe_python_template/cli.py,sha256=5tUw70ffHL-ot0rM7g6BmsVhn9IKBQXwbWU0-n9-wb4,1319
|
|
3
|
-
oe_python_template/constants.py,sha256=Z1c06l5DeRuFxYVLHihHHTYvr8_Qh0nyzVKOe5X3ZNs,350
|
|
4
|
-
oe_python_template/service.py,sha256=p59ch0g81LpsRvL-m-vLPuk0Rf6EYsZfZJ_OCA9vWzQ,500
|
|
5
|
-
oe_python_template-0.3.5.dist-info/METADATA,sha256=a0cicobo8zqGnENxF8RcTHVKQk1-hYazMSXoVj4Zm_U,19216
|
|
6
|
-
oe_python_template-0.3.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
7
|
-
oe_python_template-0.3.5.dist-info/entry_points.txt,sha256=IroSSWhLGxus9rxcashkYQda39TTvf7LbUMYtOKXUBE,66
|
|
8
|
-
oe_python_template-0.3.5.dist-info/licenses/LICENSE,sha256=5H409K6xzz9U5eUaoAHQExNkoWJRlU0LEj6wL2QJ34s,1113
|
|
9
|
-
oe_python_template-0.3.5.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|