{"id":1428,"library":"confection","title":"Confection","description":"Confection is a lightweight and flexible configuration system for Python, designed to handle complex nested configurations with features like interpolation, validation, and registry integration. It is currently at version 1.3.3 and maintains an active release cadence, often aligning with updates to related libraries like spaCy and Thinc.","status":"active","version":"1.3.3","language":"en","source_language":"en","source_url":"https://github.com/explosion/confection","tags":["configuration","config system","pydantic","registry","interpolation"],"install":[{"cmd":"pip install confection","lang":"bash","label":"Default Install"}],"dependencies":[],"imports":[{"symbol":"Config","correct":"from confection import Config"},{"symbol":"set_registry","correct":"from confection import set_registry"}],"quickstart":{"code":"from confection import Config, set_registry\n\n@set_registry(\"my_functions\", \"add\")\ndef add_function(a: int, b: int):\n    return a + b\n\nconfig = Config({\"model\": {\"func\": {\"@my_functions\": \"add\"}, \"a\": 1, \"b\": 2}})\n\nresolved = config.resolve()\nresult = resolved[\"model\"][\"func\"](resolved[\"model\"][\"a\"], resolved[\"model\"][\"b\"])\n\nprint(f\"Result: {result}\")\n\n# Example with direct config creation\nconfig_direct = Config().from_str(\"\"\"\n[model]\nfunc = @my_functions.add\na = 10\nb = 20\n\"\"\")\nresolved_direct = config_direct.resolve()\nresult_direct = resolved_direct[\"model\"][\"func\"](resolved_direct[\"model\"][\"a\"], resolved_direct[\"model\"][\"b\"])\n\nprint(f\"Direct Config Result: {result_direct}\")","lang":"python","description":"This quickstart demonstrates how to define a function in the registry, create a `Config` object, and resolve the configuration to execute the registered function with provided arguments. It also shows an example of loading a config from a string."},"warnings":[{"fix":"Review your configurations and update them to align with Confection's custom validation logic. Test thoroughly, especially if you had complex Pydantic validation schemas.","message":"Confection v1.1.0 and later dropped support for Pydantic for validation, reverting to custom validation logic. If you were relying on Pydantic's specific validation behaviors with older versions, your configurations might behave differently or break.","severity":"breaking","affected_versions":">=1.1.0"},{"fix":"Upgrade to confection v1.3.3 or later. If unable to upgrade, explicitly quote 'true', 'false', and 'null' as JSON-style lowercase literals in your config files, or ensure your consuming code handles string-based booleans/None.","message":"Prior to v1.3.3, Python-style boolean (True, False) and None literals in configuration files were silently treated as strings instead of their corresponding Python types. This could lead to type errors, especially with newer Pydantic versions.","severity":"gotcha","affected_versions":"<1.3.3"},{"fix":"For Pydantic v2 compatibility, Confection v1.0.0 and v1.0.0a2 aimed to support it. However, v1.1.0 reverted away from Pydantic entirely. The most stable approach is to use Confection v1.1.0 or newer if you wish to avoid Pydantic dependencies, or carefully test specific versions if Pydantic integration is critical.","message":"Changes in Pydantic v2 support across Confection versions (v1.0.0, v1.0.0a2, v1.1.0) could lead to compatibility issues. If you're using Pydantic in conjunction with Confection, ensure your Confection version aligns with the Pydantic version you're using.","severity":"breaking","affected_versions":"1.0.0, 1.0.0a2, 1.1.0"},{"fix":"Always validate your configuration strings carefully. Refer to the Confection documentation for the precise syntax. For older versions, be aware of potential issues with complex section references and consider upgrading to v1.2.0 or newer for bug fixes related to parsing.","message":"When using `Config.from_str()` for loading configurations, pay close attention to the YAML/INI-like syntax. Incorrect indentation or malformed sections can lead to parsing errors. For example, top-level section references have had bug fixes.","severity":"gotcha","affected_versions":"<1.2.0"}],"env_vars":null,"last_verified":"2026-04-08T00:00:00.000Z","next_check":"2026-07-07T00:00:00.000Z"}