{"id":16450906,"url":"https://github.com/community-of-python/microbootstrap","last_synced_at":"2026-03-12T10:14:06.214Z","repository":{"id":246943984,"uuid":"822526368","full_name":"community-of-python/microbootstrap","owner":"community-of-python","description":"Bootstrap your microservices in a second!","archived":false,"fork":false,"pushed_at":"2025-09-05T14:03:28.000Z","size":709,"stargazers_count":51,"open_issues_count":3,"forks_count":5,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-09-05T15:45:24.136Z","etag":null,"topics":["configuration","configuration-management","fastapi","library","litestar","litestar-framework","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/community-of-python.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-07-01T10:10:34.000Z","updated_at":"2025-09-05T14:02:57.000Z","dependencies_parsed_at":"2024-08-13T21:25:37.151Z","dependency_job_id":"8515b0ad-2d49-4e35-a6c2-5d83b2defed3","html_url":"https://github.com/community-of-python/microbootstrap","commit_stats":{"total_commits":211,"total_committers":8,"mean_commits":26.375,"dds":"0.45023696682464454","last_synced_commit":"c1d22a23d2f0648653d06be4db7fd5637cd46a86"},"previous_names":["community-of-python/microbootstrap"],"tags_count":62,"template":false,"template_full_name":null,"purl":"pkg:github/community-of-python/microbootstrap","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/community-of-python%2Fmicrobootstrap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/community-of-python%2Fmicrobootstrap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/community-of-python%2Fmicrobootstrap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/community-of-python%2Fmicrobootstrap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/community-of-python","download_url":"https://codeload.github.com/community-of-python/microbootstrap/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/community-of-python%2Fmicrobootstrap/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276229057,"owners_count":25606942,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-21T02:00:07.055Z","response_time":72,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["configuration","configuration-management","fastapi","library","litestar","litestar-framework","python"],"created_at":"2024-10-11T10:06:17.185Z","updated_at":"2026-03-03T09:03:39.967Z","avatar_url":"https://github.com/community-of-python.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/community-of-python/microbootstrap/main/logo.svg\" width=\"350\"\u003e\n\u003c/p\u003e\n\u003cbr\u003e\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://codecov.io/gh/community-of-python/microbootstrap\" target=\"_blank\"\u003e\u003cimg src=\"https://codecov.io/gh/community-of-python/microbootstrap/branch/main/graph/badge.svg\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://pypi.org/project/microbootstrap/\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/pypi/pyversions/microbootstrap\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://pypi.org/project/microbootstrap/\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/pypi/v/microbootstrap\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://pypistats.org/packages/microbootstrap\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/pypi/dm/microbootstrap\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cb\u003emicrobootstrap\u003c/b\u003e assists you in creating applications with all the necessary instruments already set up.\n\n```python\n# settings.py\nfrom microbootstrap import LitestarSettings\n\n\nclass YourSettings(LitestarSettings):\n    ...  # Your settings are stored here\n\n\nsettings = YourSettings()\n\n\n# application.py\nimport litestar\nfrom microbootstrap.bootstrappers.litestar import LitestarBootstrapper\n\nfrom your_application.settings import settings\n\n# Use the Litestar application!\napplication: litestar.Litestar = LitestarBootstrapper(settings).bootstrap()\n```\n\nWith \u003cb\u003emicrobootstrap\u003c/b\u003e, you receive an application with lightweight built-in support for:\n\n- `sentry`\n- `prometheus`\n- `opentelemetry`\n- `logging`\n- `cors`\n- `swagger` - with additional offline version support\n- `health-checks`\n\nThose instruments can be bootstrapped for:\n\n- `fastapi`,\n- `litestar`,\n- or `faststream` service,\n- or even a service that doesn't use one of these frameworks.\n\nInterested? Let's dive right in ⚡\n\n## Table of Contents\n\n- [Installation](#installation)\n- [Quickstart](#quickstart)\n- [Settings](#settings)\n- [Service settings](#service-settings)\n- [Instruments](#instruments)\n  - [Sentry](#sentry)\n  - [Prometheus](#prometheus)\n  - [Opentelemetry](#opentelemetry)\n  - [Logging](#logging)\n  - [CORS](#cors)\n  - [Swagger](#swagger)\n  - [Health checks](#health-checks)\n- [Configuration](#configuration)\n  - [Instruments configuration](#instruments-configuration)\n  - [Application configuration](#application-configuration)\n- [Advanced](#advanced)\n\n## Installation\n\nAlso, you can specify extras during installation for concrete framework:\n\n- `fastapi`\n- `litestar`\n- `faststream` (ASGI app)\n\nAlso we have `granian` extra that is requires for `create_granian_server`.\n\nFor uv:\n\n```bash\nuv add \"microbootstrap[fastapi]\"\n```\n\nFor poetry:\n\n```bash\npoetry add microbootstrap -E fastapi\n```\n\nFor pip:\n\n```bash\npip install \"microbootstrap[fastapi]\"\n```\n\n## Quickstart\n\nTo configure your application, you can use the settings object.\n\n```python\nfrom microbootstrap import LitestarSettings\n\n\nclass YourSettings(LitestarSettings):\n    # General settings\n    service_debug: bool = False\n    service_name: str = \"my-awesome-service\"\n\n    # Sentry settings\n    sentry_dsn: str = \"your-sentry-dsn\"\n\n    # Prometheus settings\n    prometheus_metrics_path: str = \"/my-path\"\n\n    # Opentelemetry settings\n    opentelemetry_container_name: str = \"your-container\"\n    opentelemetry_endpoint: str = \"/opentelemetry-endpoint\"\n\n\n\nsettings = YourSettings()\n```\n\nNext, use the `Bootstrapper` object to create an application based on your settings.\n\n```python\nimport litestar\nfrom microbootstrap.bootstrappers.litestar import LitestarBootstrapper\n\napplication: litestar.Litestar = LitestarBootstrapper(settings).bootstrap()\n```\n\nThis approach will provide you with an application that has all the essential instruments already set up for you.\n\n### FastAPI\n\n```python\nimport fastapi\n\nfrom microbootstrap import FastApiSettings\nfrom microbootstrap.bootstrappers.fastapi import FastApiBootstrapper\n\n\nclass YourSettings(FastApiSettings):\n    # General settings\n    service_debug: bool = False\n    service_name: str = \"my-awesome-service\"\n\n    # Sentry settings\n    sentry_dsn: str = \"your-sentry-dsn\"\n\n    # Prometheus settings\n    prometheus_metrics_path: str = \"/my-path\"\n\n    # Opentelemetry settings\n    opentelemetry_container_name: str = \"your-container\"\n    opentelemetry_endpoint: str = \"/opentelemetry-endpoint\"\n\n\nsettings = YourSettings()\n\napplication: fastapi.FastAPI = FastApiBootstrapper(settings).bootstrap()\n```\n\n### FastStream\n\n```python\nfrom faststream.asgi import AsgiFastStream\n\nfrom microbootstrap import FastStreamSettings\nfrom microbootstrap.bootstrappers.faststream import FastStreamBootstrapper\n\n\nclass YourSettings(FastStreamSettings):\n    # General settings\n    service_debug: bool = False\n    service_name: str = \"my-awesome-service\"\n\n    # Sentry settings\n    sentry_dsn: str = \"your-sentry-dsn\"\n\n    # Prometheus settings\n    prometheus_metrics_path: str = \"/my-path\"\n\n    # Opentelemetry settings\n    opentelemetry_container_name: str = \"your-container\"\n    opentelemetry_endpoint: str = \"/opentelemetry-endpoint\"\n\n\nsettings = YourSettings()\n\napplication: AsgiFastStream = FastStreamBootstrapper(settings).bootstrap()\n```\n\n## Settings\n\nThe settings object is the core of microbootstrap.\n\nAll framework-related settings inherit from the `BaseServiceSettings` object. `BaseServiceSettings` defines parameters for the service and various instruments.\n\nHowever, the number of parameters is \u003cb\u003enot confined\u003c/b\u003e to those defined in `BaseServiceSettings`. You can add as many as you need.\n\nThese parameters can be sourced from your environment. By default, no prefix is added to these parameters.\n\nExample:\n\n```python\nclass YourSettings(BaseServiceSettings):\n    service_debug: bool = True\n    service_name: str = \"micro-service\"\n\n    your_awesome_parameter: str = \"really awesome\"\n\n    ... # Other settings here\n```\n\nTo source `your_awesome_parameter` from the environment, set the environment variable named `YOUR_AWESOME_PARAMETER`.\n\nIf you prefer to use a prefix when sourcing parameters, set the `ENVIRONMENT_PREFIX` environment variable in advance.\n\nExample:\n\n```bash\n$ export ENVIRONMENT_PREFIX=YOUR_PREFIX_\n```\n\nThen the settings object will attempt to source the variable named `YOUR_PREFIX_YOUR_AWESOME_PARAMETER`.\n\n## Service settings\n\nEach settings object for every framework includes service parameters that can be utilized by various instruments.\n\nYou can configure them manually, or set the corresponding environment variables and let \u003cb\u003emicrobootstrap\u003c/b\u003e to source them automatically.\n\n```python\nfrom microbootstrap.settings import BaseServiceSettings\n\n\nclass ServiceSettings(BaseServiceSettings):\n    service_debug: bool = True\n    service_environment: str | None = None\n    service_name: str = \"micro-service\"\n    service_description: str = \"Micro service description\"\n    service_version: str = \"1.0.0\"\n\n    ... # Other settings here\n\n```\n\n## Instruments\n\nAt present, the following instruments are supported for bootstrapping:\n\n- `sentry`\n- `prometheus`\n- `opentelemetry`\n- `pyroscope`\n- `logging`\n- `cors`\n- `swagger`\n\nLet's clarify the process required to bootstrap these instruments.\n\n### [Sentry](https://sentry.io/)\n\nTo bootstrap Sentry, you must provide at least the `sentry_dsn`.\nAdditional parameters can also be supplied through the settings object.\n\n```python\nfrom microbootstrap.settings import BaseServiceSettings\n\n\nclass YourSettings(BaseServiceSettings):\n    service_environment: str | None = None\n\n    sentry_dsn: str | None = None\n    sentry_traces_sample_rate: float | None = None\n    sentry_sample_rate: float = pydantic.Field(default=1.0, le=1.0, ge=0.0)\n    sentry_max_breadcrumbs: int = 15\n    sentry_max_value_length: int = 16384\n    sentry_attach_stacktrace: bool = True\n    sentry_integrations: list[Integration] = []\n    sentry_additional_params: dict[str, typing.Any] = {}\n    sentry_tags: dict[str, str] | None = None\n    sentry_opentelemetry_trace_url_template: str | None = None\n\n    ... # Other settings here\n```\n\nThese settings are subsequently passed to the [sentry-sdk](https://pypi.org/project/sentry-sdk/) package, finalizing your Sentry integration.\n\nParameter descriptions:\n\n- `service_environment` - The environment name for Sentry events.\n- `sentry_dsn` - The Data Source Name for your Sentry project.\n- `sentry_traces_sample_rate` - The rate at which traces are sampled (via Sentry Tracing, not OpenTelemetry).\n- `sentry_sample_rate` - The rate at which transactions are sampled.\n- `sentry_max_breadcrumbs` - The maximum number of breadcrumbs to keep.\n- `sentry_max_value_length` - The maximum length of values in Sentry events.\n- `sentry_attach_stacktrace` - Whether to attach stacktraces to messages.\n- `sentry_integrations` - A list of Sentry integrations to enable.\n- `sentry_additional_params` - Additional parameters to pass to Sentry SDK.\n- `sentry_tags` - Tags to apply to all Sentry events.\n- `sentry_opentelemetry_trace_url_template` - Template for OpenTelemetry trace URLs to add to Sentry events (example: `\"https://example.com/traces/{trace_id}\"`).\n\n### [Prometheus](https://prometheus.io/)\n\nPrometheus integration presents a challenge because the underlying libraries for `FastAPI`, `Litestar` and `FastStream` differ significantly, making it impossible to unify them under a single interface. As a result, the Prometheus settings for `FastAPI`, `Litestar` and `FastStream` must be configured separately.\n\n#### FastAPI\n\nTo bootstrap prometheus you have to provide `prometheus_metrics_path`\n\n```python\nfrom microbootstrap.settings import FastApiSettings\n\n\nclass YourSettings(FastApiSettings):\n    service_name: str\n\n    prometheus_metrics_path: str = \"/metrics\"\n    prometheus_metrics_include_in_schema: bool = False\n    prometheus_instrumentator_params: dict[str, typing.Any] = {}\n    prometheus_instrument_params: dict[str, typing.Any] = {}\n    prometheus_expose_params: dict[str, typing.Any] = {}\n\n    ... # Other settings here\n```\n\nParameters description:\n\n- `service_name` - will be attached to metrics's names, but has to be named in [snake_case](https://en.wikipedia.org/wiki/Snake_case).\n- `prometheus_metrics_path` - path to metrics handler.\n- `prometheus_metrics_include_in_schema` - whether to include metrics route in OpenAPI schema.\n- `prometheus_instrumentator_params` - will be passed to `Instrumentor` during initialization.\n- `prometheus_instrument_params` - will be passed to `Instrumentor.instrument(...)`.\n- `prometheus_expose_params` - will be passed to `Instrumentor.expose(...)`.\n\nFastAPI prometheus bootstrapper uses [prometheus-fastapi-instrumentator](https://github.com/trallnag/prometheus-fastapi-instrumentator) that's why there are three different dict for parameters.\n\n#### Litestar\n\nTo bootstrap prometheus you have to provide `prometheus_metrics_path`\n\n```python\nfrom microbootstrap.settings import LitestarSettings\n\n\nclass YourSettings(LitestarSettings):\n    service_name: str\n\n    prometheus_metrics_path: str = \"/metrics\"\n    prometheus_additional_params: dict[str, typing.Any] = {}\n\n    ... # Other settings here\n```\n\nParameters description:\n\n- `service_name` - will be attached to metric's names, there are no name restrictions.\n- `prometheus_metrics_path` - path to metrics handler.\n- `prometheus_additional_params` - will be passed to `litestar.contrib.prometheus.PrometheusConfig`.\n\n#### FastStream\n\nTo bootstrap prometheus you have to provide `prometheus_metrics_path` and `prometheus_middleware_cls`:\n\n```python\nfrom microbootstrap import FastStreamSettings\nfrom faststream.redis.prometheus import RedisPrometheusMiddleware\n\n\nclass YourSettings(FastStreamSettings):\n    service_name: str\n\n    prometheus_metrics_path: str = \"/metrics\"\n    prometheus_middleware_cls: type[FastStreamPrometheusMiddlewareProtocol] | None = RedisPrometheusMiddleware\n\n    ... # Other settings here\n```\n\nParameters description:\n\n- `service_name` - will be attached to metric's names, there are no name restrictions.\n- `prometheus_metrics_path` - path to metrics handler.\n- `prometheus_middleware_cls` - Prometheus middleware for your broker.\n\n### [OpenTelemetry](https://opentelemetry.io/)\n\nTo bootstrap OpenTelemetry, you must provide `opentelemetry_endpoint` or set `opentelemetry_log_traces` to `True`.\n\nHowever, additional parameters can also be supplied if needed.\n\n```python\nfrom microbootstrap.settings import BaseServiceSettings, FastStreamPrometheusMiddlewareProtocol\nfrom microbootstrap.instruments.opentelemetry_instrument import OpenTelemetryInstrumentor\n\n\nclass YourSettings(BaseServiceSettings):\n    service_name: str\n    service_version: str\n\n    opentelemetry_service_name: str | None = None\n    opentelemetry_container_name: str | None = None\n    opentelemetry_endpoint: str | None = None\n    opentelemetry_namespace: str | None = None\n    opentelemetry_insecure: bool = True\n    opentelemetry_instrumentors: list[OpenTelemetryInstrumentor] = []\n    opentelemetry_exclude_urls: list[str] = []\n\n    ... # Other settings here\n```\n\nParameters description:\n\n- `service_name` - will be passed to the `Resource`.\n- `service_version` - will be passed to the `Resource`.\n- `opentelemetry_service_name` - if provided, will be passed to the `Resource` instead of `service_name`.\n- `opentelemetry_endpoint` - will be passed to `OTLPSpanExporter` as endpoint.\n- `opentelemetry_namespace` - will be passed to the `Resource`.\n- `opentelemetry_insecure` - is opentelemetry connection secure.\n- `opentelemetry_container_name` - will be passed to the `Resource`.\n- `opentelemetry_instrumentors` - a list of extra instrumentors.\n- `opentelemetry_exclude_urls` - list of ignored urls.\n- `opentelemetry_log_traces` - traces will be logged to stdout.\n- `opentelemetry_generate_health_check_spans` - generate spans for health check handlers if `True`\n\nThese settings are subsequently passed to [opentelemetry](https://opentelemetry.io/), finalizing your Opentelemetry integration.\n\n#### FastStream\n\nFor FastStream you also should pass `opentelemetry_middleware_cls` - OpenTelemetry middleware for your broker\n\n```python\nfrom microbootstrap import FastStreamSettings, FastStreamTelemetryMiddlewareProtocol\nfrom faststream.redis.opentelemetry import RedisTelemetryMiddleware\n\n\nclass YourSettings(FastStreamSettings):\n    ...\n    opentelemetry_middleware_cls: type[FastStreamTelemetryMiddlewareProtocol] | None = RedisTelemetryMiddleware\n    ...\n```\n\n### [Pyroscope](https://pyroscope.io)\n\nTo integrate Pyroscope, specify the `pyroscope_endpoint`.\n\n- The `opentelemetry_service_name` will be used as the application name.\n- `service_namespace` tag will be added with `opentelemetry_namespace` value.\n- You can also set `pyroscope_sample_rate`, `pyroscope_auth_token`, `pyroscope_tags` and `pyroscope_additional_params` — params that will be passed to `pyroscope.configure`.\n\nWhen both Pyroscope and OpenTelemetry are enabled, profile span IDs will be included in traces using [`pyroscope-otel`](https://github.com/grafana/otel-profiling-python) for correlation.\n\nNote that Pyroscope integration is not supported on Windows.\n\n### Logging\n\n\u003cb\u003emicrobootstrap\u003c/b\u003e provides in-memory JSON logging through the use of [structlog](https://pypi.org/project/structlog/).\nFor more information on in-memory logging, refer to [MemoryHandler](https://docs.python.org/3/library/logging.handlers.html#memoryhandler).\n\nTo utilize this feature, your application must be in non-debug mode, meaning `service_debug` should be set to `False`.\n\n```python\nimport logging\n\nfrom microbootstrap.settings import BaseServiceSettings\n\n\nclass YourSettings(BaseServiceSettings):\n    service_debug: bool = False\n\n    logging_log_level: int = logging.INFO\n    logging_flush_level: int = logging.ERROR\n    logging_buffer_capacity: int = 10\n    logging_unset_handlers: list[str] = [\"uvicorn\", \"uvicorn.access\"]\n    logging_extra_processors: list[typing.Any] = []\n    logging_exclude_endpoints: list[str] = [\"/health/\", \"/metrics\"]\n    logging_turn_off_middleware: bool = False\n```\n\nParameters description:\n\n- `logging_log_level` - The default log level.\n- `logging_flush_level` - All messages will be flushed from the buffer when a log with this level appears.\n- `logging_buffer_capacity` - The number of messages your buffer will store before being flushed.\n- `logging_unset_handlers` - Unset logger handlers.\n- `logging_extra_processors` - Set additional structlog processors if needed.\n- `logging_exclude_endpoints` - Exclude logging on specific endpoints.\n- `logging_turn_off_middleware` - Turning off logging middleware.\n\n### CORS\n\n```python\nfrom microbootstrap.settings import BaseServiceSettings\n\n\nclass YourSettings(BaseServiceSettings):\n    cors_allowed_origins: list[str] = pydantic.Field(default_factory=list)\n    cors_allowed_methods: list[str] = pydantic.Field(default_factory=list)\n    cors_allowed_headers: list[str] = pydantic.Field(default_factory=list)\n    cors_exposed_headers: list[str] = pydantic.Field(default_factory=list)\n    cors_allowed_credentials: bool = False\n    cors_allowed_origin_regex: str | None = None\n    cors_max_age: int = 600\n```\n\nParameter descriptions:\n\n- `cors_allowed_origins` - A list of origins that are permitted.\n- `cors_allowed_methods` - A list of HTTP methods that are allowed.\n- `cors_allowed_headers` - A list of headers that are permitted.\n- `cors_exposed_headers` - A list of headers that are exposed via the 'Access-Control-Expose-Headers' header.\n- `cors_allowed_credentials` - A boolean value that dictates whether or not to set the 'Access-Control-Allow-Credentials' header.\n- `cors_allowed_origin_regex` - A regex used to match against origins.\n- `cors_max_age` - The response caching Time-To-Live (TTL) in seconds, defaults to 600.\n\n### Swagger\n\n```python\nfrom microbootstrap.settings import BaseServiceSettings\n\n\nclass YourSettings(BaseServiceSettings):\n    service_name: str = \"micro-service\"\n    service_description: str = \"Micro service description\"\n    service_version: str = \"1.0.0\"\n    service_static_path: str = \"/static\"\n\n    swagger_path: str = \"/docs\"\n    swagger_offline_docs: bool = False\n    swagger_extra_params: dict[str, Any] = {}\n```\n\nParameter descriptions:\n\n- `service_name` - The name of the service, which will be displayed in the documentation.\n- `service_description` - A brief description of the service, which will also be displayed in the documentation.\n- `service_version` - The current version of the service.\n- `service_static_path` - The path for static files in the service.\n- `swagger_path` - The path where the documentation can be found.\n- `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.\n- `swagger_extra_params` - Additional parameters to pass into the OpenAPI configuration.\n\n#### FastStream AsyncAPI documentation\n\nAsyncAPI documentation is available by default under `/asyncapi` route. You can change that by setting `asyncapi_path`:\n\n```python\nfrom microbootstrap import FastStreamSettings\n\n\nclass YourSettings(FastStreamSettings):\n    asyncapi_path: str | None = None\n```\n\n### Health checks\n\n```python\nfrom microbootstrap.settings import BaseServiceSettings\n\n\nclass YourSettings(BaseServiceSettings):\n    service_name: str = \"micro-service\"\n    service_version: str = \"1.0.0\"\n\n    health_checks_enabled: bool = True\n    health_checks_path: str = \"/health/\"\n    health_checks_include_in_schema: bool = False\n```\n\nParameter descriptions:\n\n- `service_name` - Will be displayed in health check response.\n- `service_version` - Will be displayed in health check response.\n- `health_checks_enabled` - Must be True to enable health checks.\n- `health_checks_path` - Path for health check handler.\n- `health_checks_include_in_schema` - Must be True to include `health_checks_path` (`/health/`) in OpenAPI schema.\n\n## Configuration\n\nWhile settings provide a convenient mechanism, it's not always feasible to store everything within them.\n\nThere may be cases where you need to configure a tool directly. Here's how it can be done.\n\n### Instruments configuration\n\nTo manually configure an instrument, you need to import one of the available configurations from \u003cb\u003emicrobootstrap\u003c/b\u003e:\n\n- `SentryConfig`\n- `OpentelemetryConfig`\n- `PrometheusConfig`\n- `LoggingConfig`\n- `SwaggerConfig`\n- `CorsConfig`\n\nThese configurations can then be passed into the `.configure_instrument` or `.configure_instruments` bootstrapper methods.\n\n```python\nimport litestar\n\nfrom microbootstrap.bootstrappers.litestar import LitestarBootstrapper\nfrom microbootstrap import SentryConfig, OpentelemetryConfig\n\n\napplication: litestar.Litestar = (\n    LitestarBootstrapper(settings)\n    .configure_instrument(SentryConfig(sentry_dsn=\"https://new-dsn\"))\n    .configure_instrument(OpentelemetryConfig(opentelemetry_endpoint=\"/new-endpoint\"))\n    .bootstrap()\n)\n```\n\nAlternatively,\n\n```python\nimport litestar\n\nfrom microbootstrap.bootstrappers.litestar import LitestarBootstrapper\nfrom microbootstrap import SentryConfig, OpentelemetryConfig\n\n\napplication: litestar.Litestar = (\n    LitestarBootstrapper(settings)\n    .configure_instruments(\n        SentryConfig(sentry_dsn=\"https://examplePublicKey@o0.ingest.sentry.io/0\"),\n        OpentelemetryConfig(opentelemetry_endpoint=\"/new-endpoint\")\n    )\n    .bootstrap()\n)\n```\n\n### Application configuration\n\nThe application can be configured in a similar manner:\n\n```python\nimport litestar\n\nfrom microbootstrap.config.litestar import LitestarConfig\nfrom microbootstrap.bootstrappers.litestar import LitestarBootstrapper\nfrom microbootstrap import SentryConfig, OpentelemetryConfig\n\n\n@litestar.get(\"/my-handler\")\nasync def my_handler() -\u003e str:\n    return \"Ok\"\n\napplication: litestar.Litestar = (\n    LitestarBootstrapper(settings)\n    .configure_application(LitestarConfig(route_handlers=[my_handler]))\n    .bootstrap()\n)\n```\n\n\u003e ### Important\n\u003e\n\u003e When configuring parameters with simple data types such as: `str`, `int`, `float`, etc., these variables overwrite previous values.\n\u003e\n\u003e Example:\n\u003e\n\u003e ```python\n\u003e from microbootstrap import LitestarSettings, SentryConfig\n\u003e\n\u003e\n\u003e class YourSettings(LitestarSettings):\n\u003e     sentry_dsn: str = \"https://my-sentry-dsn\"\n\u003e\n\u003e\n\u003e application: litestar.Litestar = (\n\u003e     LitestarBootstrapper(YourSettings())\n\u003e     .configure_instrument(\n\u003e         SentryConfig(sentry_dsn=\"https://my-new-configured-sentry-dsn\")\n\u003e     )\n\u003e     .bootstrap()\n\u003e )\n\u003e ```\n\u003e\n\u003e In this example, the application will be bootstrapped with the new `https://my-new-configured-sentry-dsn` Sentry DSN, replacing the old one.\n\u003e\n\u003e However, when you configure parameters with complex data types such as: `list`, `tuple`, `dict`, or `set`, they are expanded or merged.\n\u003e\n\u003e Example:\n\u003e\n\u003e ```python\n\u003e from microbootstrap import LitestarSettings, PrometheusConfig\n\u003e\n\u003e\n\u003e class YourSettings(LitestarSettings):\n\u003e     prometheus_additional_params: dict[str, Any] = {\"first_value\": 1}\n\u003e\n\u003e\n\u003e application: litestar.Litestar = (\n\u003e     LitestarBootstrapper(YourSettings())\n\u003e     .configure_instrument(\n\u003e         PrometheusConfig(prometheus_additional_params={\"second_value\": 2})\n\u003e     )\n\u003e     .bootstrap()\n\u003e )\n\u003e ```\n\u003e\n\u003e In this case, Prometheus will receive `{\"first_value\": 1, \"second_value\": 2}` inside `prometheus_additional_params`. This is also true for `list`, `tuple`, and `set`.\n\n### Using microbootstrap without a framework\n\nWhen working on projects that don't use Litestar or FastAPI, you can still take advantage of monitoring and logging capabilities using `InstrumentsSetupper`. This class sets up Sentry, OpenTelemetry, Pyroscope and Logging instruments in a way that's easy to integrate with your project.\n\nYou can use `InstrumentsSetupper` as a context manager, like this:\n\n```python\nfrom microbootstrap.instruments_setupper import InstrumentsSetupper\nfrom microbootstrap import InstrumentsSetupperSettings\n\n\nclass YourSettings(InstrumentsSetupperSettings):\n    ...\n\n\nwith InstrumentsSetupper(YourSettings()):\n    while True:\n        print(\"doing something useful\")\n        time.sleep(1)\n```\n\nAlternatively, you can use the `setup()` and `teardown()` methods instead of a context manager:\n\n```python\ncurrent_setupper = InstrumentsSetupper(YourSettings())\ncurrent_setupper.setup()\ntry:\n    while True:\n        print(\"doing something useful\")\n        time.sleep(1)\nfinally:\n    current_setupper.teardown()\n```\n\nLike bootstrappers, you can reconfigure instruments using the `configure_instrument()` and `configure_instruments()` methods.\n\n## Advanced\n\nIf you miss some instrument, you can add your own.\nEssentially, `Instrument` is just a class with some abstractmethods.\nEvery instrument uses some config, so that's first thing, you have to define.\n\n```python\nfrom microbootstrap.instruments.base import BaseInstrumentConfig\n\n\nclass MyInstrumentConfig(BaseInstrumentConfig):\n    your_string_parameter: str\n    your_list_parameter: list\n```\n\nNext, you can create an instrument class that inherits from `Instrument` and accepts your configuration as a generic parameter.\n\n```python\nfrom microbootstrap.instruments.base import Instrument\n\n\nclass MyInstrument(Instrument[MyInstrumentConfig]):\n    instrument_name: str\n    ready_condition: str\n\n    def is_ready(self) -\u003e bool:\n        pass\n\n    def teardown(self) -\u003e None:\n        pass\n\n    def bootstrap(self) -\u003e None:\n        pass\n\n    @classmethod\n    def get_config_type(cls) -\u003e type[MyInstrumentConfig]:\n        return MyInstrumentConfig\n```\n\nNow, you can define the behavior of your instrument.\n\nAttributes:\n\n- `instrument_name` - This will be displayed in your console during bootstrap.\n- `ready_condition` - This will be displayed in your console during bootstrap if the instrument is not ready.\n\nMethods:\n\n- `is_ready` - This defines the readiness of the instrument for bootstrapping, based on its configuration values. This is required.\n- `teardown` - This allows for a graceful shutdown of the instrument during application shutdown. This is not required.\n- `bootstrap` - This is the main logic of the instrument. This is not required.\n\nOnce you have the framework of the instrument, you can adapt it for any existing framework. For instance, let's adapt it for litestar.\n\n```python\nimport litestar\n\nfrom microbootstrap.bootstrappers.litestar import LitestarBootstrapper\n\n@LitestarBootstrapper.use_instrument()\nclass LitestarMyInstrument(MyInstrument):\n    def bootstrap_before(self) -\u003e dict[str, typing.Any]:\n        pass\n\n    def bootstrap_after(self, application: litestar.Litestar) -\u003e dict[str, typing.Any]:\n        pass\n```\n\nTo bind the instrument to a bootstrapper, use the `.use_instrument` decorator.\n\nTo add extra parameters to the application, you can use:\n\n- `bootstrap_before` - This adds arguments to the application configuration before creation.\n- `bootstrap_after` - This adds arguments to the application after creation.\n\nAfterwards, you can use your instrument during the bootstrap process.\n\n```python\nimport litestar\n\nfrom microbootstrap.bootstrappers.litestar import LitestarBootstrapper\nfrom microbootstrap import SentryConfig, OpentelemetryConfig\n\nfrom your_app import MyInstrumentConfig\n\n\napplication: litestar.Litestar = (\n    LitestarBootstrapper(settings)\n    .configure_instrument(\n        MyInstrumentConfig(\n            your_string_parameter=\"very-nice-parameter\",\n            your_list_parameter=[\"very-special-list\"],\n        )\n    )\n    .bootstrap()\n)\n```\n\nAlternatively, you can fill these parameters within your main settings object.\n\n```python\nfrom microbootstrap import LitestarSettings\nfrom microbootstrap.bootstrappers.litestar import LitestarBootstrapper\n\nfrom your_app import MyInstrumentConfig\n\n\nclass YourSettings(LitestarSettings, MyInstrumentConfig):\n    your_string_parameter: str = \"very-nice-parameter\"\n    your_list_parameter: list = [\"very-special-list\"]\n\nsettings = YourSettings()\n\napplication: litestar.Litestar = LitestarBootstrapper(settings).bootstrap()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcommunity-of-python%2Fmicrobootstrap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcommunity-of-python%2Fmicrobootstrap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcommunity-of-python%2Fmicrobootstrap/lists"}