djresttoolkit 0.7.0__tar.gz → 0.8.0__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.
- {djresttoolkit-0.7.0 → djresttoolkit-0.8.0}/PKG-INFO +75 -8
- {djresttoolkit-0.7.0 → djresttoolkit-0.8.0}/README.md +72 -7
- {djresttoolkit-0.7.0 → djresttoolkit-0.8.0}/pyproject.toml +3 -1
- djresttoolkit-0.8.0/src/djresttoolkit/envconfig/__init__.py +3 -0
- djresttoolkit-0.8.0/src/djresttoolkit/envconfig/_env_settings.py +84 -0
- {djresttoolkit-0.7.0 → djresttoolkit-0.8.0}/.gitignore +0 -0
- {djresttoolkit-0.7.0 → djresttoolkit-0.8.0}/LICENSE +0 -0
- {djresttoolkit-0.7.0 → djresttoolkit-0.8.0}/demo/staticfiles/admin/img/LICENSE +0 -0
- {djresttoolkit-0.7.0 → djresttoolkit-0.8.0}/src/djresttoolkit/__init__.py +0 -0
- {djresttoolkit-0.7.0 → djresttoolkit-0.8.0}/src/djresttoolkit/admin.py +0 -0
- {djresttoolkit-0.7.0 → djresttoolkit-0.8.0}/src/djresttoolkit/apps.py +0 -0
- {djresttoolkit-0.7.0 → djresttoolkit-0.8.0}/src/djresttoolkit/dbseed/__init__.py +0 -0
- {djresttoolkit-0.7.0 → djresttoolkit-0.8.0}/src/djresttoolkit/dbseed/models/__init__.py +0 -0
- {djresttoolkit-0.7.0 → djresttoolkit-0.8.0}/src/djresttoolkit/dbseed/models/_choice_field.py +0 -0
- {djresttoolkit-0.7.0 → djresttoolkit-0.8.0}/src/djresttoolkit/dbseed/models/_gen.py +0 -0
- {djresttoolkit-0.7.0 → djresttoolkit-0.8.0}/src/djresttoolkit/dbseed/models/_seed_model.py +0 -0
- {djresttoolkit-0.7.0 → djresttoolkit-0.8.0}/src/djresttoolkit/mail/__init__.py +0 -0
- {djresttoolkit-0.7.0 → djresttoolkit-0.8.0}/src/djresttoolkit/mail/_email_sender.py +0 -0
- {djresttoolkit-0.7.0 → djresttoolkit-0.8.0}/src/djresttoolkit/mail/_models.py +0 -0
- {djresttoolkit-0.7.0 → djresttoolkit-0.8.0}/src/djresttoolkit/mail/_types.py +0 -0
- {djresttoolkit-0.7.0 → djresttoolkit-0.8.0}/src/djresttoolkit/management/__init__.py +0 -0
- {djresttoolkit-0.7.0 → djresttoolkit-0.8.0}/src/djresttoolkit/management/commands/__init__.py +0 -0
- {djresttoolkit-0.7.0 → djresttoolkit-0.8.0}/src/djresttoolkit/management/commands/dbflush.py +0 -0
- {djresttoolkit-0.7.0 → djresttoolkit-0.8.0}/src/djresttoolkit/management/commands/dbseed.py +0 -0
- {djresttoolkit-0.7.0 → djresttoolkit-0.8.0}/src/djresttoolkit/middlewares/__init__.py +0 -0
- {djresttoolkit-0.7.0 → djresttoolkit-0.8.0}/src/djresttoolkit/middlewares/_response_time_middleware.py +0 -0
- {djresttoolkit-0.7.0 → djresttoolkit-0.8.0}/src/djresttoolkit/migrations/__init__.py +0 -0
- {djresttoolkit-0.7.0 → djresttoolkit-0.8.0}/src/djresttoolkit/models/__init__.py +0 -0
- {djresttoolkit-0.7.0 → djresttoolkit-0.8.0}/src/djresttoolkit/py.typed +0 -0
- {djresttoolkit-0.7.0 → djresttoolkit-0.8.0}/src/djresttoolkit/renderers/__init__.py +0 -0
- {djresttoolkit-0.7.0 → djresttoolkit-0.8.0}/src/djresttoolkit/renderers/_throttle_info_json_renderer.py +0 -0
- {djresttoolkit-0.7.0 → djresttoolkit-0.8.0}/src/djresttoolkit/throttling/__init__.py +0 -0
- {djresttoolkit-0.7.0 → djresttoolkit-0.8.0}/src/djresttoolkit/throttling/_throttle_inspector.py +0 -0
- {djresttoolkit-0.7.0 → djresttoolkit-0.8.0}/src/djresttoolkit/views/__init__.py +0 -0
- {djresttoolkit-0.7.0 → djresttoolkit-0.8.0}/src/djresttoolkit/views/_exceptions/__init__.py +0 -0
- {djresttoolkit-0.7.0 → djresttoolkit-0.8.0}/src/djresttoolkit/views/_exceptions/_exception_handler.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: djresttoolkit
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.8.0
|
4
4
|
Summary: A collection of Django and DRF utilities to simplify API development.
|
5
5
|
Project-URL: Homepage, https://github.com/shaileshpandit141/djresttoolkit
|
6
6
|
Project-URL: Documentation, https://shaileshpandit141.github.io/djresttoolkit
|
@@ -47,7 +47,9 @@ Classifier: Topic :: Utilities
|
|
47
47
|
Classifier: Typing :: Typed
|
48
48
|
Requires-Python: >=3.13
|
49
49
|
Requires-Dist: faker>=37.5.3
|
50
|
+
Requires-Dist: pydantic-settings>=2.10.1
|
50
51
|
Requires-Dist: pydantic>=2.11.7
|
52
|
+
Requires-Dist: pyyaml>=6.0.2
|
51
53
|
Provides-Extra: dev
|
52
54
|
Requires-Dist: mypy; extra == 'dev'
|
53
55
|
Requires-Dist: pytest; extra == 'dev'
|
@@ -201,7 +203,72 @@ or
|
|
201
203
|
Flushed 120 records from all models and reset IDs.
|
202
204
|
```
|
203
205
|
|
204
|
-
### 3.
|
206
|
+
### 3. EnvBaseSettings
|
207
|
+
|
208
|
+
```python
|
209
|
+
from djresttoolkit.envconfig import EnvBaseSettings
|
210
|
+
```
|
211
|
+
|
212
|
+
#### `EnvBaseSettings`
|
213
|
+
|
214
|
+
A **base settings class** for managing application configuration using:
|
215
|
+
|
216
|
+
- YAML files (default `.environ.yaml`)
|
217
|
+
- Environment variables (default `.env`)
|
218
|
+
|
219
|
+
Supports **nested configuration** using double underscores (`__`) in environment variable names.
|
220
|
+
|
221
|
+
#### Class Attributes
|
222
|
+
|
223
|
+
| Attribute | Type | Default | Description |
|
224
|
+
| -------------- | -------------------- | --------------- | ------------------------------------------------------------------ |
|
225
|
+
| `env_file` | `str` | `.env` | Environment variable file path. |
|
226
|
+
| `yaml_file` | `str` | `.environ.yaml` | YAML configuration file path. |
|
227
|
+
| `model_config` | `SettingsConfigDict` | — | Pydantic settings configuration (file encoding, nested delimiter). |
|
228
|
+
|
229
|
+
#### Methods
|
230
|
+
|
231
|
+
#### `load(cls, *, env_file: str | None = None, ymal_file: str | None = None, warning: bool = True) -> EnvBaseSettings`
|
232
|
+
|
233
|
+
Loads configuration from **YAML first**, then overrides with **environment variables**.
|
234
|
+
|
235
|
+
#### Parameters
|
236
|
+
|
237
|
+
- `env_file` — Optional custom `.env` file path.
|
238
|
+
- `ymal_file` — Optional custom YAML file path.
|
239
|
+
- `warning` — Emit a warning if YAML file is missing (default `True`).
|
240
|
+
|
241
|
+
#### Returns
|
242
|
+
|
243
|
+
- Instance of `EnvBaseSettings` (or subclass) with loaded configuration.
|
244
|
+
|
245
|
+
#### Raises
|
246
|
+
|
247
|
+
- `UserWarning` if YAML file not found and `warning=True`.
|
248
|
+
|
249
|
+
### Usage Example
|
250
|
+
|
251
|
+
```python
|
252
|
+
from djresttoolkit.envconfig import EnvBaseSettings
|
253
|
+
|
254
|
+
class EnvSettings(EnvBaseSettings):
|
255
|
+
debug: bool = False
|
256
|
+
database_url: str
|
257
|
+
|
258
|
+
# Load settings
|
259
|
+
settings = EnvSettings.load(warning=False)
|
260
|
+
|
261
|
+
print(settings.debug)
|
262
|
+
print(settings.database_url)
|
263
|
+
```
|
264
|
+
|
265
|
+
#### Features
|
266
|
+
|
267
|
+
- Prioritizes `.env` variables over YAML.
|
268
|
+
- Supports nested keys: `DATABASE__HOST` → `settings.database.host`.
|
269
|
+
- Designed to be subclassed for project-specific settings.
|
270
|
+
|
271
|
+
### 4. EmailSender
|
205
272
|
|
206
273
|
```python
|
207
274
|
from djresttoolkit.mail import EmailSender, EmailContent, EmailTemplate
|
@@ -217,7 +284,7 @@ Send templated emails.
|
|
217
284
|
EmailSender(email_content: EmailContent | EmailContentDict)
|
218
285
|
```
|
219
286
|
|
220
|
-
#### Methods
|
287
|
+
#### EmailSender Methods
|
221
288
|
|
222
289
|
```python
|
223
290
|
send(to: list[str], exceptions: bool = False) -> bool
|
@@ -250,7 +317,7 @@ EmailSender(content).send(to=["user@example.com"])
|
|
250
317
|
|
251
318
|
- `text`, `html` — template file paths
|
252
319
|
|
253
|
-
###
|
320
|
+
### 5. Custom DRF Exception Handler
|
254
321
|
|
255
322
|
```python
|
256
323
|
from djresttoolkit.views import exception_handler
|
@@ -264,12 +331,12 @@ A DRF exception handler that:
|
|
264
331
|
- Adds throttling support (defaults to `AnonRateThrottle`).
|
265
332
|
- Returns **429 Too Many Requests** with `retry_after` if throttle limit is exceeded.
|
266
333
|
|
267
|
-
#### Parameters
|
334
|
+
#### Exception Handler Parameters
|
268
335
|
|
269
336
|
- `exc`: Exception object.
|
270
337
|
- `context`: DRF context dictionary containing `"request"` and `"view"`.
|
271
338
|
|
272
|
-
#### Returns
|
339
|
+
#### Returns Type of Exception Handler
|
273
340
|
|
274
341
|
- `Response` — DRF Response object (with throttling info if applicable), or `None`.
|
275
342
|
|
@@ -290,7 +357,7 @@ REST_FRAMEWORK = {
|
|
290
357
|
- Tracks requests in cache and calculates `retry_after`.
|
291
358
|
- Cleans expired timestamps automatically.
|
292
359
|
|
293
|
-
###
|
360
|
+
### 6. Response Time Middleware
|
294
361
|
|
295
362
|
```python
|
296
363
|
from djresttoolkit.middlewares import ResponseTimeMiddleware
|
@@ -337,7 +404,7 @@ X-Response-Time: 0.01234 seconds
|
|
337
404
|
INFO: Request processed in 0.01234 seconds
|
338
405
|
```
|
339
406
|
|
340
|
-
###
|
407
|
+
### 7. Throttle Utilities
|
341
408
|
|
342
409
|
#### `ThrottleInfoJSONRenderer`
|
343
410
|
|
@@ -145,7 +145,72 @@ or
|
|
145
145
|
Flushed 120 records from all models and reset IDs.
|
146
146
|
```
|
147
147
|
|
148
|
-
### 3.
|
148
|
+
### 3. EnvBaseSettings
|
149
|
+
|
150
|
+
```python
|
151
|
+
from djresttoolkit.envconfig import EnvBaseSettings
|
152
|
+
```
|
153
|
+
|
154
|
+
#### `EnvBaseSettings`
|
155
|
+
|
156
|
+
A **base settings class** for managing application configuration using:
|
157
|
+
|
158
|
+
- YAML files (default `.environ.yaml`)
|
159
|
+
- Environment variables (default `.env`)
|
160
|
+
|
161
|
+
Supports **nested configuration** using double underscores (`__`) in environment variable names.
|
162
|
+
|
163
|
+
#### Class Attributes
|
164
|
+
|
165
|
+
| Attribute | Type | Default | Description |
|
166
|
+
| -------------- | -------------------- | --------------- | ------------------------------------------------------------------ |
|
167
|
+
| `env_file` | `str` | `.env` | Environment variable file path. |
|
168
|
+
| `yaml_file` | `str` | `.environ.yaml` | YAML configuration file path. |
|
169
|
+
| `model_config` | `SettingsConfigDict` | — | Pydantic settings configuration (file encoding, nested delimiter). |
|
170
|
+
|
171
|
+
#### Methods
|
172
|
+
|
173
|
+
#### `load(cls, *, env_file: str | None = None, ymal_file: str | None = None, warning: bool = True) -> EnvBaseSettings`
|
174
|
+
|
175
|
+
Loads configuration from **YAML first**, then overrides with **environment variables**.
|
176
|
+
|
177
|
+
#### Parameters
|
178
|
+
|
179
|
+
- `env_file` — Optional custom `.env` file path.
|
180
|
+
- `ymal_file` — Optional custom YAML file path.
|
181
|
+
- `warning` — Emit a warning if YAML file is missing (default `True`).
|
182
|
+
|
183
|
+
#### Returns
|
184
|
+
|
185
|
+
- Instance of `EnvBaseSettings` (or subclass) with loaded configuration.
|
186
|
+
|
187
|
+
#### Raises
|
188
|
+
|
189
|
+
- `UserWarning` if YAML file not found and `warning=True`.
|
190
|
+
|
191
|
+
### Usage Example
|
192
|
+
|
193
|
+
```python
|
194
|
+
from djresttoolkit.envconfig import EnvBaseSettings
|
195
|
+
|
196
|
+
class EnvSettings(EnvBaseSettings):
|
197
|
+
debug: bool = False
|
198
|
+
database_url: str
|
199
|
+
|
200
|
+
# Load settings
|
201
|
+
settings = EnvSettings.load(warning=False)
|
202
|
+
|
203
|
+
print(settings.debug)
|
204
|
+
print(settings.database_url)
|
205
|
+
```
|
206
|
+
|
207
|
+
#### Features
|
208
|
+
|
209
|
+
- Prioritizes `.env` variables over YAML.
|
210
|
+
- Supports nested keys: `DATABASE__HOST` → `settings.database.host`.
|
211
|
+
- Designed to be subclassed for project-specific settings.
|
212
|
+
|
213
|
+
### 4. EmailSender
|
149
214
|
|
150
215
|
```python
|
151
216
|
from djresttoolkit.mail import EmailSender, EmailContent, EmailTemplate
|
@@ -161,7 +226,7 @@ Send templated emails.
|
|
161
226
|
EmailSender(email_content: EmailContent | EmailContentDict)
|
162
227
|
```
|
163
228
|
|
164
|
-
#### Methods
|
229
|
+
#### EmailSender Methods
|
165
230
|
|
166
231
|
```python
|
167
232
|
send(to: list[str], exceptions: bool = False) -> bool
|
@@ -194,7 +259,7 @@ EmailSender(content).send(to=["user@example.com"])
|
|
194
259
|
|
195
260
|
- `text`, `html` — template file paths
|
196
261
|
|
197
|
-
###
|
262
|
+
### 5. Custom DRF Exception Handler
|
198
263
|
|
199
264
|
```python
|
200
265
|
from djresttoolkit.views import exception_handler
|
@@ -208,12 +273,12 @@ A DRF exception handler that:
|
|
208
273
|
- Adds throttling support (defaults to `AnonRateThrottle`).
|
209
274
|
- Returns **429 Too Many Requests** with `retry_after` if throttle limit is exceeded.
|
210
275
|
|
211
|
-
#### Parameters
|
276
|
+
#### Exception Handler Parameters
|
212
277
|
|
213
278
|
- `exc`: Exception object.
|
214
279
|
- `context`: DRF context dictionary containing `"request"` and `"view"`.
|
215
280
|
|
216
|
-
#### Returns
|
281
|
+
#### Returns Type of Exception Handler
|
217
282
|
|
218
283
|
- `Response` — DRF Response object (with throttling info if applicable), or `None`.
|
219
284
|
|
@@ -234,7 +299,7 @@ REST_FRAMEWORK = {
|
|
234
299
|
- Tracks requests in cache and calculates `retry_after`.
|
235
300
|
- Cleans expired timestamps automatically.
|
236
301
|
|
237
|
-
###
|
302
|
+
### 6. Response Time Middleware
|
238
303
|
|
239
304
|
```python
|
240
305
|
from djresttoolkit.middlewares import ResponseTimeMiddleware
|
@@ -281,7 +346,7 @@ X-Response-Time: 0.01234 seconds
|
|
281
346
|
INFO: Request processed in 0.01234 seconds
|
282
347
|
```
|
283
348
|
|
284
|
-
###
|
349
|
+
### 7. Throttle Utilities
|
285
350
|
|
286
351
|
#### `ThrottleInfoJSONRenderer`
|
287
352
|
|
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
[project]
|
6
6
|
name = "djresttoolkit"
|
7
|
-
version = "0.
|
7
|
+
version = "0.8.0"
|
8
8
|
description = "A collection of Django and DRF utilities to simplify API development."
|
9
9
|
readme = { file = "README.md", content-type = "text/markdown" }
|
10
10
|
license = { file = "LICENSE" }
|
@@ -48,6 +48,8 @@ requires-python = ">=3.13"
|
|
48
48
|
dependencies = [
|
49
49
|
"faker>=37.5.3",
|
50
50
|
"pydantic>=2.11.7",
|
51
|
+
"pydantic-settings>=2.10.1",
|
52
|
+
"pyyaml>=6.0.2",
|
51
53
|
]
|
52
54
|
|
53
55
|
# CLI scripts entry point configuration
|
@@ -0,0 +1,84 @@
|
|
1
|
+
import warnings
|
2
|
+
from pathlib import Path
|
3
|
+
from typing import Any, ClassVar
|
4
|
+
|
5
|
+
import yaml
|
6
|
+
from pydantic_settings import BaseSettings, SettingsConfigDict
|
7
|
+
|
8
|
+
|
9
|
+
class EnvBaseSettings(BaseSettings):
|
10
|
+
""" "
|
11
|
+
EnvBaseSettings is a base settings class for managing application configuration
|
12
|
+
using both YAML files and environment variables.
|
13
|
+
This class is designed to load configuration values from a YAML file first,
|
14
|
+
and then override those values with environment variables if present. It supports
|
15
|
+
nested configuration using a double underscore (`__`) as the delimiter in
|
16
|
+
environment variable names, allowing for hierarchical settings.
|
17
|
+
|
18
|
+
Class Attributes:
|
19
|
+
env_file (str): The default filename for the environment variables file (default: ".env").
|
20
|
+
yaml_file (str): The default filename for the YAML configuration file (default: ".environ.yaml").
|
21
|
+
model_config (SettingsConfigDict): Configuration for environment variable parsing, including file encoding and nested delimiter.
|
22
|
+
|
23
|
+
Methods:
|
24
|
+
load(cls, *, env_file: str | None = None, ymal_file: str | None = None, warning: bool = True) -> "EnvBaseSettings":
|
25
|
+
Loads configuration from a YAML file (if it exists), then overrides with environment variables.
|
26
|
+
- env_file: Optional custom path to the .env file.
|
27
|
+
- ymal_file: Optional custom path to the YAML file.
|
28
|
+
- warning: If True, emits a warning if the YAML file is not found.
|
29
|
+
Returns an instance of EnvBaseSettings with the loaded configuration.
|
30
|
+
|
31
|
+
Usage:
|
32
|
+
- Define your settings as subclasses of EnvBaseSettings.
|
33
|
+
- Call `YourSettingsClass.load()` to load configuration from files and environment variables.
|
34
|
+
- Supports nested configuration via double underscore in environment variable names (e.g., `DATABASE__HOST`).
|
35
|
+
|
36
|
+
Raises:
|
37
|
+
- UserWarning: If the YAML file is not found and `warning` is True.
|
38
|
+
|
39
|
+
Example:
|
40
|
+
```python
|
41
|
+
from djresttoolkit.envconfig import EnvBaseSettings
|
42
|
+
|
43
|
+
class EnvSettings(EnvBaseSettings):
|
44
|
+
debug: bool = False
|
45
|
+
database_url: str
|
46
|
+
|
47
|
+
settings = EnvSettings.load(warning=False)
|
48
|
+
```
|
49
|
+
|
50
|
+
"""
|
51
|
+
|
52
|
+
env_file: ClassVar[str] = ".env"
|
53
|
+
yaml_file: ClassVar[str] = ".environ.yaml"
|
54
|
+
|
55
|
+
model_config = SettingsConfigDict(
|
56
|
+
env_file=env_file,
|
57
|
+
env_file_encoding="utf-8",
|
58
|
+
env_nested_delimiter="__",
|
59
|
+
)
|
60
|
+
|
61
|
+
@classmethod
|
62
|
+
def load(
|
63
|
+
cls,
|
64
|
+
*,
|
65
|
+
env_file: str | None = None,
|
66
|
+
ymal_file: str | None = None,
|
67
|
+
warning: bool = True,
|
68
|
+
) -> "EnvBaseSettings":
|
69
|
+
"""Load from YAML first, then override with .env."""
|
70
|
+
if env_file:
|
71
|
+
cls.env_file = env_file
|
72
|
+
if ymal_file:
|
73
|
+
cls.yaml_file = ymal_file
|
74
|
+
|
75
|
+
config_file = Path(cls.yaml_file)
|
76
|
+
yaml_data: dict[str, Any] = {}
|
77
|
+
if config_file.exists():
|
78
|
+
with config_file.open("r") as f:
|
79
|
+
yaml_data = yaml.safe_load(f) or {}
|
80
|
+
elif warning:
|
81
|
+
msg: str = f"Config file {config_file} not found, using only env vars."
|
82
|
+
warnings.warn(msg, UserWarning, stacklevel=1)
|
83
|
+
|
84
|
+
return cls(**yaml_data)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{djresttoolkit-0.7.0 → djresttoolkit-0.8.0}/src/djresttoolkit/dbseed/models/_choice_field.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{djresttoolkit-0.7.0 → djresttoolkit-0.8.0}/src/djresttoolkit/management/commands/__init__.py
RENAMED
File without changes
|
{djresttoolkit-0.7.0 → djresttoolkit-0.8.0}/src/djresttoolkit/management/commands/dbflush.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{djresttoolkit-0.7.0 → djresttoolkit-0.8.0}/src/djresttoolkit/throttling/_throttle_inspector.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|