github manzt/anywidget anywidget@0.7.0

latest releases: create-anywidget@0.7.5, create-anywidget@0.7.3, create-anywidget@0.7.2...
13 months ago

Minor Changes

  • feat(experimental)!: Require include in _get_anywidget_state signature (#317)

    Allows implementors to avoid re-serializing fields which aren't needed to send
    to the front end. This is a BREAKING change because it requires implementors
    of _get_anywidget_state to account for include in the function signature.

    from dataclasses import dataclass, asdict
    from io import BytesIO
    
    import polars as pl
    import psygnal
    
    @psygnal.evented
    @dataclass
    class Foo:
      value: int
      df: pl.DataFrame
    
      def _get_anywidget_state(self, include: set[str] | None):
        data = asdict(self)
        if include and "df" in include:
          with BytesIO() as f:
            self.df.write_ipc(f)
            data["df"] = f.getvalue()
        else:
          del data["df"] # don't serialize df to bytes
        return data

Don't miss a new anywidget release

NewReleases is sending notifications on new releases.