Registry / serialization / lazr-config

lazr-config

JSON →
library3.1pypypiunverified

lazr.config is a Python library for defining configuration schemas, processing configuration data from various sources (like files or command-line arguments), and validating that data against the defined schema. It ensures that applications receive well-formed and valid configurations, reducing runtime errors. The current version is 3.1, and it typically follows an as-needed release cadence driven by Launchpad's requirements.

pip install lazr.config
INSTALL
IMPORT
SIG · LAZR-CONFIG
L
lazr-config
serializationpythonv3.1
Install
2.2s avg
Import
Disk
22MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 20.1MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 2.2s · import 0.000s · 21MB
22MB installed
● package 22MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ConfigurationSchema
from lazr.config import ConfigurationSchema
from lazr.config import ConfigurationSchema

This quickstart demonstrates how to define a configuration schema using `ConfigurationSchema` and `Field`, and then create a validated `Config` instance from a Python dictionary. It also shows how type mismatches lead to `ConfigError`.

from lazr.config import ConfigurationSchema, Field, Config, ConfigError # 1. Define a configuration schema class MySchema(ConfigurationSchema): db_host = Field(str, default='localhost', doc="Database hostname") db_port = Field(int, default=5432, doc="Database port") debug_mode = Field(bool, default=False, doc="Enable debug logging") # 2. Create a configuration instance from a dictionary config_data = { 'db_host': 'prod.database.com', 'db_port': 5432, # 'debug_mode' is omitted, will use default } try: config = Config(MySchema, config_data) print(f"DB Host: {config.db_host}") print(f"DB Port: {config.db_port}") print(f"Debug Mode: {config.debug_mode}") # Accessing an unknown field raises an AttributeError # print(config.unknown_field) except ConfigError as e: print(f"Configuration error: {e}") # Example of an invalid configuration invalid_config_data = { 'db_port': 'not_a_number', # This will fail validation } try: invalid_config = Config(MySchema, invalid_config_data) except ConfigError as e: print(f"Caught expected error for invalid config: {e}")
Debug
Known issues
breakingPython 2 support was officially dropped in lazr.config version 3.0. Projects still relying on Python 2 will need to use an older version (e.g., 2.x) or migrate to Python 3.
fix
Upgrade your Python environment to 3.8 or newer. If Python 2 is required, use lazr.config<3.0 and be aware it is no longer maintained.
affects: >=3.0
gotchaField types in lazr.config schemas are strictly enforced. Providing a value that does not match the declared type (e.g., a string for an integer field) will result in a `ConfigError`.
fix
Ensure that the data provided to the `Config` object, regardless of its source, strictly conforms to the types defined in the `ConfigurationSchema`.
affects: all
gotchaAttempting to access a configuration field that was not defined in the `ConfigurationSchema` will raise an `AttributeError` on the `Config` instance, similar to accessing an undeclared attribute on a regular Python object.
fix
All configuration parameters you intend to use must be explicitly declared as `Field`s within your `ConfigurationSchema`. If you need dynamic access, consider using `Config.get_raw_data()` to access the underlying dictionary.
affects: all
gotchaThe `Config` class constructor directly takes a dictionary for configuration data. For loading from external sources like configuration files (e.g., INI, YAML) or command-line arguments, you must use helper classes like `ConfigFile` or `CommandLineArgumentParser`.
fix
For file-based configuration, use `ConfigFile(schema, config_file_path)` and then `config_object.config` or similar. For command-line, use `CommandLineArgumentParser(schema)` to parse arguments into a `Config` instance.
affects: all
Upgrade
Version history
3.1latest on PyPI · released Dec 9, 2024
Audit
Dependencies
zope.interfacerequiredProvides an interface system used internally for defining schema and configuration components.
Agent activity
2 hits · last 30 days
node
2
Resources
lazr-config — pip install lazr-config · libregistry