This release is a pre-release and may not be stable for production use.
Zookeeper
A small library for configuring modular applications.
Installation
pip install zookeeper
Components
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()
p.configure({
"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.
print(p)
>>> 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
@add_task_to_cli
class UseChildA(Task):
parent: ParentComponent
def run(self):
print(self.parent.child.a)
@add_task_to_cli
class UseParentA(UseChildA):
def run(self):
print(self.parent.a)
if __name__ == "__main__":
cli()
Running the above file then gives a nice CLI interface:
python test.py use_child_a
>>> ValueError: No configuration value found for annotated parameter 'UseChildA.parent.a' of type 'int'.
python test.py use_child_a a=5
>>> 5
python test.py use_child_a a=5 child.a=3
>>> 3
python test.py use_parent_a a=5 child.a=3
>>> 5
Using Zookeeper to define Larq or Keras experiments
See examples/larq_experiment.py 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.
Metadata
Release files for zookeeper 1.0.dev4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| zookeeper-1.0.dev4.tar.gz | 16.6 kB | Without provenance | Details for zookeeper-1.0.dev4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| zookeeper-1.0.dev4-py3-none-any.whl | Python 3 | none | any | Details for zookeeper-1.0.dev4-py3-none-any.whl |
Total release size: 39.3 kB
Release files / zookeeper-1.0.dev4.tar.gz
| Download URL | zookeeper-1.0.dev4.tar.gz |
|---|---|
| Size | 16.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d09a7e010adfb4a0b561d2537109182d2aaef53710d0eba4bd18e15c0871493c
|
|
BLAKE2b-256 checksum How to use checksums |
9ba4ec743ef709ea51aedf966b1ddb1976e0587cbacbdcb9cc9807f2ae6141c5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.5
|
Release files / zookeeper-1.0.dev4-py3-none-any.whl
| Download URL | zookeeper-1.0.dev4-py3-none-any.whl |
|---|---|
| Size | 22.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fb9d53710c986b15213850091b738a21de8c4e6864e2e0890ac798c4f583f804
|
|
BLAKE2b-256 checksum How to use checksums |
52c04880c4c3456acf32ec5412f9599dcc870927c7f2951c9aa07b505c1e5317
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.5
|
Security for zookeeper 1.0.dev4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.