oe-python-template-example 0.0.7__py3-none-any.whl → 0.0.8__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.
@@ -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_example import Service
14
+
15
+ HELLO_WORLD_EXAMPLE = "Hello, world!"
16
+
17
+
18
+ app = FastAPI(
19
+ version="1.0.0",
20
+ title="OE Python Template Example",
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-example.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)
@@ -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_example import Service, __version__
11
+ from oe_python_template_example.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_example.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-example
3
- Version: 0.0.7
3
+ Version: 0.0.8
4
4
  Summary: 🧠 Example project scaffolded and kept up to date with OE Python Template (oe-python-template).
5
5
  Project-URL: Homepage, https://oe-python-template-example.readthedocs.io/en/latest/
6
6
  Project-URL: Documentation, https://oe-python-template-example.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
@@ -127,7 +128,7 @@ copier copy gh:helmut-hoffer-von-ankershoffen/oe-python-template .
127
128
  Step 4: Setup the local environment
128
129
 
129
130
  ```shell
130
- uv run nox -s setup_eev
131
+ uv run nox -s setup_dev
131
132
  ```
132
133
 
133
134
  Step 5: Perform inital commit and push
@@ -174,8 +175,8 @@ uvx oe-python-template-example
174
175
  The CLI provides extensive help:
175
176
 
176
177
  ```shell
177
- uvx oe-python-template-example --help # all CLI commands
178
- uvx oe-python-template-example command --help # all options for command
178
+ uvx oe-python-template-example --help # all CLI commands
179
+ uvx oe-python-template-example hello-world --help # help for specific command
179
180
  ```
180
181
 
181
182
 
@@ -0,0 +1,10 @@
1
+ oe_python_template_example/__init__.py,sha256=-sCwS9lD6CvgWw88f7snBDF947PWIhEupJVebXL_w1M,314
2
+ oe_python_template_example/api.py,sha256=3OmZFB_5bVdHS6wcGttfgiOmq86K5R6lXOzvTPXIQ94,2203
3
+ oe_python_template_example/cli.py,sha256=ptgFKScjYQAj364TCBqs23rVZqIpXUxUXEoc_4f1YJE,2399
4
+ oe_python_template_example/constants.py,sha256=6uQHr2CRgzWQWhUQCRRKiPuFhzKB2iblZk3dIRQ5dDc,358
5
+ oe_python_template_example/service.py,sha256=ZpsZFnnJm_3EqoVqGomfAyIjLVmWJFuJ3G9qatWj5yI,516
6
+ oe_python_template_example-0.0.8.dist-info/METADATA,sha256=E5qbQjBSvgDTEqxceoqIYvOMjekUwGc3LRUXYWEmxI4,20031
7
+ oe_python_template_example-0.0.8.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
8
+ oe_python_template_example-0.0.8.dist-info/entry_points.txt,sha256=S2eCPB45b1Wgj_GsDRFAN-e4h7dBA5UPxT8od98erDE,82
9
+ oe_python_template_example-0.0.8.dist-info/licenses/LICENSE,sha256=5H409K6xzz9U5eUaoAHQExNkoWJRlU0LEj6wL2QJ34s,1113
10
+ oe_python_template_example-0.0.8.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- oe_python_template_example/__init__.py,sha256=-sCwS9lD6CvgWw88f7snBDF947PWIhEupJVebXL_w1M,314
2
- oe_python_template_example/cli.py,sha256=6giUEesoEuwytZnthiTBH9-ALkiwdkTL4TEb7vsqbGM,1351
3
- oe_python_template_example/constants.py,sha256=6uQHr2CRgzWQWhUQCRRKiPuFhzKB2iblZk3dIRQ5dDc,358
4
- oe_python_template_example/service.py,sha256=ZpsZFnnJm_3EqoVqGomfAyIjLVmWJFuJ3G9qatWj5yI,516
5
- oe_python_template_example-0.0.7.dist-info/METADATA,sha256=2zKINPEf3Z6IjOkP_gYtBt6WwAwXineL8JtCFExWnxQ,19978
6
- oe_python_template_example-0.0.7.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
- oe_python_template_example-0.0.7.dist-info/entry_points.txt,sha256=S2eCPB45b1Wgj_GsDRFAN-e4h7dBA5UPxT8od98erDE,82
8
- oe_python_template_example-0.0.7.dist-info/licenses/LICENSE,sha256=5H409K6xzz9U5eUaoAHQExNkoWJRlU0LEj6wL2QJ34s,1113
9
- oe_python_template_example-0.0.7.dist-info/RECORD,,