oe-python-template 0.6.30__py3-none-any.whl → 0.6.32__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/__init__.py +5 -0
- oe_python_template/api.py +17 -75
- oe_python_template/cli.py +4 -3
- oe_python_template/models.py +44 -0
- oe_python_template/service.py +19 -1
- {oe_python_template-0.6.30.dist-info → oe_python_template-0.6.32.dist-info}/METADATA +6 -5
- oe_python_template-0.6.32.dist-info/RECORD +11 -0
- oe_python_template-0.6.30.dist-info/RECORD +0 -10
- {oe_python_template-0.6.30.dist-info → oe_python_template-0.6.32.dist-info}/WHEEL +0 -0
- {oe_python_template-0.6.30.dist-info → oe_python_template-0.6.32.dist-info}/entry_points.txt +0 -0
- {oe_python_template-0.6.30.dist-info → oe_python_template-0.6.32.dist-info}/licenses/LICENSE +0 -0
oe_python_template/__init__.py
CHANGED
|
@@ -5,10 +5,15 @@ from .constants import (
|
|
|
5
5
|
__project_path__,
|
|
6
6
|
__version__,
|
|
7
7
|
)
|
|
8
|
+
from .models import Echo, Health, HealthStatus, Utterance
|
|
8
9
|
from .service import Service
|
|
9
10
|
|
|
10
11
|
__all__ = [
|
|
12
|
+
"Echo",
|
|
13
|
+
"Health",
|
|
14
|
+
"HealthStatus",
|
|
11
15
|
"Service",
|
|
16
|
+
"Utterance",
|
|
12
17
|
"__project_name__",
|
|
13
18
|
"__project_path__",
|
|
14
19
|
"__version__",
|
oe_python_template/api.py
CHANGED
|
@@ -10,13 +10,12 @@ The endpoints use Pydantic models for request and response validation.
|
|
|
10
10
|
|
|
11
11
|
import os
|
|
12
12
|
from collections.abc import Generator
|
|
13
|
-
from enum import StrEnum
|
|
14
13
|
from typing import Annotated
|
|
15
14
|
|
|
16
15
|
from fastapi import Depends, FastAPI, Response, status
|
|
17
16
|
from pydantic import BaseModel, Field
|
|
18
17
|
|
|
19
|
-
from oe_python_template import Service
|
|
18
|
+
from oe_python_template import Echo, Health, HealthStatus, Service, Utterance
|
|
20
19
|
|
|
21
20
|
TITLE = "OE Python Template"
|
|
22
21
|
HELLO_WORLD_EXAMPLE = "Hello, world!"
|
|
@@ -94,30 +93,6 @@ api_v2 = FastAPI(
|
|
|
94
93
|
)
|
|
95
94
|
|
|
96
95
|
|
|
97
|
-
class _HealthStatus(StrEnum):
|
|
98
|
-
"""Health status enumeration."""
|
|
99
|
-
|
|
100
|
-
UP = "UP"
|
|
101
|
-
DOWN = "DOWN"
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
class Health(BaseModel):
|
|
105
|
-
"""Health status model."""
|
|
106
|
-
|
|
107
|
-
status: _HealthStatus
|
|
108
|
-
reason: str | None = None
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
class HealthResponse(BaseModel):
|
|
112
|
-
"""Response model for health endpoint."""
|
|
113
|
-
|
|
114
|
-
health: str = Field(
|
|
115
|
-
...,
|
|
116
|
-
description="The hello world message",
|
|
117
|
-
examples=[HELLO_WORLD_EXAMPLE],
|
|
118
|
-
)
|
|
119
|
-
|
|
120
|
-
|
|
121
96
|
@api_v1.get("/healthz", tags=["Observability"])
|
|
122
97
|
@api_v1.get("/health", tags=["Observability"])
|
|
123
98
|
@api_v2.get("/healthz", tags=["Observability"])
|
|
@@ -136,17 +111,17 @@ async def health(service: Annotated[Service, Depends(get_service)], response: Re
|
|
|
136
111
|
Health: The health status of the service.
|
|
137
112
|
"""
|
|
138
113
|
if service.healthy():
|
|
139
|
-
health_result = Health(status=
|
|
114
|
+
health_result = Health(status=HealthStatus.UP)
|
|
140
115
|
else:
|
|
141
|
-
health_result = Health(status=
|
|
116
|
+
health_result = Health(status=HealthStatus.DOWN, reason="Service is unhealthy")
|
|
142
117
|
|
|
143
|
-
if health_result.status ==
|
|
118
|
+
if health_result.status == HealthStatus.DOWN:
|
|
144
119
|
response.status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
|
|
145
120
|
|
|
146
121
|
return health_result
|
|
147
122
|
|
|
148
123
|
|
|
149
|
-
class
|
|
124
|
+
class _HelloWorldResponse(BaseModel):
|
|
150
125
|
"""Response model for hello-world endpoint."""
|
|
151
126
|
|
|
152
127
|
message: str = Field(
|
|
@@ -158,81 +133,48 @@ class HelloWorldResponse(BaseModel):
|
|
|
158
133
|
|
|
159
134
|
@api_v1.get("/hello-world", tags=["Basics"])
|
|
160
135
|
@api_v2.get("/hello-world", tags=["Basics"])
|
|
161
|
-
async def hello_world() ->
|
|
136
|
+
async def hello_world() -> _HelloWorldResponse:
|
|
162
137
|
"""
|
|
163
138
|
Return a hello world message.
|
|
164
139
|
|
|
165
140
|
Returns:
|
|
166
|
-
|
|
141
|
+
_HelloWorldResponse: A response containing the hello world message.
|
|
167
142
|
"""
|
|
168
|
-
return
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
class EchoResponse(BaseModel):
|
|
172
|
-
"""Response model for echo endpoint."""
|
|
173
|
-
|
|
174
|
-
message: str = Field(
|
|
175
|
-
...,
|
|
176
|
-
min_length=1,
|
|
177
|
-
description="The message content",
|
|
178
|
-
examples=[HELLO_WORLD_EXAMPLE],
|
|
179
|
-
)
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
class EchoRequest(BaseModel):
|
|
183
|
-
"""Request model for echo endpoint."""
|
|
184
|
-
|
|
185
|
-
text: str = Field(
|
|
186
|
-
...,
|
|
187
|
-
min_length=1,
|
|
188
|
-
description="The text to echo back",
|
|
189
|
-
examples=[HELLO_WORLD_EXAMPLE],
|
|
190
|
-
)
|
|
143
|
+
return _HelloWorldResponse(message=Service.get_hello_world())
|
|
191
144
|
|
|
192
145
|
|
|
193
|
-
@api_v1.
|
|
194
|
-
async def echo(
|
|
146
|
+
@api_v1.get("/echo/{text}", tags=["Basics"])
|
|
147
|
+
async def echo(text: str) -> Echo:
|
|
195
148
|
"""
|
|
196
149
|
Echo back the provided text.
|
|
197
150
|
|
|
198
151
|
Args:
|
|
199
|
-
|
|
152
|
+
text (str): The text to echo.
|
|
200
153
|
|
|
201
154
|
Returns:
|
|
202
|
-
|
|
155
|
+
Echo: The echo.
|
|
203
156
|
|
|
204
157
|
Raises:
|
|
205
158
|
422 Unprocessable Entity: If text is not provided or empty.
|
|
206
159
|
"""
|
|
207
|
-
return
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
class Utterance(BaseModel):
|
|
211
|
-
"""Request model for echo endpoint."""
|
|
212
|
-
|
|
213
|
-
utterance: str = Field(
|
|
214
|
-
...,
|
|
215
|
-
min_length=1,
|
|
216
|
-
description="The utterance to echo back",
|
|
217
|
-
examples=[HELLO_WORLD_EXAMPLE],
|
|
218
|
-
)
|
|
160
|
+
return Service.echo(Utterance(text=text))
|
|
219
161
|
|
|
220
162
|
|
|
221
163
|
@api_v2.post("/echo", tags=["Basics"])
|
|
222
|
-
async def echo_v2(request: Utterance) ->
|
|
164
|
+
async def echo_v2(request: Utterance) -> Echo:
|
|
223
165
|
"""
|
|
224
166
|
Echo back the provided utterance.
|
|
225
167
|
|
|
226
168
|
Args:
|
|
227
|
-
request (Utterance): The
|
|
169
|
+
request (Utterance): The utterance to echo back.
|
|
228
170
|
|
|
229
171
|
Returns:
|
|
230
|
-
|
|
172
|
+
Echo: The echo.
|
|
231
173
|
|
|
232
174
|
Raises:
|
|
233
175
|
422 Unprocessable Entity: If utterance is not provided or empty.
|
|
234
176
|
"""
|
|
235
|
-
return
|
|
177
|
+
return Service.echo(request)
|
|
236
178
|
|
|
237
179
|
|
|
238
180
|
api.mount("/v1", api_v1)
|
oe_python_template/cli.py
CHANGED
|
@@ -9,7 +9,7 @@ import uvicorn
|
|
|
9
9
|
import yaml
|
|
10
10
|
from rich.console import Console
|
|
11
11
|
|
|
12
|
-
from oe_python_template import Service, __version__
|
|
12
|
+
from oe_python_template import Service, Utterance, __version__
|
|
13
13
|
from oe_python_template.api import api_v1, api_v2
|
|
14
14
|
|
|
15
15
|
console = Console()
|
|
@@ -30,10 +30,11 @@ def echo(
|
|
|
30
30
|
] = False,
|
|
31
31
|
) -> None:
|
|
32
32
|
"""Echo the text."""
|
|
33
|
+
echo = Service.echo(Utterance(text=text))
|
|
33
34
|
if json:
|
|
34
|
-
console.print_json(data={"text": text})
|
|
35
|
+
console.print_json(data={"text": echo.text})
|
|
35
36
|
else:
|
|
36
|
-
console.print(text)
|
|
37
|
+
console.print(echo.text)
|
|
37
38
|
|
|
38
39
|
|
|
39
40
|
@cli.command()
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"""Models used throughout OE Python Template's codebase ."""
|
|
2
|
+
|
|
3
|
+
from enum import StrEnum
|
|
4
|
+
|
|
5
|
+
from pydantic import BaseModel, Field
|
|
6
|
+
|
|
7
|
+
UTTERANCE_EXAMPLE = "Hello, world!"
|
|
8
|
+
ECHO_EXAMPLE = "HELLO, WORLD!"
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Utterance(BaseModel):
|
|
12
|
+
"""Model representing a text utterance."""
|
|
13
|
+
|
|
14
|
+
text: str = Field(
|
|
15
|
+
...,
|
|
16
|
+
min_length=1,
|
|
17
|
+
description="The utterance to echo back",
|
|
18
|
+
examples=[UTTERANCE_EXAMPLE],
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class Echo(BaseModel):
|
|
23
|
+
"""Response model for echo endpoint."""
|
|
24
|
+
|
|
25
|
+
text: str = Field(
|
|
26
|
+
...,
|
|
27
|
+
min_length=1,
|
|
28
|
+
description="The echo",
|
|
29
|
+
examples=[ECHO_EXAMPLE],
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class HealthStatus(StrEnum):
|
|
34
|
+
"""Health status enumeration."""
|
|
35
|
+
|
|
36
|
+
UP = "UP"
|
|
37
|
+
DOWN = "DOWN"
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class Health(BaseModel):
|
|
41
|
+
"""Health status model."""
|
|
42
|
+
|
|
43
|
+
status: HealthStatus
|
|
44
|
+
reason: str | None = None
|
oe_python_template/service.py
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
"""Service of OE Python Template."""
|
|
1
|
+
"""Service of OE Python Template's."""
|
|
2
2
|
|
|
3
3
|
import os
|
|
4
4
|
|
|
5
5
|
from dotenv import load_dotenv
|
|
6
6
|
|
|
7
|
+
from oe_python_template.models import Echo, Utterance
|
|
8
|
+
|
|
7
9
|
load_dotenv()
|
|
8
10
|
THE_VAR = os.getenv("THE_VAR", "not defined")
|
|
9
11
|
|
|
@@ -33,3 +35,19 @@ class Service:
|
|
|
33
35
|
bool: True if the service is healthy, False otherwise.
|
|
34
36
|
"""
|
|
35
37
|
return self.is_healthy
|
|
38
|
+
|
|
39
|
+
@staticmethod
|
|
40
|
+
def echo(utterance: Utterance) -> Echo:
|
|
41
|
+
"""
|
|
42
|
+
Loudly echo utterance.
|
|
43
|
+
|
|
44
|
+
Args:
|
|
45
|
+
utterance (Utterance): The utterance to echo.
|
|
46
|
+
|
|
47
|
+
Returns:
|
|
48
|
+
Echo: The loudly echoed utterance.
|
|
49
|
+
|
|
50
|
+
Raises:
|
|
51
|
+
ValueError: If the utterance is empty or contains only whitespace.
|
|
52
|
+
"""
|
|
53
|
+
return Echo(text=utterance.text.upper())
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: oe-python-template
|
|
3
|
-
Version: 0.6.
|
|
3
|
+
Version: 0.6.32
|
|
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/
|
|
@@ -112,7 +112,7 @@ This [Copier](https://copier.readthedocs.io/en/stable/) template enables you to
|
|
|
112
112
|
|
|
113
113
|
### Development Infrastructure
|
|
114
114
|
|
|
115
|
-
Projects generated with
|
|
115
|
+
Projects generated with this template come with a comprehensive development toolchain and quality assurance framework that supports the entire software development lifecycle - from coding and testing to documentation, release management, and compliance auditing. This infrastructure automates routine tasks, enforces code quality standards, and streamlines the path to production:
|
|
116
116
|
|
|
117
117
|
1. Linting with [Ruff](https://github.com/astral-sh/ruff)
|
|
118
118
|
2. Static type checking with [mypy](https://mypy.readthedocs.io/en/stable/)
|
|
@@ -198,9 +198,10 @@ external services such as CloudCov, SonarQube Cloud, Read The Docs, Docker.io, a
|
|
|
198
198
|
./n bump
|
|
199
199
|
```
|
|
200
200
|
Notes:
|
|
201
|
-
1. You can remove this
|
|
202
|
-
2. The following sections refer to the dummy application and service
|
|
203
|
-
Use
|
|
201
|
+
1. You can remove the above sections - from "Scaffolding" to this notes - post having successfully generated your project.
|
|
202
|
+
2. The following sections refer to the dummy application and service generated into the `tests` and `src` folder by this template.
|
|
203
|
+
Use the documentation and code as inspiration, adapt to your business logic, or remove and start documenting and coding from scratch.
|
|
204
|
+
|
|
204
205
|
|
|
205
206
|
## Overview
|
|
206
207
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
oe_python_template/__init__.py,sha256=R49r9JJnOBe4HrPGcu37ySvguxpGzQgTM7LtlyRnUK0,436
|
|
2
|
+
oe_python_template/api.py,sha256=ZBtx7vSHAUzZDwhwp8Q0zW1Bg9-sPs73cLPA7lbeHWk,4978
|
|
3
|
+
oe_python_template/cli.py,sha256=RwVJztulrFbdKRASqdjWLhCM7YNgBoxiP4tvlmekE30,3493
|
|
4
|
+
oe_python_template/constants.py,sha256=Z1c06l5DeRuFxYVLHihHHTYvr8_Qh0nyzVKOe5X3ZNs,350
|
|
5
|
+
oe_python_template/models.py,sha256=L9uwom3TkuOpN3R30bGKEBQKcrLLEMc-O9e8VVSNTGw,838
|
|
6
|
+
oe_python_template/service.py,sha256=wHwaD_2oSMle41QKXC64T4uKznUnyuV9d4b9Cu7lIoY,1202
|
|
7
|
+
oe_python_template-0.6.32.dist-info/METADATA,sha256=cDKXOr7SAbnWpY4yoylRejd2eq-ncrqp8v1WNYvBeVU,27672
|
|
8
|
+
oe_python_template-0.6.32.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
9
|
+
oe_python_template-0.6.32.dist-info/entry_points.txt,sha256=IroSSWhLGxus9rxcashkYQda39TTvf7LbUMYtOKXUBE,66
|
|
10
|
+
oe_python_template-0.6.32.dist-info/licenses/LICENSE,sha256=5H409K6xzz9U5eUaoAHQExNkoWJRlU0LEj6wL2QJ34s,1113
|
|
11
|
+
oe_python_template-0.6.32.dist-info/RECORD,,
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
oe_python_template/__init__.py,sha256=XJAycUgDI2K8T0jVcXbaGfx2UAQJZbYcvJ_SYSqFyDA,315
|
|
2
|
-
oe_python_template/api.py,sha256=-7d4cLPHmdLZSkzu6UOaCp9hUO0Aq8MNq8uEZuiW9Y4,6259
|
|
3
|
-
oe_python_template/cli.py,sha256=jvIPeJzx9esff7-M5pBe2R3vvmpxRvxKIre1VOGndls,3426
|
|
4
|
-
oe_python_template/constants.py,sha256=Z1c06l5DeRuFxYVLHihHHTYvr8_Qh0nyzVKOe5X3ZNs,350
|
|
5
|
-
oe_python_template/service.py,sha256=Gd-B9IIZ1vB1uONVJHA65hPnfeYeKUIcnU3rZbU2lGs,744
|
|
6
|
-
oe_python_template-0.6.30.dist-info/METADATA,sha256=UJ3jCMlRmEw9rFAjD58iyrAPCe_Vs_2bzJNRNQIDvCU,27518
|
|
7
|
-
oe_python_template-0.6.30.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
8
|
-
oe_python_template-0.6.30.dist-info/entry_points.txt,sha256=IroSSWhLGxus9rxcashkYQda39TTvf7LbUMYtOKXUBE,66
|
|
9
|
-
oe_python_template-0.6.30.dist-info/licenses/LICENSE,sha256=5H409K6xzz9U5eUaoAHQExNkoWJRlU0LEj6wL2QJ34s,1113
|
|
10
|
-
oe_python_template-0.6.30.dist-info/RECORD,,
|
|
File without changes
|
{oe_python_template-0.6.30.dist-info → oe_python_template-0.6.32.dist-info}/entry_points.txt
RENAMED
|
File without changes
|
{oe_python_template-0.6.30.dist-info → oe_python_template-0.6.32.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|