py-ipv8
py-ipv8 copied to clipboard
Supply Pydantic configuration model
To enable any and all configuration of IPv8, an IPv8
instance should always be configured through a dict
. Pydantic is one of the most popular configuration management tools available and it can also create a dict
. Therefore, Pydantic be used with IPv8. However, programmers have to define their own Pydantic model to fit the IPv8 configuration dict
to use Pydantic.
To avoid excessive recreation of Pydantic models, IPv8 can supply a pre-made Pydantic model. Of course, to keep IPv8 lightweight and all non-essential dependencies optional, this model should only be supplied if pydantic
is available on the system running IPv8.
An example that highlights the envisioned usage is as follows.
from ipv8.configuration import ConfigBuilder # Should be fine if `import pydantic` fails
from ipv8.configuration import IPv8Model # Errors out if `import pydantic` fails
m = IPv8Model(logger={'level': "ERROR"}
ipv8_instance = IPv8(m.dict()) # Keep the interface clean: IPv8(m) should never be supported