oe-python-template 0.6.30__tar.gz → 0.6.32__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: oe-python-template
3
- Version: 0.6.30
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 the 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:
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 section post having successfully generated your project.
202
- 2. The following sections refer to the dummy application and service provided by this template.
203
- Use them as inspiration and adapt them to your own project.
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
 
@@ -51,7 +51,7 @@ This [Copier](https://copier.readthedocs.io/en/stable/) template enables you to
51
51
 
52
52
  ### Development Infrastructure
53
53
 
54
- Projects generated with the 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:
54
+ 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:
55
55
 
56
56
  1. Linting with [Ruff](https://github.com/astral-sh/ruff)
57
57
  2. Static type checking with [mypy](https://mypy.readthedocs.io/en/stable/)
@@ -137,9 +137,10 @@ external services such as CloudCov, SonarQube Cloud, Read The Docs, Docker.io, a
137
137
  ./n bump
138
138
  ```
139
139
  Notes:
140
- 1. You can remove this section post having successfully generated your project.
141
- 2. The following sections refer to the dummy application and service provided by this template.
142
- Use them as inspiration and adapt them to your own project.
140
+ 1. You can remove the above sections - from "Scaffolding" to this notes - post having successfully generated your project.
141
+ 2. The following sections refer to the dummy application and service generated into the `tests` and `src` folder by this template.
142
+ Use the documentation and code as inspiration, adapt to your business logic, or remove and start documenting and coding from scratch.
143
+
143
144
 
144
145
  ## Overview
145
146
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "oe-python-template"
3
- version = "0.6.30"
3
+ version = "0.6.32"
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,7 @@ 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",
128
+ # "sphinx-pydantic>=0.1.1",
129
129
  "sphinx-rtd-theme>=3.0.2",
130
130
  "sphinx_selective_exclude>=1.0.3",
131
131
  "sphinx-toolbox>=3.9.0",
@@ -136,6 +136,13 @@ dev = [
136
136
  "watchdog>=6.0.0",
137
137
  ]
138
138
 
139
+ [tool.uv]
140
+ override-dependencies = [ # https://github.com/astral-sh/uv/issues/4422
141
+ "rfc3987; sys_platform == 'never'", # GPLv3
142
+ "sphinx-jsonschema; sys_platform == 'never'", # GPLv3
143
+ ]
144
+
145
+
139
146
  [tool.ruff]
140
147
  target-version = "py311"
141
148
  preview = true
@@ -248,7 +255,7 @@ source = ["src/"]
248
255
 
249
256
 
250
257
  [tool.bumpversion]
251
- current_version = "0.6.30"
258
+ current_version = "0.6.32"
252
259
  parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)"
253
260
  serialize = ["{major}.{minor}.{patch}"]
254
261
  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=_HealthStatus.UP)
114
+ health_result = Health(status=HealthStatus.UP)
140
115
  else:
141
- health_result = Health(status=_HealthStatus.DOWN, reason="Service is unhealthy")
116
+ health_result = Health(status=HealthStatus.DOWN, reason="Service is unhealthy")
142
117
 
143
- if health_result.status == _HealthStatus.DOWN:
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 HelloWorldResponse(BaseModel):
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() -> HelloWorldResponse:
136
+ async def hello_world() -> _HelloWorldResponse:
162
137
  """
163
138
  Return a hello world message.
164
139
 
165
140
  Returns:
166
- HelloWorldResponse: A response containing the hello world message.
141
+ _HelloWorldResponse: A response containing the hello world message.
167
142
  """
168
- return HelloWorldResponse(message=Service.get_hello_world())
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.post("/echo", tags=["Basics"])
194
- async def echo(request: EchoRequest) -> EchoResponse:
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
- request (EchoRequest): The request containing the text to echo back.
152
+ text (str): The text to echo.
200
153
 
201
154
  Returns:
202
- EchoResponse: A response containing the echoed text.
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 EchoResponse(message=request.text)
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) -> EchoResponse:
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 request containing the utterance to echo back.
169
+ request (Utterance): The utterance to echo back.
228
170
 
229
171
  Returns:
230
- EchoResponse: A response containing the echoed utterance.
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 EchoResponse(message=request.utterance)
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())