### Install with Litestar, Structlog, and OpenTelemetry using Poetry Source: https://github.com/modern-python/lite-bootstrap/blob/main/docs/introduction/installation.md Use this command to install lite-bootstrap with specific Litestar integrations for logging and OpenTelemetry using Poetry. ```bash poetry add lite-bootstrap[litestar-logging,litestar-otl] ``` -------------------------------- ### Install Lite Bootstrap with Free Extras Source: https://github.com/modern-python/lite-bootstrap/blob/main/docs/integrations/free.md Install the lite-bootstrap package with all free extras using your preferred package manager. ```bash uv add lite-bootstrap[free-all] ``` ```bash pip install lite-bootstrap[free-all] ``` ```bash poetry add lite-bootstrap[free-all] ``` -------------------------------- ### Install Lite Bootstrap with FastMCP Extras Source: https://github.com/modern-python/lite-bootstrap/blob/main/docs/integrations/fastmcp.md Install the necessary package for FastMCP integration using your preferred package manager. ```bash uv add lite-bootstrap[fastmcp-all] ``` ```bash pip install lite-bootstrap[fastmcp-all] ``` ```bash poetry add lite-bootstrap[fastmcp-all] ``` -------------------------------- ### Install Lite-Bootstrap with LiteStar extras Source: https://github.com/modern-python/lite-bootstrap/blob/main/docs/integrations/litestar.md Install the necessary package for LiteStar integration using your preferred package manager. ```bash uv add lite-bootstrap[litestar-all] ``` ```bash pip install lite-bootstrap[litestar-all] ``` ```bash poetry add lite-bootstrap[litestar-all] ``` -------------------------------- ### Install with Litestar, Structlog, and OpenTelemetry using uv Source: https://github.com/modern-python/lite-bootstrap/blob/main/docs/introduction/installation.md Use this command to install lite-bootstrap with specific Litestar integrations for logging and OpenTelemetry using the uv package manager. ```bash uv add lite-bootstrap[litestar-logging,litestar-otl] ``` -------------------------------- ### Install with Litestar, Structlog, and OpenTelemetry using pip Source: https://github.com/modern-python/lite-bootstrap/blob/main/docs/introduction/installation.md Use this command to install lite-bootstrap with specific Litestar integrations for logging and OpenTelemetry using pip. ```bash pip install lite-bootstrap[litestar-logging,litestar-otl] ``` -------------------------------- ### Install Lite-Bootstrap with FastAPI Extras Source: https://github.com/modern-python/lite-bootstrap/blob/main/docs/integrations/fastapi.md Install the necessary Lite-Bootstrap package for FastAPI. Choose the command corresponding to your package manager (uv, pip, or poetry). ```bash uv add lite-bootstrap[fastapi-all] ``` ```bash pip install lite-bootstrap[fastapi-all] ``` ```bash poetry add lite-bootstrap[fastapi-all] ``` -------------------------------- ### Install Lite Bootstrap for FastStream (pip) Source: https://github.com/modern-python/lite-bootstrap/blob/main/docs/integrations/faststream.md Use this command to install the Lite Bootstrap package with FastStream support using pip. ```bash pip install lite-bootstrap[faststream-all] ``` -------------------------------- ### Install Lite Bootstrap for FastStream (poetry) Source: https://github.com/modern-python/lite-bootstrap/blob/main/docs/integrations/faststream.md Use this command to add the Lite Bootstrap package with FastStream support using poetry. ```bash poetry add lite-bootstrap[faststream-all] ``` -------------------------------- ### Install Lite Bootstrap for FastStream (uv) Source: https://github.com/modern-python/lite-bootstrap/blob/main/docs/integrations/faststream.md Use this command to add the necessary Lite Bootstrap package with FastStream support using uv. ```bash uv add lite-bootstrap[faststream-all] ``` -------------------------------- ### FastAPI App Tagging Example Source: https://github.com/modern-python/lite-bootstrap/blob/main/architecture/bootstrappers.md Example of how a bootstrapper tags a FastAPI application with internal state using a prefixed attribute to avoid framework namespace conflicts. ```python from fastapi import FastAPI app: FastAPI = FastAPI() # Check if lifespan is already attached if not getattr(app, "_lite_bootstrap_lifespan_attached", False): # Mark lifespan as attached app._lite_bootstrap_lifespan_attached = True # noqa: SLF001 ``` -------------------------------- ### Define FastMCP Bootstrapper Configuration and Bootstrap Application Source: https://github.com/modern-python/lite-bootstrap/blob/main/docs/integrations/fastmcp.md Configure the FastMCP bootstrapper with service details and application settings, then bootstrap the FastMCP application. This setup includes defining a simple tool function. ```python from fastmcp import FastMCP from lite_bootstrap import FastMcpBootstrapper, FastMcpConfig bootstrapper_config = FastMcpConfig( service_name="microservice", service_version="2.0.0", service_environment="test", sentry_dsn="https://testdsn@localhost/1", prometheus_metrics_path="/custom-metrics/", health_checks_path="/custom-health/", logging_buffer_capacity=0, ) bootstrapper = FastMcpBootstrapper(bootstrap_config=bootstrapper_config) application: FastMCP = bootstrapper.bootstrap() @application.tool def greet_person(person_name: str) -> str: return f"Hello, {person_name}!" ``` -------------------------------- ### Instrument Dependency Missing Warning Example Source: https://github.com/modern-python/lite-bootstrap/blob/main/architecture/bootstrappers.md This warning is emitted when a required optional package for an instrument is missing. It is a subclass of InstrumentSkippedWarning. ```python from lite_bootstrap.warnings import InstrumentDependencyMissingWarning # To filter this warning: # import warnings # warnings.filterwarnings("ignore", category=InstrumentDependencyMissingWarning) ``` -------------------------------- ### Ignoring Instrument Dependency Warnings Source: https://github.com/modern-python/lite-bootstrap/blob/main/docs/introduction/configuration.md Provides an example of how to filter out `InstrumentDependencyMissingWarning` using Python's `warnings` module. This is useful for suppressing warnings about optional instrument dependencies. ```python import warnings from lite_bootstrap import InstrumentDependencyMissingWarning warnings.filterwarnings("ignore", category=InstrumentDependencyMissingWarning) ``` -------------------------------- ### Lite-Bootstrap Architecture Overview Source: https://github.com/modern-python/lite-bootstrap/blob/main/CLAUDE.md Illustrates the core architectural pattern involving configuration, instruments, and bootstrapper classes. ```text BaseConfig (frozen dataclass, kw_only) └── Framework configs compose multiple instrument configs via multiple inheritance BaseInstrument[ConfigT] (generic, non-frozen dataclass with slots) └── Instrument subclasses: lifecycle via bootstrap() / teardown(); skip check via is_configured() classmethod BaseBootstrapper (abc.ABC) ├── FastAPIBootstrapper ├── LitestarBootstrapper ├── FastStreamBootstrapper ├── FastMcpBootstrapper └── FreeBootstrapper ``` -------------------------------- ### Configure and Bootstrap Application with Free Features Source: https://github.com/modern-python/lite-bootstrap/blob/main/docs/integrations/free.md Define the configuration for the FreeBootstrapper, including OpenTelemetry and Sentry endpoints, and then bootstrap the application. ```python from lite_bootstrap import FreeBootstrapperConfig, FreeBootstrapper bootstrapper_config = FreeBootstrapperConfig( opentelemetry_endpoint="otl", sentry_dsn="https://testdsn@localhost/1", ) bootstrapper = FreeBootstrapper(bootstrapper_config) bootstrapper.bootstrap() ``` -------------------------------- ### Development Commands Source: https://github.com/modern-python/lite-bootstrap/blob/main/CLAUDE.md Common commands for managing dependencies, linting, and testing. Always use 'just' commands with 'uv run'. ```bash just install # Update lock file and sync all extras + lint group just lint # Format and lint (eof-fixer, ruff format, ruff check --fix, ty check) just lint-ci # CI lint in check-only mode (no auto-fix) just test # Run pytest with coverage just test -- -k "test_name" # Run a single test just test-branch # Run tests with branch coverage ``` -------------------------------- ### Define FastStream Bootstrapper Configuration Source: https://github.com/modern-python/lite-bootstrap/blob/main/docs/integrations/faststream.md Configure and bootstrap a FastStream application with Lite Bootstrap, including service details, OpenTelemetry, Prometheus, Sentry, and health checks. ```python from lite_bootstrap import FastStreamConfig, FastStreamBootstrapper from faststream.asgi import AsgiFastStream from faststream.redis.opentelemetry import RedisTelemetryMiddleware from faststream.redis.prometheus import RedisPrometheusMiddleware from faststream.redis import RedisBroker broker = RedisBroker() bootstrapper_config = FastStreamConfig( service_name="microservice", service_version="2.0.0", service_environment="test", opentelemetry_endpoint="otl", opentelemetry_middleware_cls=RedisTelemetryMiddleware, prometheus_metrics_path="/custom-metrics/", prometheus_middleware_cls=RedisPrometheusMiddleware, sentry_dsn="https://testdsn@localhost/1", health_checks_path="/custom-health/", logging_buffer_capacity=0, application=AsgiFastStream(broker), ) bootstrapper = FastStreamBootstrapper(bootstrapper_config) application = bootstrapper.bootstrap() ``` -------------------------------- ### Configure and Bootstrap LiteStar Application Source: https://github.com/modern-python/lite-bootstrap/blob/main/docs/integrations/litestar.md Define the configuration for LiteStar using LitestarConfig and build the application with LitestarBootstrapper. ```python from lite_bootstrap import LitestarConfig, LitestarBootstrapper bootstrapper_config = LitestarConfig( service_name="microservice", service_version="2.0.0", service_environment="test", cors_allowed_origins=["http://test"], health_checks_path="/custom-health/", opentelemetry_endpoint="otl", prometheus_metrics_path="/custom-metrics/", sentry_dsn="https://testdsn@localhost/1", swagger_offline_docs=True, ) bootstrapper = LitestarBootstrapper(bootstrapper_config) application = bootstrapper.bootstrap() ``` -------------------------------- ### Sentinel Prefix for User-Supplied App Instances Source: https://github.com/modern-python/lite-bootstrap/blob/main/CLAUDE.md Use the '_lite_bootstrap_*' prefix for internal state sentinels on user-supplied framework app instances. Read state using getattr and write using direct attribute assignment, avoiding framework-specific namespaces. ```python application._lite_bootstrap_ = value # noqa: SLF001 ``` ```python getattr(application, "_lite_bootstrap_", False) ``` -------------------------------- ### Structlog Configuration for FastStream Source: https://github.com/modern-python/lite-bootstrap/blob/main/docs/introduction/configuration.md Demonstrates how to configure structlog logging for FastStream applications. Allows independent control over application log level and FastStream broker service message log level. ```python import logging from lite_bootstrap import FastStreamConfig config = FastStreamConfig( logging_log_level=logging.INFO, # your application logs faststream_log_level=logging.WARNING, # broker "Received"/"Processed" messages (default) ) ``` -------------------------------- ### Inspecting Skipped Instruments Programmatically Source: https://github.com/modern-python/lite-bootstrap/blob/main/docs/introduction/configuration.md Shows how to programmatically inspect which instruments were skipped during the bootstrapper construction. This is helpful for debugging and understanding why certain instruments were not initialized. ```python bootstrapper = FastAPIBootstrapper(bootstrap_config=config) for cls, reason in bootstrapper.skipped_instruments: print(f"{cls.__name__}: {reason}") ``` -------------------------------- ### FastAPI Application Bootstrapper Configuration Source: https://github.com/modern-python/lite-bootstrap/blob/main/docs/integrations/fastapi.md Configure and build a FastAPI application using Lite-Bootstrap. This snippet shows how to define service details, CORS origins, health check paths, and other operational settings. ```python from lite_bootstrap import FastAPIConfig, FastAPIBootstrapper bootstrapper_config = FastAPIConfig( service_name="microservice", service_version="2.0.0", service_environment="test", cors_allowed_origins=["http://test"], health_checks_path="/custom-health/", opentelemetry_endpoint="otl", prometheus_metrics_path="/custom-metrics/", sentry_dsn="https://testdsn@localhost/1", swagger_offline_docs=True, ) bootstrapper = FastAPIBootstrapper(bootstrapper_config) application = bootstrapper.bootstrap() ``` -------------------------------- ### FastAPIConfig Application Initialization Source: https://github.com/modern-python/lite-bootstrap/blob/main/architecture/config-model.md This snippet shows how FastAPIConfig initializes a FastAPI application if the 'application' field is still UNSET during post-initialization. It uses object.__setattr__ to bypass the frozen guard for construction-time computed fields. ```python if isinstance(self.application, UnsetType): application = fastapi.FastAPI(...) object.__setattr__(self, "application", application) ``` -------------------------------- ### __post_init__ Cascade Invariant Source: https://github.com/modern-python/lite-bootstrap/blob/main/CLAUDE.md Ensure every config-class __post_init__ calls super().__post_init__() to maintain MRO chain termination. FastAPIConfig uses an explicit super() call due to @dataclass(slots=True) altering the class object. ```python super().__post_init__() ``` ```python super(FastAPIConfig, self).__post_init__() ``` -------------------------------- ### Configure Structlog with Custom Time Stamper Source: https://github.com/modern-python/lite-bootstrap/blob/main/docs/introduction/configuration.md Customize the timestamp format and UTC setting for structlog logging by providing a custom TimeStamper instance. ```python import structlog from lite_bootstrap import FastAPIConfig config = FastAPIConfig( logging_time_stamper=structlog.processors.TimeStamper(fmt="%Y-%m-%d %H:%M:%S", utc=True), ) ``` -------------------------------- ### Bypass Frozen-Config in __post_init__ Source: https://github.com/modern-python/lite-bootstrap/blob/main/CLAUDE.md Use object.__setattr__ within a frozen config's __post_init__ to set fields that depend on other config values during construction. Document this trade-off with a comment. ```python object.__setattr__(self, "field", value) # User-facing immutability vs. construction-time mutation ``` -------------------------------- ### Explicit Super Call in __post_init__ Source: https://github.com/modern-python/lite-bootstrap/blob/main/architecture/config-model.md Demonstrates the explicit super call pattern required in __post_init__ when using @dataclass(slots=True) to ensure the initialization cascade completes correctly. This is necessary because the decorator can alter the class object, breaking the bare super() mechanism. ```python super(FastAPIConfig, self).__post_init__() ``` -------------------------------- ### Handle None in from_dict vs from_object Source: https://github.com/modern-python/lite-bootstrap/blob/main/CLAUDE.md BaseConfig.from_dict allows explicit None overrides, while BaseConfig.from_object filters out attributes with None values. Choose from_dict for explicit None semantics. ```python BaseConfig.from_dict({"service_name": None}) ``` -------------------------------- ### Structlog Integration with Litestar Source: https://github.com/modern-python/lite-bootstrap/blob/main/docs/introduction/configuration.md Shows how to enable structlog logging within Litestar applications. The StructlogPlugin is automatically registered, making `request.logger` available in route handlers. ```python from litestar import Litestar, Request, get from lite_bootstrap import LitestarConfig, LitestarBootstrapper @get("/") async def handler(request: Request) -> dict[str, str]: request.logger.info("handling request") return {"status": "ok"} ``` -------------------------------- ### Optional-Import Guard Pattern Source: https://github.com/modern-python/lite-bootstrap/blob/main/CLAUDE.md Use conditional imports at the top level to keep optional dependencies truly optional. Code referencing optional modules is only reached after dependency checks confirm their availability. ```python if import_checker.is_X_installed: import X ``` -------------------------------- ### Access Logger in LiteStar Route Handler Source: https://github.com/modern-python/lite-bootstrap/blob/main/docs/integrations/litestar.md Demonstrates how to access the request logger within a LiteStar route handler using StructlogPlugin. ```python from litestar import Request, get @get("/items") async def list_items(request: Request) -> list[str]: request.logger.info("listing items") return [] ``` -------------------------------- ### Backward-Compat Aliases for Renames Source: https://github.com/modern-python/lite-bootstrap/blob/main/CLAUDE.md When renaming a public class, create a silent module-level alias (OldName = NewName) at the end of the file to maintain backward compatibility. Ensure both names are re-exported from __init__.py if the old name was publicly exported. ```python OldName = NewName ``` -------------------------------- ### Extract Magic Values to Named Locals Source: https://github.com/modern-python/lite-bootstrap/blob/main/CLAUDE.md Avoid using magic values directly in assertions. Instead, extract them to named local variables for better readability and maintainability. ```python expected_max_age = 600 assert config.cors_max_age == expected_max_age ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.