ZConfig: Structured Configuration Library

4.3 · active · verified Thu Apr 16

ZConfig is a Python library designed for structured, schema-driven configuration, particularly useful for complex applications and logging. It employs an XML-based schema language to define the allowable structure and content of configuration documents, including custom data conversion routines written in Python. This approach offers greater flexibility and validation capabilities compared to Python's standard `ConfigParser` module. ZConfig is currently at version 4.3 and is actively maintained by the Zope Foundation.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to configure Python's logging framework using ZConfig's `configureLoggers` function. It takes an XML string defining the logging setup, including log level and output destination (STDOUT in this case).

from ZConfig import configureLoggers
import logging

# Define a simple ZConfig XML for logging
log_config = '''
<logger>
  level INFO
  <logfile>
    PATH STDOUT
    format %(levelname)s %(name)s %(message)s
  </logfile>
</logger>
'''

# Configure the Python logging framework using ZConfig
configureLoggers(log_config)

# Get a logger and test it
logger = logging.getLogger()
logger.info('An info message')
logger.debug('A debug message') # This will not show as level is INFO

view raw JSON →