Skip to main content

A small library for managing deep learning models, hyper parameters and datasets

Project description


GitHub Actions Codecov PyPI - Python Version PyPI PyPI - License Code style: black Join the community on Spectrum

A small library for configuring modular applications.


pip install zookeeper


The fundamental building block of Zookeeper is a Component. Component subclasses can have configurable parameters, which are declared using class-level type annotations (in a similar way to Python dataclasses). These parameters can be Python objects or nested sub-components, and need not be set with a default value.

For example:

from zookeeper import Component

class ChildComponent(Component):
    a: int                  # An `int` parameter, with no default set
    b: str = "foo"          # A `str` parameter, which by default will be `foo`

class ParentComponent(Component):
    a: int                  # The same `int` parameter as the child
    child: ChildComponent   # A nested component parameter, of type `ChildComponent`

After instantiation, components can be 'configured' with a configuration dictionary, containing values for a tree of nested parameters. This process automatically injects the correct values into each parameter.

If a child sub-component declares a parameter which already exists in some containing parent, then it will pick up the value that's set on the parent, unless a 'scoped' value is set on the child.

For example:

p = ParentComponent()

    "a": 5,
    "child.a": 4,

>>> 'ChildComponent' is the only concrete component class that satisfies the type
>>> of the annotated parameter 'ParentComponent.child'. Using an instance of this
>>> class by default.


>>> ParentComponent(
>>>     a = 5,
>>>     child = ChildComponent(
>>>         a = 4,
>>>         b = "foo"
>>>     )
>>> )

Tasks and the CLI

The best way to define runnable tasks with Zookeeper is to subclass Task and override the run method.

Zookeeper provides a small mechanism to run tasks from a CLI, using the decorator @add_task_to_cli. The CLI will automatically instantiate the task and call configure(), passing in configuration parsed from command line arguments.

For example:

from zookeeper import Task
from zookeeper.cli import add_task_to_cli, cli

class UseChildA(Task):
    parent: ParentComponent

    def run(self):

class UseParentA(UseChildA):
    def run(self):

if __name__ == "__main__":

Running the above file then gives a nice CLI interface:

python use_child_a
>>> ValueError: No configuration value found for annotated parameter 'UseChildA.parent.a' of type 'int'.

python use_child_a a=5
>>> 5

python use_child_a a=5 child.a=3
>>> 3

python use_parent_a a=5 child.a=3
>>> 5

Using Zookeeper to define Larq or Keras experiments

See examples/ for an example of how to use Zookeeper to define all the necessary components (dataset, preprocessing, and model) of a Larq experiment: training a BinaryNet on CIFAR-10. This example can be easily adapted to other Larq or Keras models and other datasets.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for zookeeper, version 1.0.dev2
Filename, size File type Python version Upload date Hashes
Filename, size zookeeper-1.0.dev2-py3-none-any.whl (21.1 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size zookeeper-1.0.dev2.tar.gz (15.2 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page