{"id":6371,"library":"gin-config","title":"Gin-Config","description":"Gin provides a lightweight configuration framework for Python, based on dependency injection. Functions or classes can be decorated with @gin.configurable, allowing default parameter values to be supplied from a config file (or passed via the command line) using a simple but powerful syntax. This removes the need to define and maintain configuration objects or write boilerplate parameter plumbing and factory code, while often dramatically expanding a project's flexibility and configurability. It is particularly well suited for machine learning experiments. It is currently at version 0.5.0 and is actively maintained by Google.","status":"active","version":"0.5.0","language":"python","source_language":"en","source_url":"https://github.com/google/gin-config","tags":["configuration","dependency injection","machine learning","experiment management"],"install":[{"cmd":"pip install gin-config","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"symbol":"gin","correct":"import gin"},{"note":"The decorator is usually accessed via the top-level 'gin' import.","wrong":"from gin_config import configurable","symbol":"configurable","correct":"@gin.configurable"},{"note":"The decorator is usually accessed via the top-level 'gin' import.","wrong":"from gin_config import register","symbol":"register","correct":"@gin.register"},{"symbol":"parse_config_file","correct":"gin.parse_config_file('config.gin')"},{"symbol":"parse_config_files_and_bindings","correct":"gin.parse_config_files_and_bindings(gin_files, gin_params)"},{"symbol":"query_parameter","correct":"gin.query_parameter('my_function.param_name')"},{"symbol":"REQUIRED","correct":"def my_function(param=gin.REQUIRED):"},{"symbol":"operative_config_str","correct":"config_string = gin.operative_config_str()"}],"quickstart":{"code":"import gin\n\n# 1. Define a configurable function or class\n@gin.configurable\ndef greet(name='World', greeting='Hello'):\n    return f\"{greeting}, {name}!\"\n\n# 2. Create a config file (e.g., config.gin)\n# Save this content to a file named 'config.gin':\n# greet.name = 'Gin-Config User'\n# greet.greeting = 'Hi there'\n\n# 3. In your Python code, parse the config file\n# For demonstration, we'll use gin.parse_config_string\n# In a real application, you'd use gin.parse_config_file('config.gin')\ngin_config_content = \"\"\"\ngreet.name = 'Gin-Config User'\ngreet.greeting = 'Hi there'\n\"\"\"\ngin.parse_config_string(gin_config_content)\n\n# 4. Call the configurable function\n# Gin will automatically inject parameters from the config\nresult = greet()\nprint(result)\n\n# You can still override configured values by passing arguments directly\nresult_override = greet(name='Developer')\nprint(result_override)\n\n# Clear configurations (useful for testing or multiple configurations)\ngin.clear_config()\n\n# Demonstrate gin.REQUIRED\n@gin.configurable\ndef show_required(value=gin.REQUIRED):\n    return f\"Required value: {value}\"\n\n# Try to call without configuring or providing 'value'\ntry:\n    show_required()\nexcept ValueError as e:\n    print(f\"Expected error for missing required parameter: {e}\")\n\n# Configure and call\ngin.parse_config_string(\"show_required.value = 42\")\nprint(show_required())\n\n","lang":"python","description":"To get started with Gin-Config, you define functions or classes that you want to make configurable by decorating them with `@gin.configurable`. You then create a `.gin` configuration file where you specify parameter bindings using a `function_name.parameter_name = value` syntax. Finally, you parse this configuration file in your Python application using `gin.parse_config_file()`, and Gin-Config automatically injects the configured values when the decorated functions or classes are called."},"warnings":[{"fix":"Always use `pip install gin-config` for the Python library and refer to the official GitHub repository `google/gin-config` for documentation. When searching, be specific (e.g., 'gin-config python').","message":"Confusion with 'gin-gonic/gin' (Go framework). There is a popular Go web framework also named 'Gin'. Ensure you are installing and referencing `gin-config` (for Python) and not the Go project.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Choose the appropriate decorator based on whether you want direct calls to respect Gin's configuration or only indirect/referenced calls.","message":"Distinction between `@gin.configurable` and `@gin.register`. Functions decorated with `@gin.configurable` will have their parameters overridden by Gin configurations even when called directly from other Python code. Functions with `@gin.register` will *not* have their parameters overridden when called directly; configurations only apply when they are referenced using the `@some_name` syntax within config files or other Gin contexts.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Prefer `my_function(param=gin.REQUIRED)` when defining configurable functions if a parameter must always be supplied by Gin or the caller. Consider passing `gin.REQUIRED` at the call site for greater flexibility in some scenarios.","message":"Handling required parameters with `gin.REQUIRED`. While `gin.REQUIRED` can be used as a default value in a function signature, it is generally more flexible and often preferred to provide `gin.REQUIRED` at the call site if the function might be called multiple times with different requirements.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Pre-calculate any necessary arithmetic values in your Python code before parsing or provide the final numeric literals directly in the `.gin` configuration file.","message":"Arithmetic expressions are not supported in Gin config files. While the configuration syntax is Python-like and supports literals, comments, and line continuation, it does not evaluate arithmetic expressions.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Suppress the `unused-import` pylint warning for modules containing multiple configurable items, or structure your code to minimize the number of configurable items within a single module.","message":"Pylint warnings for unused imports with configurable items. When using `@gin.configurable` or `@gin.register`, you must import all functions/classes that might be configured, even if only one is selected at runtime via the config. This can lead to `pylint` flagging 'unused imports'.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'0.5.0':89 'activ':92 'allow':24 'base':12 'boilerpl':59 'class':18 'code':64 'command':39 'config':3,33 'configur':8,55,74,96 'current':86 'decor':21 'default':25 'defin':52 'depend':14,97 'dramat':67 'expand':68 'experi':83,101 'factori':63 'file':34 'flexibl':72 'framework':9 'function':16 'gin':2,4 'gin-config':1 'gin.configurable':23 'googl':95 'inject':15,98 'learn':82,100 'lightweight':7 'line':40 'machin':81,99 'maintain':54,93 'manag':102 'need':50 'object':56 'often':66 'paramet':26,60 'particular':77 'pass':36 'plumb':61 'power':45 'project':70 'provid':5 'python':11 'remov':48 'simpl':43 'suit':79 'suppli':30 'syntax':46 'use':41 'valu':27 'version':88 'via':37 'well':78 'write':58","created_at":"2026-04-15T05:34:23.690952+00:00","updated_at":"2026-04-16T15:16:22.203105+00:00","problems":[{"fix":"Ensure `gin-config` is installed (`pip install gin-config`). The primary module is `gin.config`, so use `import gin.config` or decorate functions/classes with `@gin.configurable`. If trying to import `gin.tf` or `gin.torch`, verify that the `tensorflow` or `torch` integrations for `gin-config` are correctly installed and that the modules exist in your current `gin-config` version. Often, just importing `gin.config` is sufficient, or installing `gin-config` as `pip install -U gin-config` for the latest version.","cause":"The `gin-config` package is installed, but users attempt to import it using `import gin` instead of `import gin.config` or by importing specific submodules like `gin.tf` or `gin.torch` when those submodules are not part of the installed `gin-config` or have been moved/removed in newer versions.","error":"ModuleNotFoundError: No module named 'gin'"},{"fix":"Ensure that all functions and classes that are intended to be configurable by `gin-config` are decorated with `@gin.configurable` and that their containing modules are imported *before* `gin.parse_config_file()` or `gin.parse_config_string()` is called.","cause":"This error occurs when `gin.parse_config_file()` or `gin.parse_config_string()` is called, but the configurable function or class referenced in the configuration (e.g., 'my_function' in `my_function.param = value`) has not yet been defined with `@gin.configurable` or imported into the current execution scope.","error":"ValueError: No configurable matching 'my_function'"},{"fix":"Update the `.gin` configuration file to reflect the current parameters of the configurable function or class. Alternatively, if the parameter is optional and no longer needed, remove its entry from the configuration file. If the parameter genuinely no longer exists in the code and you are loading an older config, consider using `skip_unknown=True` with `gin.parse_config_file()` if applicable, though it's generally better to align config and code.","cause":"This error indicates a mismatch between the configuration file and the Python code. A parameter is specified in the `.gin` config file for a configurable function or class, but that parameter does not exist in the definition of the function or class. This commonly happens after refactoring code where parameters are renamed or removed, but the configuration file is not updated.","error":"ValueError: Configurable 'FunctionName' doesn't have a parameter named 'param_name'"},{"fix":"Ensure all `gin.bind_parameter()` calls and `gin.parse_config_file()` (or `parse_config_string()`) calls occur before `gin.finalize()`. If modifications are truly needed after finalization, you can temporarily unlock the configuration using a context manager: `with gin.unlock_config(): # modify config here`.","cause":"The `gin-config` system has been 'finalized' by calling `gin.finalize()` to prevent further modifications, but a subsequent attempt is made to bind or re-bind parameters.","error":"RuntimeError: Attempted to modify locked Gin config."},{"fix":"Provide a value for the missing required parameter. This can be done in the `.gin` configuration file (e.g., `MyConfigurable.parameter_name = 'value'`), by calling `gin.bind_parameter('MyConfigurable.parameter_name', 'value')`, or directly when calling the configurable function or instantiating the class.","cause":"A configurable function or class has a parameter explicitly marked as `gin.REQUIRED` (e.g., `param=gin.REQUIRED`), but no value for this parameter has been provided either in the call site, the gin configuration, or a default binding.","error":"Missing required parameter: [parameter_name]"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.5.0","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/google/gin-config","docs":"https://github.com/google/gin-config/docs","changelog":null,"pypi":"https://pypi.org/project/gin-config/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["ai-ml","devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-28","install_tag":null}}