fastapi-mongo-base 1.4.0__tar.gz → 1.4.2__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.
- {fastapi_mongo_base-1.4.0/src/fastapi_mongo_base.egg-info → fastapi_mongo_base-1.4.2}/PKG-INFO +1 -1
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/pyproject.toml +1 -1
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/src/fastapi_mongo_base/core/prometheus/mongo.py +75 -5
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/src/fastapi_mongo_base/utils/basic.py +41 -12
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2/src/fastapi_mongo_base.egg-info}/PKG-INFO +1 -1
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/LICENSE.txt +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/MANIFEST.in +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/README.md +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/docs/boilerplate.md +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/docs/changelog.md +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/docs/contributing.md +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/docs/endpoints.md +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/docs/extra.css +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/docs/index.md +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/docs/installation.md +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/docs/license.md +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/docs/quickstart.md +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/docs/settings.md +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/docs/tutorial.md +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/docs/usage.md +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/mkdocs.yml +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/pytest.ini +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/setup.cfg +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/src/fastapi_mongo_base/__init__.py +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/src/fastapi_mongo_base/core/__init__.py +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/src/fastapi_mongo_base/core/app_factory.py +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/src/fastapi_mongo_base/core/config.py +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/src/fastapi_mongo_base/core/db.py +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/src/fastapi_mongo_base/core/enums.py +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/src/fastapi_mongo_base/core/error_responses.py +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/src/fastapi_mongo_base/core/errors/mongodb_errors.py +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/src/fastapi_mongo_base/core/errors/resource_errors.py +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/src/fastapi_mongo_base/core/exceptions.py +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/src/fastapi_mongo_base/core/middlewares/prometheus.py +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/src/fastapi_mongo_base/core/sentry.py +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/src/fastapi_mongo_base/models.py +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/src/fastapi_mongo_base/py.typed +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/src/fastapi_mongo_base/routes.py +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/src/fastapi_mongo_base/schemas.py +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/src/fastapi_mongo_base/sql.py +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/src/fastapi_mongo_base/tasks.py +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/src/fastapi_mongo_base/utils/__init__.py +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/src/fastapi_mongo_base/utils/bsontools.py +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/src/fastapi_mongo_base/utils/timezone.py +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/src/fastapi_mongo_base/utils/usso_routes.py +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/src/fastapi_mongo_base.egg-info/SOURCES.txt +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/src/fastapi_mongo_base.egg-info/dependency_links.txt +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/src/fastapi_mongo_base.egg-info/requires.txt +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/src/fastapi_mongo_base.egg-info/top_level.txt +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/tests/__init__.py +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/tests/app/__init__.py +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/tests/app/logs/app.log +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/tests/app/main.py +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/tests/app/server.py +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/tests/conftest.py +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/tests/test_apis.py +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/tests/test_app.py +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/tests/test_db.py +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/tests/test_mongodb_errors.py +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/tests/test_openapi_errors.py +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/tests/test_resource_errors.py +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/tests/test_sentry.py +0 -0
- {fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/tests/test_usso_routes_workspace.py +0 -0
{fastapi_mongo_base-1.4.0/src/fastapi_mongo_base.egg-info → fastapi_mongo_base-1.4.2}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: fastapi-mongo-base
|
|
3
|
-
Version: 1.4.
|
|
3
|
+
Version: 1.4.2
|
|
4
4
|
Summary: A simple boilerplate application, including models and schemas and abstract router, for FastAPI with MongoDB
|
|
5
5
|
Author-email: Mahdi Kiani <mahdikiany@gmail.com>
|
|
6
6
|
Maintainer-email: Mahdi Kiani <mahdikiany@gmail.com>
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "fastapi-mongo-base"
|
|
7
|
-
version = "1.4.
|
|
7
|
+
version = "1.4.2"
|
|
8
8
|
description = "A simple boilerplate application, including models and schemas and abstract router, for FastAPI with MongoDB"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
@@ -21,15 +21,36 @@ try:
|
|
|
21
21
|
["database"],
|
|
22
22
|
)
|
|
23
23
|
|
|
24
|
+
connections_ready_total = Counter(
|
|
25
|
+
"mongodb_pool_connections_ready_total",
|
|
26
|
+
"Total MongoDB connections ready for checkout",
|
|
27
|
+
["database"],
|
|
28
|
+
)
|
|
29
|
+
|
|
24
30
|
connections_closed_total = Counter(
|
|
25
31
|
"mongodb_pool_connections_closed_total",
|
|
26
32
|
"Total MongoDB connections closed",
|
|
27
33
|
["database"],
|
|
28
34
|
)
|
|
35
|
+
|
|
36
|
+
checkouts_started_total = Counter(
|
|
37
|
+
"mongodb_pool_checkouts_started_total",
|
|
38
|
+
"Total MongoDB connection checkout attempts",
|
|
39
|
+
["database"],
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
checkouts_failed_total = Counter(
|
|
43
|
+
"mongodb_pool_checkouts_failed_total",
|
|
44
|
+
"Total MongoDB connection checkout failures",
|
|
45
|
+
["database", "reason"],
|
|
46
|
+
)
|
|
29
47
|
except ImportError:
|
|
30
48
|
pool_connections = None
|
|
31
49
|
connections_created_total = None
|
|
50
|
+
connections_ready_total = None
|
|
32
51
|
connections_closed_total = None
|
|
52
|
+
checkouts_started_total = None
|
|
53
|
+
checkouts_failed_total = None
|
|
33
54
|
|
|
34
55
|
|
|
35
56
|
class DatabasePoolMonitor(monitoring.ConnectionPoolListener):
|
|
@@ -54,6 +75,11 @@ class DatabasePoolMonitor(monitoring.ConnectionPoolListener):
|
|
|
54
75
|
state="in_use",
|
|
55
76
|
).set(self.in_use_connections)
|
|
56
77
|
|
|
78
|
+
def _reset_pool_metrics(self) -> None:
|
|
79
|
+
self.available_connections = 0
|
|
80
|
+
self.in_use_connections = 0
|
|
81
|
+
self._update_metrics()
|
|
82
|
+
|
|
57
83
|
def pool_created(self, event: monitoring.PoolCreatedEvent) -> None:
|
|
58
84
|
"""Handle MongoDB pool creation events."""
|
|
59
85
|
del event
|
|
@@ -66,10 +92,16 @@ class DatabasePoolMonitor(monitoring.ConnectionPoolListener):
|
|
|
66
92
|
"""Handle MongoDB pool clearing events."""
|
|
67
93
|
del event
|
|
68
94
|
|
|
95
|
+
with self._lock:
|
|
96
|
+
self._reset_pool_metrics()
|
|
97
|
+
|
|
69
98
|
def pool_closed(self, event: monitoring.PoolClosedEvent) -> None:
|
|
70
99
|
"""Handle MongoDB pool closure events."""
|
|
71
100
|
del event
|
|
72
101
|
|
|
102
|
+
with self._lock:
|
|
103
|
+
self._reset_pool_metrics()
|
|
104
|
+
|
|
73
105
|
def connection_created(
|
|
74
106
|
self,
|
|
75
107
|
event: monitoring.ConnectionCreatedEvent,
|
|
@@ -77,10 +109,22 @@ class DatabasePoolMonitor(monitoring.ConnectionPoolListener):
|
|
|
77
109
|
"""Record a MongoDB connection creation event."""
|
|
78
110
|
del event
|
|
79
111
|
|
|
112
|
+
with self._lock:
|
|
113
|
+
connections_created_total.labels(
|
|
114
|
+
database=self.database_name,
|
|
115
|
+
).inc()
|
|
116
|
+
|
|
117
|
+
def connection_ready(
|
|
118
|
+
self,
|
|
119
|
+
event: monitoring.ConnectionReadyEvent,
|
|
120
|
+
) -> None:
|
|
121
|
+
"""Record a MongoDB connection readiness event."""
|
|
122
|
+
del event
|
|
123
|
+
|
|
80
124
|
with self._lock:
|
|
81
125
|
self.available_connections += 1
|
|
82
126
|
|
|
83
|
-
|
|
127
|
+
connections_ready_total.labels(
|
|
84
128
|
database=self.database_name,
|
|
85
129
|
).inc()
|
|
86
130
|
|
|
@@ -94,10 +138,13 @@ class DatabasePoolMonitor(monitoring.ConnectionPoolListener):
|
|
|
94
138
|
del event
|
|
95
139
|
|
|
96
140
|
with self._lock:
|
|
97
|
-
self.
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
141
|
+
if self.in_use_connections > 0:
|
|
142
|
+
self.in_use_connections -= 1
|
|
143
|
+
else:
|
|
144
|
+
self.available_connections = max(
|
|
145
|
+
0,
|
|
146
|
+
self.available_connections - 1,
|
|
147
|
+
)
|
|
101
148
|
|
|
102
149
|
connections_closed_total.labels(
|
|
103
150
|
database=self.database_name,
|
|
@@ -105,6 +152,29 @@ class DatabasePoolMonitor(monitoring.ConnectionPoolListener):
|
|
|
105
152
|
|
|
106
153
|
self._update_metrics()
|
|
107
154
|
|
|
155
|
+
def connection_check_out_started(
|
|
156
|
+
self,
|
|
157
|
+
event: monitoring.ConnectionCheckOutStartedEvent,
|
|
158
|
+
) -> None:
|
|
159
|
+
"""Record the start of a MongoDB connection checkout attempt."""
|
|
160
|
+
del event
|
|
161
|
+
|
|
162
|
+
with self._lock:
|
|
163
|
+
checkouts_started_total.labels(
|
|
164
|
+
database=self.database_name,
|
|
165
|
+
).inc()
|
|
166
|
+
|
|
167
|
+
def connection_check_out_failed(
|
|
168
|
+
self,
|
|
169
|
+
event: monitoring.ConnectionCheckOutFailedEvent,
|
|
170
|
+
) -> None:
|
|
171
|
+
"""Record a failed MongoDB connection checkout attempt."""
|
|
172
|
+
with self._lock:
|
|
173
|
+
checkouts_failed_total.labels(
|
|
174
|
+
database=self.database_name,
|
|
175
|
+
reason=event.reason,
|
|
176
|
+
).inc()
|
|
177
|
+
|
|
108
178
|
def connection_checked_out(
|
|
109
179
|
self,
|
|
110
180
|
event: monitoring.ConnectionCheckedOutEvent,
|
|
@@ -328,9 +328,21 @@ async def gather_sync(
|
|
|
328
328
|
R = TypeVar("R")
|
|
329
329
|
|
|
330
330
|
|
|
331
|
+
def _resolve_mock(
|
|
332
|
+
mock_response: R | Callable[..., R | Awaitable[R]],
|
|
333
|
+
*args: object,
|
|
334
|
+
**kwargs: object,
|
|
335
|
+
) -> R | Awaitable[R]:
|
|
336
|
+
if callable(mock_response):
|
|
337
|
+
return mock_response(*args, **kwargs)
|
|
338
|
+
return mock_response
|
|
339
|
+
|
|
340
|
+
|
|
331
341
|
def debug_mode_mock(
|
|
332
342
|
mock_response: R | Callable[..., R | Awaitable[R]],
|
|
333
|
-
) -> Callable[
|
|
343
|
+
) -> Callable[
|
|
344
|
+
[Callable[..., R | Awaitable[R]]], Callable[..., R | Awaitable[R]]
|
|
345
|
+
]:
|
|
334
346
|
"""
|
|
335
347
|
Return a mock response if debug is enabled.
|
|
336
348
|
|
|
@@ -340,22 +352,39 @@ def debug_mode_mock(
|
|
|
340
352
|
Returns:
|
|
341
353
|
A decorator that returns a mock response if debug is enabled.
|
|
342
354
|
"""
|
|
343
|
-
from ..core.config import Settings
|
|
344
355
|
|
|
345
356
|
def decorator(
|
|
346
|
-
func: Callable[..., Awaitable[R]],
|
|
347
|
-
) -> Callable[..., Awaitable[R]]:
|
|
357
|
+
func: Callable[..., R | Awaitable[R]],
|
|
358
|
+
) -> Callable[..., R | Awaitable[R]]:
|
|
359
|
+
|
|
360
|
+
from ..core.config import Settings
|
|
361
|
+
|
|
348
362
|
@functools.wraps(func)
|
|
349
|
-
async def
|
|
363
|
+
async def async_wrapper(*args: object, **kwargs: object) -> R:
|
|
350
364
|
if Settings.debug:
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
return result
|
|
356
|
-
return mock_response
|
|
365
|
+
result = _resolve_mock(mock_response, *args, **kwargs)
|
|
366
|
+
if isinstance(result, Awaitable):
|
|
367
|
+
return await result
|
|
368
|
+
return result
|
|
357
369
|
return await func(*args, **kwargs)
|
|
358
370
|
|
|
359
|
-
|
|
371
|
+
@functools.wraps(func)
|
|
372
|
+
def sync_wrapper(*args: object, **kwargs: object) -> R:
|
|
373
|
+
if Settings.debug:
|
|
374
|
+
result = _resolve_mock(mock_response, *args, **kwargs)
|
|
375
|
+
if isinstance(result, Awaitable):
|
|
376
|
+
msg = (
|
|
377
|
+
"debug_mode_mock callable returned "
|
|
378
|
+
"Awaitable for sync function"
|
|
379
|
+
)
|
|
380
|
+
raise TypeError(msg)
|
|
381
|
+
return result
|
|
382
|
+
return func(*args, **kwargs)
|
|
383
|
+
|
|
384
|
+
return (
|
|
385
|
+
async_wrapper
|
|
386
|
+
if inspect.iscoroutinefunction(func)
|
|
387
|
+
else sync_wrapper
|
|
388
|
+
)
|
|
360
389
|
|
|
361
390
|
return decorator
|
{fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2/src/fastapi_mongo_base.egg-info}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: fastapi-mongo-base
|
|
3
|
-
Version: 1.4.
|
|
3
|
+
Version: 1.4.2
|
|
4
4
|
Summary: A simple boilerplate application, including models and schemas and abstract router, for FastAPI with MongoDB
|
|
5
5
|
Author-email: Mahdi Kiani <mahdikiany@gmail.com>
|
|
6
6
|
Maintainer-email: Mahdi Kiani <mahdikiany@gmail.com>
|
|
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
|
|
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
|
{fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/src/fastapi_mongo_base/core/__init__.py
RENAMED
|
File without changes
|
{fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/src/fastapi_mongo_base/core/app_factory.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/src/fastapi_mongo_base/core/error_responses.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/src/fastapi_mongo_base/core/exceptions.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
|
{fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/src/fastapi_mongo_base/utils/__init__.py
RENAMED
|
File without changes
|
{fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/src/fastapi_mongo_base/utils/bsontools.py
RENAMED
|
File without changes
|
{fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/src/fastapi_mongo_base/utils/timezone.py
RENAMED
|
File without changes
|
{fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/src/fastapi_mongo_base/utils/usso_routes.py
RENAMED
|
File without changes
|
{fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/src/fastapi_mongo_base.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/src/fastapi_mongo_base.egg-info/requires.txt
RENAMED
|
File without changes
|
{fastapi_mongo_base-1.4.0 → fastapi_mongo_base-1.4.2}/src/fastapi_mongo_base.egg-info/top_level.txt
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|