{"id":7460,"library":"objectory","title":"Objectory","description":"Objectory is a lightweight Python library (version 0.3.1) designed for general-purpose object factories. It focuses on dynamic object factory implementations, allowing objects to be registered and instantiated from their configuration without altering the factory's core code. The library supports both abstract factory and registry patterns. As it is currently in a development stage (pre-1.0.0), the API may experience frequent changes.","status":"active","version":"0.3.1","language":"en","source_language":"en","source_url":"https://github.com/durandtibo/objectory","tags":["object factory","design pattern","factory pattern","dependency injection","registry","instantiation"],"install":[{"cmd":"pip install objectory","lang":"bash","label":"Install latest stable version"}],"dependencies":[{"reason":"Requires Python 3.10 or newer.","package":"python","optional":false}],"imports":[{"symbol":"factory","correct":"from objectory import factory"},{"symbol":"AbstractFactory","correct":"from objectory import AbstractFactory"},{"symbol":"Registry","correct":"from objectory import Registry"}],"quickstart":{"code":"from objectory import factory, AbstractFactory, Registry\n\n# 1. Basic factory usage with a built-in type\nobj_list = factory(\"builtins.list\")\nprint(f\"Created list: {obj_list}\")\nobj_list_init = factory(\"builtins.list\", [1, 2, 3])\nprint(f\"Created list with data: {obj_list_init}\")\n\n# 2. AbstractFactory pattern\nclass BaseProduct(metaclass=AbstractFactory):\n    pass\n\nclass ConcreteProductA(BaseProduct):\n    def __init__(self, name=\"ProductA\"):\n        self.name = name\n\nclass ConcreteProductB(BaseProduct):\n    def __init__(self, value=100):\n        self.value = value\n\nproduct_a = BaseProduct.factory(\"ConcreteProductA\", name=\"SpecialA\")\nprint(f\"Created product A: {product_a.name}\")\nproduct_b = BaseProduct.factory(\"ConcreteProductB\")\nprint(f\"Created product B value: {product_b.value}\")\n\n# 3. Registry pattern\nmy_registry = Registry()\n\n@my_registry.register()\nclass RegisteredClass:\n    def __init__(self, message=\"Hello from registry!\"):\n        self.message = message\n\nregistered_instance = my_registry.factory(\"RegisteredClass\", message=\"Dynamic message!\")\nprint(f\"Created registered instance: {registered_instance.message}\")","lang":"python","description":"Demonstrates the three main ways to use Objectory: direct factory instantiation, abstract factory inheritance, and dynamic class registration with a Registry."},"warnings":[{"fix":"Always review the changelog and release notes when upgrading to new versions, and thoroughly test your application. Pin exact versions in your `requirements.txt`.","message":"Objectory is in a pre-1.0.0 development stage, and its API is not guaranteed to be stable. Upgrading to new versions may introduce breaking changes, requiring code modifications.","severity":"breaking","affected_versions":"<1.0.0"},{"fix":"Double-check the string path for accuracy. For custom classes, ensure the module containing them has been imported at some point before the factory attempts to instantiate them, or that the classes are directly registered if using `Registry`.","message":"When using `factory` with string identifiers (e.g., 'module.ClassName'), ensure the specified module is importable and the class/function exists within it. Incorrect paths or missing imports will lead to runtime errors.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Run `pip install objectory` to install the library.","cause":"The 'objectory' package is not installed in your current Python environment.","error":"ModuleNotFoundError: No module named 'objectory'"},{"fix":"Verify that 'NonExistentClass' is correctly spelled, accessible in the current scope, or properly registered with the `Registry` or `AbstractFactory` base class.","cause":"The string identifier passed to `factory` or `Registry.factory` does not correspond to an existing or registered class/function.","error":"ValueError: Cannot create object for type 'NonExistentClass'"},{"fix":"Ensure that the `*args` and `**kwargs` passed to the factory method align with the constructor requirements of the target class.","cause":"The arguments provided to `factory` (or `AbstractFactory.factory`, `Registry.factory`) do not match the `__init__` signature of the class being instantiated.","error":"TypeError: __init__() missing X required positional arguments"}]}