microbootstrap 0.4.4__tar.gz → 0.5.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.
Files changed (30) hide show
  1. {microbootstrap-0.4.4 → microbootstrap-0.5.2}/PKG-INFO +25 -1
  2. {microbootstrap-0.4.4 → microbootstrap-0.5.2}/README.md +23 -0
  3. {microbootstrap-0.4.4 → microbootstrap-0.5.2}/microbootstrap/__init__.py +2 -1
  4. {microbootstrap-0.4.4 → microbootstrap-0.5.2}/microbootstrap/bootstrappers/fastapi.py +11 -0
  5. {microbootstrap-0.4.4 → microbootstrap-0.5.2}/microbootstrap/bootstrappers/litestar.py +16 -1
  6. microbootstrap-0.5.2/microbootstrap/instruments/health_checks_instrument.py +31 -0
  7. {microbootstrap-0.4.4 → microbootstrap-0.5.2}/microbootstrap/settings.py +9 -4
  8. {microbootstrap-0.4.4 → microbootstrap-0.5.2}/pyproject.toml +2 -1
  9. {microbootstrap-0.4.4 → microbootstrap-0.5.2}/microbootstrap/bootstrappers/__init__.py +0 -0
  10. {microbootstrap-0.4.4 → microbootstrap-0.5.2}/microbootstrap/bootstrappers/base.py +0 -0
  11. {microbootstrap-0.4.4 → microbootstrap-0.5.2}/microbootstrap/config/__init__.py +0 -0
  12. {microbootstrap-0.4.4 → microbootstrap-0.5.2}/microbootstrap/config/fastapi.py +0 -0
  13. {microbootstrap-0.4.4 → microbootstrap-0.5.2}/microbootstrap/config/litestar.py +0 -0
  14. {microbootstrap-0.4.4 → microbootstrap-0.5.2}/microbootstrap/console_writer.py +0 -0
  15. {microbootstrap-0.4.4 → microbootstrap-0.5.2}/microbootstrap/exceptions.py +0 -0
  16. {microbootstrap-0.4.4 → microbootstrap-0.5.2}/microbootstrap/granian_server.py +0 -0
  17. {microbootstrap-0.4.4 → microbootstrap-0.5.2}/microbootstrap/helpers.py +0 -0
  18. {microbootstrap-0.4.4 → microbootstrap-0.5.2}/microbootstrap/instruments/__init__.py +0 -0
  19. {microbootstrap-0.4.4 → microbootstrap-0.5.2}/microbootstrap/instruments/base.py +0 -0
  20. {microbootstrap-0.4.4 → microbootstrap-0.5.2}/microbootstrap/instruments/cors_instrument.py +0 -0
  21. {microbootstrap-0.4.4 → microbootstrap-0.5.2}/microbootstrap/instruments/instrument_box.py +0 -0
  22. {microbootstrap-0.4.4 → microbootstrap-0.5.2}/microbootstrap/instruments/logging_instrument.py +0 -0
  23. {microbootstrap-0.4.4 → microbootstrap-0.5.2}/microbootstrap/instruments/opentelemetry_instrument.py +0 -0
  24. {microbootstrap-0.4.4 → microbootstrap-0.5.2}/microbootstrap/instruments/prometheus_instrument.py +0 -0
  25. {microbootstrap-0.4.4 → microbootstrap-0.5.2}/microbootstrap/instruments/sentry_instrument.py +0 -0
  26. {microbootstrap-0.4.4 → microbootstrap-0.5.2}/microbootstrap/instruments/swagger_instrument.py +0 -0
  27. {microbootstrap-0.4.4 → microbootstrap-0.5.2}/microbootstrap/middlewares/__init__.py +0 -0
  28. {microbootstrap-0.4.4 → microbootstrap-0.5.2}/microbootstrap/middlewares/fastapi.py +0 -0
  29. {microbootstrap-0.4.4 → microbootstrap-0.5.2}/microbootstrap/middlewares/litestar.py +0 -0
  30. {microbootstrap-0.4.4 → microbootstrap-0.5.2}/microbootstrap/py.typed +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: microbootstrap
3
- Version: 0.4.4
3
+ Version: 0.5.2
4
4
  Summary: Package for bootstrapping new micro-services
5
5
  Keywords: python,microservice,bootstrap,opentelemetry,logging,error-tracing,litestar,fastapi
6
6
  Author: community-of-python
@@ -25,6 +25,7 @@ Requires-Dist: eval-type-backport (>=0.2.0,<0.3.0)
25
25
  Requires-Dist: fastapi (>=0.111.0,<0.112.0) ; extra == "fastapi"
26
26
  Requires-Dist: fastapi-offline-docs (>=1.0.1,<2.0.0) ; extra == "fastapi"
27
27
  Requires-Dist: granian[reload] (>=1.4.4,<2.0.0)
28
+ Requires-Dist: health-checks (>=1.0.0,<2.0.0)
28
29
  Requires-Dist: litestar (>=2.9.1,<3.0.0) ; extra == "litestar"
29
30
  Requires-Dist: litestar-offline-docs (>=1.0.1,<2.0.0) ; extra == "litestar"
30
31
  Requires-Dist: opentelemetry-api (>=1.25.0,<2.0.0)
@@ -90,6 +91,7 @@ With <b>microbootstrap</b>, you receive an application with lightweight built-in
90
91
  - `logging`
91
92
  - `cors`
92
93
  - `swagger` - with additional offline version support
94
+ - `health-checks`
93
95
 
94
96
  Those instruments can be bootstrapped for:
95
97
 
@@ -111,6 +113,7 @@ Interested? Let's dive right in ⚡
111
113
  - [Logging](#logging)
112
114
  - [CORS](#cors)
113
115
  - [Swagger](#swagger)
116
+ - [Health checks](#health-checks)
114
117
  - [Configuration](#configuration)
115
118
  - [Instruments configuration](#instruments-configuration)
116
119
  - [Application configuration](#application-configuration)
@@ -454,6 +457,27 @@ Parameter descriptions:
454
457
  - `swagger_offline_docs` - A boolean value that, when set to True, allows the Swagger JS bundles to be accessed offline. This is because the service starts to host via static.
455
458
  - `swagger_extra_params` - Additional parameters to pass into the OpenAPI configuration.
456
459
 
460
+ ### Health checks
461
+
462
+ ```python
463
+ from microbootstrap.settings import BaseServiceSettings
464
+
465
+
466
+ class YourSettings(BaseServiceSettings):
467
+ service_name: str = "micro-service"
468
+ service_version: str = "1.0.0"
469
+
470
+ health_checks_enabled: bool = True
471
+ health_checks_path: str = "/health/"
472
+ ```
473
+
474
+ Parameter descriptions:
475
+
476
+ - `service_name` - Will be displayed in health check response.
477
+ - `service_version` - Will be displayed in health check response.
478
+ - `health_checks_enabled` - Must be True to enable health checks.
479
+ - `health_checks_path` - Path for health check handler.
480
+
457
481
  ## Configuration
458
482
 
459
483
  While settings provide a convenient mechanism, it's not always feasible to store everything within them.
@@ -41,6 +41,7 @@ With <b>microbootstrap</b>, you receive an application with lightweight built-in
41
41
  - `logging`
42
42
  - `cors`
43
43
  - `swagger` - with additional offline version support
44
+ - `health-checks`
44
45
 
45
46
  Those instruments can be bootstrapped for:
46
47
 
@@ -62,6 +63,7 @@ Interested? Let's dive right in ⚡
62
63
  - [Logging](#logging)
63
64
  - [CORS](#cors)
64
65
  - [Swagger](#swagger)
66
+ - [Health checks](#health-checks)
65
67
  - [Configuration](#configuration)
66
68
  - [Instruments configuration](#instruments-configuration)
67
69
  - [Application configuration](#application-configuration)
@@ -405,6 +407,27 @@ Parameter descriptions:
405
407
  - `swagger_offline_docs` - A boolean value that, when set to True, allows the Swagger JS bundles to be accessed offline. This is because the service starts to host via static.
406
408
  - `swagger_extra_params` - Additional parameters to pass into the OpenAPI configuration.
407
409
 
410
+ ### Health checks
411
+
412
+ ```python
413
+ from microbootstrap.settings import BaseServiceSettings
414
+
415
+
416
+ class YourSettings(BaseServiceSettings):
417
+ service_name: str = "micro-service"
418
+ service_version: str = "1.0.0"
419
+
420
+ health_checks_enabled: bool = True
421
+ health_checks_path: str = "/health/"
422
+ ```
423
+
424
+ Parameter descriptions:
425
+
426
+ - `service_name` - Will be displayed in health check response.
427
+ - `service_version` - Will be displayed in health check response.
428
+ - `health_checks_enabled` - Must be True to enable health checks.
429
+ - `health_checks_path` - Path for health check handler.
430
+
408
431
  ## Configuration
409
432
 
410
433
  While settings provide a convenient mechanism, it's not always feasible to store everything within them.
@@ -1,4 +1,5 @@
1
1
  from microbootstrap.instruments.cors_instrument import CorsConfig
2
+ from microbootstrap.instruments.health_checks_instrument import HealthChecksConfig
2
3
  from microbootstrap.instruments.logging_instrument import LoggingConfig
3
4
  from microbootstrap.instruments.opentelemetry_instrument import OpentelemetryConfig
4
5
  from microbootstrap.instruments.prometheus_instrument import FastApiPrometheusConfig, LitestarPrometheusConfig
@@ -13,9 +14,9 @@ __all__ = (
13
14
  "FastApiPrometheusConfig",
14
15
  "LitestarPrometheusConfig",
15
16
  "LoggingConfig",
16
- "LitestarBootstrapper",
17
17
  "LitestarSettings",
18
18
  "FastApiSettings",
19
19
  "CorsConfig",
20
20
  "SwaggerConfig",
21
+ "HealthChecksConfig",
21
22
  )
@@ -4,6 +4,7 @@ import fastapi
4
4
  import typing_extensions
5
5
  from fastapi.middleware.cors import CORSMiddleware
6
6
  from fastapi_offline_docs import enable_offline_docs
7
+ from health_checks.fastapi_healthcheck import build_fastapi_health_check_router
7
8
  from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
8
9
  from prometheus_fastapi_instrumentator import Instrumentator
9
10
  from sentry_sdk.integrations.fastapi import FastApiIntegration
@@ -11,6 +12,7 @@ from sentry_sdk.integrations.fastapi import FastApiIntegration
11
12
  from microbootstrap.bootstrappers.base import ApplicationBootstrapper
12
13
  from microbootstrap.config.fastapi import FastApiConfig
13
14
  from microbootstrap.instruments.cors_instrument import CorsInstrument
15
+ from microbootstrap.instruments.health_checks_instrument import HealthChecksInstrument
14
16
  from microbootstrap.instruments.logging_instrument import LoggingInstrument
15
17
  from microbootstrap.instruments.opentelemetry_instrument import OpentelemetryInstrument
16
18
  from microbootstrap.instruments.prometheus_instrument import FastApiPrometheusConfig, PrometheusInstrument
@@ -114,3 +116,12 @@ class FastApiPrometheusInstrument(PrometheusInstrument[FastApiPrometheusConfig])
114
116
  @classmethod
115
117
  def get_config_type(cls) -> type[FastApiPrometheusConfig]:
116
118
  return FastApiPrometheusConfig
119
+
120
+
121
+ @FastApiBootstrapper.use_instrument()
122
+ class FastApiHealthChecksInstrument(HealthChecksInstrument):
123
+ def bootstrap_after(self, application: fastapi.FastAPI) -> fastapi.FastAPI:
124
+ application.include_router(
125
+ build_fastapi_health_check_router(self.health_check, self.instrument_config.health_checks_path),
126
+ )
127
+ return application
@@ -4,6 +4,7 @@ import typing
4
4
  import litestar
5
5
  import litestar.types
6
6
  import typing_extensions
7
+ from health_checks.litestar_healthcheck import build_litestar_health_check_router
7
8
  from litestar import openapi
8
9
  from litestar.config.cors import CORSConfig as LitestarCorsConfig
9
10
  from litestar.contrib.opentelemetry.config import OpenTelemetryConfig as LitestarOpentelemetryConfig
@@ -15,6 +16,7 @@ from sentry_sdk.integrations.litestar import LitestarIntegration
15
16
  from microbootstrap.bootstrappers.base import ApplicationBootstrapper
16
17
  from microbootstrap.config.litestar import LitestarConfig
17
18
  from microbootstrap.instruments.cors_instrument import CorsInstrument
19
+ from microbootstrap.instruments.health_checks_instrument import HealthChecksInstrument
18
20
  from microbootstrap.instruments.logging_instrument import LoggingInstrument
19
21
  from microbootstrap.instruments.opentelemetry_instrument import OpentelemetryInstrument
20
22
  from microbootstrap.instruments.prometheus_instrument import LitestarPrometheusConfig, PrometheusInstrument
@@ -75,7 +77,7 @@ class LitestarSwaggerInstrument(SwaggerInstrument):
75
77
  } | self.instrument_config.swagger_extra_params
76
78
 
77
79
  bootstrap_result: typing.Final[dict[str, typing.Any]] = {
78
- "openapi_config": openapi.OpenAPIConfig(**all_swagger_params)
80
+ "openapi_config": openapi.OpenAPIConfig(**all_swagger_params),
79
81
  }
80
82
  if self.instrument_config.swagger_offline_docs:
81
83
  bootstrap_result["static_files_config"] = [
@@ -137,3 +139,16 @@ class LitestarPrometheusInstrument(PrometheusInstrument[LitestarPrometheusConfig
137
139
  @classmethod
138
140
  def get_config_type(cls) -> type[LitestarPrometheusConfig]:
139
141
  return LitestarPrometheusConfig
142
+
143
+
144
+ @LitestarBootstrapper.use_instrument()
145
+ class LitestarHealthChecksInstrument(HealthChecksInstrument):
146
+ def bootstrap_before(self) -> dict[str, typing.Any]:
147
+ return {
148
+ "route_handlers": [
149
+ build_litestar_health_check_router(
150
+ self.health_check,
151
+ self.instrument_config.health_checks_path,
152
+ ),
153
+ ],
154
+ }
@@ -0,0 +1,31 @@
1
+ from __future__ import annotations
2
+
3
+ from health_checks.http_based import DefaultHTTPHealthCheck
4
+
5
+ from microbootstrap.instruments.base import BaseInstrumentConfig, Instrument
6
+
7
+
8
+ class HealthChecksConfig(BaseInstrumentConfig):
9
+ service_name: str = "micro-service"
10
+ service_version: str = "1.0.0"
11
+
12
+ health_checks_enabled: bool = True
13
+ health_checks_path: str = "/health/"
14
+
15
+
16
+ class HealthChecksInstrument(Instrument[HealthChecksConfig]):
17
+ instrument_name = "Health checks"
18
+ ready_condition = "Set health_checks_enabled to True"
19
+
20
+ def bootstrap(self) -> None:
21
+ self.health_check = DefaultHTTPHealthCheck(
22
+ service_version=self.instrument_config.service_version,
23
+ service_name=self.instrument_config.service_name,
24
+ )
25
+
26
+ def is_ready(self) -> bool:
27
+ return self.instrument_config.health_checks_enabled
28
+
29
+ @classmethod
30
+ def get_config_type(cls) -> type[HealthChecksConfig]:
31
+ return HealthChecksConfig
@@ -8,6 +8,7 @@ import pydantic_settings
8
8
  from microbootstrap import (
9
9
  CorsConfig,
10
10
  FastApiPrometheusConfig,
11
+ HealthChecksConfig,
11
12
  LitestarPrometheusConfig,
12
13
  LoggingConfig,
13
14
  OpentelemetryConfig,
@@ -28,11 +29,13 @@ class BaseServiceSettings(
28
29
  service_debug: bool = False
29
30
  service_environment: str | None = None
30
31
  service_name: str = pydantic.Field(
31
- "micro-service", validation_alias=pydantic.AliasChoices("SERVICE_NAME", f"{ENV_PREFIX}SERVICE_NAME")
32
+ "micro-service",
33
+ validation_alias=pydantic.AliasChoices("SERVICE_NAME", f"{ENV_PREFIX}SERVICE_NAME"),
32
34
  )
33
35
  service_description: str = "Micro service description"
34
36
  service_version: str = pydantic.Field(
35
- "1.0.0", validation_alias=pydantic.AliasChoices("CI_COMMIT_TAG", f"{ENV_PREFIX}SERVICE_VERSION")
37
+ "1.0.0",
38
+ validation_alias=pydantic.AliasChoices("CI_COMMIT_TAG", f"{ENV_PREFIX}SERVICE_VERSION"),
36
39
  )
37
40
  service_static_path: str = "/static"
38
41
 
@@ -50,24 +53,26 @@ class BaseServiceSettings(
50
53
 
51
54
 
52
55
  class LitestarSettings(
53
- BaseServiceSettings,
54
56
  LoggingConfig,
55
57
  OpentelemetryConfig,
56
58
  SentryConfig,
57
59
  LitestarPrometheusConfig,
58
60
  SwaggerConfig,
59
61
  CorsConfig,
62
+ HealthChecksConfig,
63
+ BaseServiceSettings,
60
64
  ):
61
65
  """Settings for a litestar botstrap."""
62
66
 
63
67
 
64
68
  class FastApiSettings(
65
- BaseServiceSettings,
66
69
  LoggingConfig,
67
70
  OpentelemetryConfig,
68
71
  SentryConfig,
69
72
  FastApiPrometheusConfig,
70
73
  SwaggerConfig,
71
74
  CorsConfig,
75
+ HealthChecksConfig,
76
+ BaseServiceSettings,
72
77
  ):
73
78
  """Settings for a fastapi botstrap."""
@@ -26,7 +26,7 @@ classifiers = [
26
26
  "Programming Language :: Python :: 3.11",
27
27
  "Programming Language :: Python :: 3.12",
28
28
  ]
29
- version = "0.4.4"
29
+ version = "0.5.2"
30
30
  description = "Package for bootstrapping new micro-services"
31
31
  authors = ["community-of-python"]
32
32
  readme = "README.md"
@@ -66,6 +66,7 @@ fastapi = { version = "^0.111.0", optional = true }
66
66
  prometheus-fastapi-instrumentator = { version = "^6.1.0", optional = true }
67
67
  opentelemetry-instrumentation-fastapi = { version = "^0.46b0", optional = true }
68
68
  fastapi-offline-docs = { version = "^1.0.1", optional = true }
69
+ health-checks = "^1.0.0"
69
70
 
70
71
  [tool.poetry.group.dev.dependencies]
71
72
  pytest = "^8.2.2"