Skip to content

Home

CI Nightly Tests Nightly Package Tests
Documentation Documentation
Codecov
Code style: black Doc style: google Ruff Doc style: google
PYPI version Python BSD-3-Clause
Downloads Monthly downloads

Overview

A Python library for general purpose object factories. In particular, it focuses on dynamic object factory implementations where objects can be registered dynamically without changing the code of the factory. An object factory can be used to instantiate an object from its configuration. The current implementation contains both abstract factory and registry approaches.

factory

from objectory import factory


class MyClass:
    pass


obj = factory("MyClass")
print(obj)

abstract factory

from objectory import AbstractFactory


class BaseClass(metaclass=AbstractFactory):
    pass


class MyClass(BaseClass):
    pass


obj = BaseClass.factory("MyClass")
print(obj)

Output:

<__main__.MyClass object at 0x...>

registry

from objectory import Registry

registry = Registry()


@registry.register()
class MyClass:
    pass


obj = registry.factory("MyClass")
print(obj)
<__main__.MyClass object at 0x...>

API stability

⚠ While objectory is in development stage, no API is guaranteed to be stable from one release to the next. In fact, it is very likely that the API will change multiple times before a stable 1.0.0 release. In practice, this means that upgrading objectory to a new version will possibly break any code that was using the old version of objectory.

License

objectory is licensed under BSD 3-Clause "New" or "Revised" license available in LICENSE file.