fastapi-commons 0.4.0__tar.gz → 0.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_commons-0.4.0/src/fastapi_commons.egg-info → fastapi_commons-0.4.2}/PKG-INFO +2 -2
- {fastapi_commons-0.4.0 → fastapi_commons-0.4.2}/pyproject.toml +1 -1
- {fastapi_commons-0.4.0 → fastapi_commons-0.4.2}/src/fastapi_commons/__init__.py +1 -1
- fastapi_commons-0.4.2/src/fastapi_commons/helpers.py +10 -0
- fastapi_commons-0.4.2/src/fastapi_commons/middleware/correlation_id.py +18 -0
- fastapi_commons-0.4.2/src/fastapi_commons/middleware/log_context.py +19 -0
- {fastapi_commons-0.4.0 → fastapi_commons-0.4.2/src/fastapi_commons.egg-info}/PKG-INFO +2 -2
- {fastapi_commons-0.4.0 → fastapi_commons-0.4.2}/src/fastapi_commons.egg-info/SOURCES.txt +5 -1
- {fastapi_commons-0.4.0 → fastapi_commons-0.4.2}/src/fastapi_commons.egg-info/requires.txt +1 -1
- fastapi_commons-0.4.2/tests/unit/__init__.py +0 -0
- {fastapi_commons-0.4.0 → fastapi_commons-0.4.2}/uv.lock +6 -7
- {fastapi_commons-0.4.0 → fastapi_commons-0.4.2}/.coveragerc +0 -0
- {fastapi_commons-0.4.0 → fastapi_commons-0.4.2}/.env_template +0 -0
- {fastapi_commons-0.4.0 → fastapi_commons-0.4.2}/.github/workflows/checks.yml +0 -0
- {fastapi_commons-0.4.0 → fastapi_commons-0.4.2}/.github/workflows/python-publish.yaml +0 -0
- {fastapi_commons-0.4.0 → fastapi_commons-0.4.2}/.github/workflows/release-on-tag-push.yml +0 -0
- {fastapi_commons-0.4.0 → fastapi_commons-0.4.2}/.gitignore +0 -0
- {fastapi_commons-0.4.0 → fastapi_commons-0.4.2}/.pre-commit-config.yaml +0 -0
- {fastapi_commons-0.4.0 → fastapi_commons-0.4.2}/.python-version +0 -0
- {fastapi_commons-0.4.0 → fastapi_commons-0.4.2}/AUTHORS.rst +0 -0
- {fastapi_commons-0.4.0 → fastapi_commons-0.4.2}/CHANGELOG.rst +0 -0
- {fastapi_commons-0.4.0 → fastapi_commons-0.4.2}/LICENSE +0 -0
- {fastapi_commons-0.4.0 → fastapi_commons-0.4.2}/README.md +0 -0
- {fastapi_commons-0.4.0 → fastapi_commons-0.4.2}/README.rst +0 -0
- {fastapi_commons-0.4.0 → fastapi_commons-0.4.2}/setup.cfg +0 -0
- {fastapi_commons-0.4.0 → fastapi_commons-0.4.2}/src/fastapi_commons/auth.py +0 -0
- {fastapi_commons-0.4.0 → fastapi_commons-0.4.2}/src/fastapi_commons/conf.py +0 -0
- {fastapi_commons-0.4.0 → fastapi_commons-0.4.2}/src/fastapi_commons/handlers.py +0 -0
- {fastapi_commons-0.4.0 → fastapi_commons-0.4.2}/src/fastapi_commons/instrumentation.py +0 -0
- {fastapi_commons-0.4.0/tests → fastapi_commons-0.4.2/src/fastapi_commons/middleware}/__init__.py +0 -0
- /fastapi_commons-0.4.0/src/fastapi_commons/middleware.py → /fastapi_commons-0.4.2/src/fastapi_commons/middleware/prometheus.py +0 -0
- {fastapi_commons-0.4.0 → fastapi_commons-0.4.2}/src/fastapi_commons.egg-info/dependency_links.txt +0 -0
- {fastapi_commons-0.4.0 → fastapi_commons-0.4.2}/src/fastapi_commons.egg-info/top_level.txt +0 -0
- {fastapi_commons-0.4.0/tests/unit → fastapi_commons-0.4.2/tests}/__init__.py +0 -0
- {fastapi_commons-0.4.0 → fastapi_commons-0.4.2}/tests/conftest.py +0 -0
- {fastapi_commons-0.4.0 → fastapi_commons-0.4.2}/tests/unit/test_poc.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: fastapi-commons
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.2
|
|
4
4
|
Summary: Re-usable FastAPI code
|
|
5
5
|
Author-email: Oleg Korsak <kamikaze.is.waiting.you@gmail.com>
|
|
6
6
|
License-Expression: GPL-3.0
|
|
@@ -26,7 +26,7 @@ Requires-Dist: opentelemetry-exporter-otlp~=1.41.0
|
|
|
26
26
|
Requires-Dist: opentelemetry-instrumentation-fastapi~=0.60b1
|
|
27
27
|
Requires-Dist: opentelemetry-instrumentation-logging~=0.60b1
|
|
28
28
|
Requires-Dist: prometheus-client~=0.25.0
|
|
29
|
-
Requires-Dist: python3-commons~=0.16.
|
|
29
|
+
Requires-Dist: python3-commons~=0.16.4
|
|
30
30
|
Dynamic: license-file
|
|
31
31
|
|
|
32
32
|
FastAPI commons
|
|
@@ -2,7 +2,7 @@ import importlib.metadata
|
|
|
2
2
|
import logging
|
|
3
3
|
|
|
4
4
|
from fastapi_commons.instrumentation import setup_opentelemetry
|
|
5
|
-
from fastapi_commons.middleware import PrometheusMiddleware, metrics
|
|
5
|
+
from fastapi_commons.middleware.prometheus import PrometheusMiddleware, metrics
|
|
6
6
|
|
|
7
7
|
try:
|
|
8
8
|
dist_name = __name__
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
from typing import Annotated
|
|
2
|
+
|
|
3
|
+
from fastapi import Header, Request
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def get_client_ip(request: Request, x_forwarded_for: Annotated[str | None, Header()] = None) -> str | None:
|
|
7
|
+
if x_forwarded_for:
|
|
8
|
+
return x_forwarded_for
|
|
9
|
+
|
|
10
|
+
return client.host if (client := request.client) else None
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import contextvars
|
|
2
|
+
from uuid import uuid4
|
|
3
|
+
|
|
4
|
+
from fastapi import Request, Response
|
|
5
|
+
from starlette.middleware.base import BaseHTTPMiddleware, RequestResponseEndpoint
|
|
6
|
+
|
|
7
|
+
correlation_id_ctx: contextvars.ContextVar[str] = contextvars.ContextVar('correlation_id')
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class CorrelationIDMiddleware(BaseHTTPMiddleware):
|
|
11
|
+
async def dispatch(self, request: Request, call_next: RequestResponseEndpoint) -> Response:
|
|
12
|
+
correlation_id = request.headers.get('X-Correlation-ID', str(uuid4()))
|
|
13
|
+
correlation_id_ctx.set(correlation_id)
|
|
14
|
+
|
|
15
|
+
response = await call_next(request)
|
|
16
|
+
response.headers['X-Correlation-ID'] = correlation_id
|
|
17
|
+
|
|
18
|
+
return response
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import contextvars
|
|
2
|
+
|
|
3
|
+
from fastapi import Request, Response
|
|
4
|
+
from starlette.middleware.base import BaseHTTPMiddleware, RequestResponseEndpoint
|
|
5
|
+
|
|
6
|
+
from fastapi_commons.helpers import get_client_ip
|
|
7
|
+
|
|
8
|
+
log_context: contextvars.ContextVar[dict | None] = contextvars.ContextVar('log_context', default=None)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class LogContextMiddleware(BaseHTTPMiddleware):
|
|
12
|
+
async def dispatch(self, request: Request, call_next: RequestResponseEndpoint) -> Response:
|
|
13
|
+
context = {
|
|
14
|
+
'client_ip': get_client_ip(request),
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
log_context.set(context)
|
|
18
|
+
|
|
19
|
+
return await call_next(request)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: fastapi-commons
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.2
|
|
4
4
|
Summary: Re-usable FastAPI code
|
|
5
5
|
Author-email: Oleg Korsak <kamikaze.is.waiting.you@gmail.com>
|
|
6
6
|
License-Expression: GPL-3.0
|
|
@@ -26,7 +26,7 @@ Requires-Dist: opentelemetry-exporter-otlp~=1.41.0
|
|
|
26
26
|
Requires-Dist: opentelemetry-instrumentation-fastapi~=0.60b1
|
|
27
27
|
Requires-Dist: opentelemetry-instrumentation-logging~=0.60b1
|
|
28
28
|
Requires-Dist: prometheus-client~=0.25.0
|
|
29
|
-
Requires-Dist: python3-commons~=0.16.
|
|
29
|
+
Requires-Dist: python3-commons~=0.16.4
|
|
30
30
|
Dynamic: license-file
|
|
31
31
|
|
|
32
32
|
FastAPI commons
|
|
@@ -17,13 +17,17 @@ src/fastapi_commons/__init__.py
|
|
|
17
17
|
src/fastapi_commons/auth.py
|
|
18
18
|
src/fastapi_commons/conf.py
|
|
19
19
|
src/fastapi_commons/handlers.py
|
|
20
|
+
src/fastapi_commons/helpers.py
|
|
20
21
|
src/fastapi_commons/instrumentation.py
|
|
21
|
-
src/fastapi_commons/middleware.py
|
|
22
22
|
src/fastapi_commons.egg-info/PKG-INFO
|
|
23
23
|
src/fastapi_commons.egg-info/SOURCES.txt
|
|
24
24
|
src/fastapi_commons.egg-info/dependency_links.txt
|
|
25
25
|
src/fastapi_commons.egg-info/requires.txt
|
|
26
26
|
src/fastapi_commons.egg-info/top_level.txt
|
|
27
|
+
src/fastapi_commons/middleware/__init__.py
|
|
28
|
+
src/fastapi_commons/middleware/correlation_id.py
|
|
29
|
+
src/fastapi_commons/middleware/log_context.py
|
|
30
|
+
src/fastapi_commons/middleware/prometheus.py
|
|
27
31
|
tests/__init__.py
|
|
28
32
|
tests/conftest.py
|
|
29
33
|
tests/unit/__init__.py
|
|
File without changes
|
|
@@ -511,7 +511,7 @@ requires-dist = [
|
|
|
511
511
|
{ name = "pydantic", extras = ["email"], specifier = "~=2.13.3" },
|
|
512
512
|
{ name = "pydantic-settings", specifier = "~=2.14.0" },
|
|
513
513
|
{ name = "python-jose", specifier = "~=3.5.0" },
|
|
514
|
-
{ name = "python3-commons", specifier = "~=0.16.
|
|
514
|
+
{ name = "python3-commons", specifier = "~=0.16.4" },
|
|
515
515
|
{ name = "sqlalchemy", extras = ["asyncio"], specifier = "~=2.0.49" },
|
|
516
516
|
]
|
|
517
517
|
|
|
@@ -1084,7 +1084,7 @@ wheels = [
|
|
|
1084
1084
|
|
|
1085
1085
|
[[package]]
|
|
1086
1086
|
name = "pre-commit"
|
|
1087
|
-
version = "4.
|
|
1087
|
+
version = "4.6.0"
|
|
1088
1088
|
source = { registry = "https://pypi.org/simple" }
|
|
1089
1089
|
dependencies = [
|
|
1090
1090
|
{ name = "cfgv" },
|
|
@@ -1093,9 +1093,9 @@ dependencies = [
|
|
|
1093
1093
|
{ name = "pyyaml" },
|
|
1094
1094
|
{ name = "virtualenv" },
|
|
1095
1095
|
]
|
|
1096
|
-
sdist = { url = "https://files.pythonhosted.org/packages/
|
|
1096
|
+
sdist = { url = "https://files.pythonhosted.org/packages/8e/22/2de9408ac81acbb8a7d05d4cc064a152ccf33b3d480ebe0cd292153db239/pre_commit-4.6.0.tar.gz", hash = "sha256:718d2208cef53fdc38206e40524a6d4d9576d103eb16f0fec11c875e7716e9d9", size = 198525, upload-time = "2026-04-21T20:31:41.613Z" }
|
|
1097
1097
|
wheels = [
|
|
1098
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
1098
|
+
{ url = "https://files.pythonhosted.org/packages/80/6e/4b28b62ecb6aae56769c34a8ff1d661473ec1e9519e2d5f8b2c150086b26/pre_commit-4.6.0-py2.py3-none-any.whl", hash = "sha256:e2cf246f7299edcabcf15f9b0571fdce06058527f0a06535068a86d38089f29b", size = 226472, upload-time = "2026-04-21T20:31:40.092Z" },
|
|
1099
1099
|
]
|
|
1100
1100
|
|
|
1101
1101
|
[[package]]
|
|
@@ -1411,7 +1411,7 @@ wheels = [
|
|
|
1411
1411
|
|
|
1412
1412
|
[[package]]
|
|
1413
1413
|
name = "python3-commons"
|
|
1414
|
-
version = "0.16.
|
|
1414
|
+
version = "0.16.4"
|
|
1415
1415
|
source = { registry = "https://pypi.org/simple" }
|
|
1416
1416
|
dependencies = [
|
|
1417
1417
|
{ name = "aiobotocore" },
|
|
@@ -1426,9 +1426,8 @@ dependencies = [
|
|
|
1426
1426
|
{ name = "valkey", extra = ["libvalkey"] },
|
|
1427
1427
|
{ name = "zeep" },
|
|
1428
1428
|
]
|
|
1429
|
-
sdist = { url = "https://files.pythonhosted.org/packages/40/8c/d6bb68614944e3c9542a23bfe0314e0b9626ebca4b1cb0a36dff941cb79c/python3_commons-0.16.0.tar.gz", hash = "sha256:83471867ea10d5879ff7877dd4a18d17c46314404091058938a9e833dc1ed43b", size = 111299, upload-time = "2026-04-21T15:19:49.293Z" }
|
|
1430
1429
|
wheels = [
|
|
1431
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
1430
|
+
{ url = "https://files.pythonhosted.org/packages/d8/cc/e74c9c8d7a469e00f5fcf6ac7af8cdd52afba5defe9251cadc87c7b6dc28/python3_commons-0.16.4-py3-none-any.whl", hash = "sha256:b0dfb364a77a0182c0c94a34eea98e264adae5b62484ba65353a47824fd9b185", size = 37938, upload-time = "2026-04-22T09:28:52.939Z" },
|
|
1432
1431
|
]
|
|
1433
1432
|
|
|
1434
1433
|
[[package]]
|
|
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_commons-0.4.0/tests → fastapi_commons-0.4.2/src/fastapi_commons/middleware}/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{fastapi_commons-0.4.0 → fastapi_commons-0.4.2}/src/fastapi_commons.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|