oe-python-template 0.6.31__tar.gz → 0.6.33__tar.gz
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-0.6.31 → oe_python_template-0.6.33}/PKG-INFO +1 -1
- {oe_python_template-0.6.31 → oe_python_template-0.6.33}/pyproject.toml +8 -3
- {oe_python_template-0.6.31 → oe_python_template-0.6.33}/src/oe_python_template/__init__.py +5 -0
- {oe_python_template-0.6.31 → oe_python_template-0.6.33}/src/oe_python_template/api.py +17 -75
- {oe_python_template-0.6.31 → oe_python_template-0.6.33}/src/oe_python_template/cli.py +4 -3
- oe_python_template-0.6.33/src/oe_python_template/models.py +44 -0
- {oe_python_template-0.6.31 → oe_python_template-0.6.33}/src/oe_python_template/service.py +19 -1
- {oe_python_template-0.6.31 → oe_python_template-0.6.33}/.gitignore +0 -0
- {oe_python_template-0.6.31 → oe_python_template-0.6.33}/LICENSE +0 -0
- {oe_python_template-0.6.31 → oe_python_template-0.6.33}/README.md +0 -0
- {oe_python_template-0.6.31 → oe_python_template-0.6.33}/src/oe_python_template/constants.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: oe-python-template
|
|
3
|
-
Version: 0.6.
|
|
3
|
+
Version: 0.6.33
|
|
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/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "oe-python-template"
|
|
3
|
-
version = "0.6.
|
|
3
|
+
version = "0.6.33"
|
|
4
4
|
description = "🧠 Copier template to scaffold Python projects compliant with best practices and modern tooling."
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
authors = [
|
|
@@ -125,7 +125,6 @@ dev = [
|
|
|
125
125
|
"sphinx-copybutton>=0.5.2",
|
|
126
126
|
"sphinx-inline-tabs>=2023.4.21",
|
|
127
127
|
"sphinx-mdinclude>=0.6.2",
|
|
128
|
-
"sphinx-pydantic>=0.1.1",
|
|
129
128
|
"sphinx-rtd-theme>=3.0.2",
|
|
130
129
|
"sphinx_selective_exclude>=1.0.3",
|
|
131
130
|
"sphinx-toolbox>=3.9.0",
|
|
@@ -136,6 +135,12 @@ dev = [
|
|
|
136
135
|
"watchdog>=6.0.0",
|
|
137
136
|
]
|
|
138
137
|
|
|
138
|
+
[tool.uv]
|
|
139
|
+
override-dependencies = [ # https://github.com/astral-sh/uv/issues/4422
|
|
140
|
+
"rfc3987; sys_platform == 'never'", # GPLv3
|
|
141
|
+
]
|
|
142
|
+
|
|
143
|
+
|
|
139
144
|
[tool.ruff]
|
|
140
145
|
target-version = "py311"
|
|
141
146
|
preview = true
|
|
@@ -248,7 +253,7 @@ source = ["src/"]
|
|
|
248
253
|
|
|
249
254
|
|
|
250
255
|
[tool.bumpversion]
|
|
251
|
-
current_version = "0.6.
|
|
256
|
+
current_version = "0.6.33"
|
|
252
257
|
parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)"
|
|
253
258
|
serialize = ["{major}.{minor}.{patch}"]
|
|
254
259
|
search = "{current_version}"
|
|
@@ -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__",
|
|
@@ -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)
|
|
@@ -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
|
|
@@ -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())
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|