Exposing simple ways to render pydantic models in notebooks and other interactive computing environments.
Table of Contents
pip install spork
I created this module because I wanted a simple way to describe how to render pydantic models, especially when streaming in data to update a model. Wouldn't it be nice to see a visual display of the model as it's being updated?
To explore this space a bit, I've created a View
and an AutoView
. This lets you update fields and have them update within the notebook.
You can use existing pydantic models or create new ones by inheriting from AutoView
:
from spork import AutoView
from pydantic import BaseModel
class Record(BaseModel):
name: str
age: int
class RecordView(Record, AutoView):
def render(self):
return f"<b>{self.name}</b> is {self.age} years old."
rv = RecordView(name="Kyle", age=35)
rv.display()
When using an AutoView
, you can update the fields and the view will update wherever you ran .display()
rv.age = 101
spork
is distributed under the terms of the MIT license.