streambricks 0.2.2__tar.gz → 0.2.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. {streambricks-0.2.2 → streambricks-0.2.4}/PKG-INFO +1 -1
  2. {streambricks-0.2.2 → streambricks-0.2.4}/src/streambricks/__init__.py +3 -1
  3. streambricks-0.2.4/src/streambricks/state.py +32 -0
  4. {streambricks-0.2.2 → streambricks-0.2.4}/src/streambricks/widgets/model_widget.py +30 -6
  5. {streambricks-0.2.2 → streambricks-0.2.4}/.copier-answers.yml +0 -0
  6. {streambricks-0.2.2 → streambricks-0.2.4}/.github/FUNDING.yml +0 -0
  7. {streambricks-0.2.2 → streambricks-0.2.4}/.github/copilot-instructions.md +0 -0
  8. {streambricks-0.2.2 → streambricks-0.2.4}/.github/dependabot.yml +0 -0
  9. {streambricks-0.2.2 → streambricks-0.2.4}/.github/workflows/build.yml +0 -0
  10. {streambricks-0.2.2 → streambricks-0.2.4}/.github/workflows/documentation.yml +0 -0
  11. {streambricks-0.2.2 → streambricks-0.2.4}/.gitignore +0 -0
  12. {streambricks-0.2.2 → streambricks-0.2.4}/.pre-commit-config.yaml +0 -0
  13. {streambricks-0.2.2 → streambricks-0.2.4}/LICENSE +0 -0
  14. {streambricks-0.2.2 → streambricks-0.2.4}/README.md +0 -0
  15. {streambricks-0.2.2 → streambricks-0.2.4}/docs/.empty +0 -0
  16. {streambricks-0.2.2 → streambricks-0.2.4}/duties.py +0 -0
  17. {streambricks-0.2.2 → streambricks-0.2.4}/mkdocs.yml +0 -0
  18. {streambricks-0.2.2 → streambricks-0.2.4}/overrides/_dummy.txt +0 -0
  19. {streambricks-0.2.2 → streambricks-0.2.4}/pyproject.toml +0 -0
  20. {streambricks-0.2.2 → streambricks-0.2.4}/src/streambricks/helpers.py +0 -0
  21. {streambricks-0.2.2 → streambricks-0.2.4}/src/streambricks/py.typed +0 -0
  22. {streambricks-0.2.2 → streambricks-0.2.4}/src/streambricks/widgets/__init__.py +0 -0
  23. {streambricks-0.2.2 → streambricks-0.2.4}/src/streambricks/widgets/model_selector.py +0 -0
  24. {streambricks-0.2.2 → streambricks-0.2.4}/src/streambricks/widgets/multi_select.py +0 -0
  25. {streambricks-0.2.2 → streambricks-0.2.4}/src/streambricks/widgets/type_helpers.py +0 -0
  26. {streambricks-0.2.2 → streambricks-0.2.4}/tests/__init__.py +0 -0
  27. {streambricks-0.2.2 → streambricks-0.2.4}/tests/conftest.py +0 -0
  28. {streambricks-0.2.2 → streambricks-0.2.4}/tests/test_widgets.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: streambricks
3
- Version: 0.2.2
3
+ Version: 0.2.4
4
4
  Summary: Streamlit widgets and helpers
5
5
  Project-URL: Documentation, https://phil65.github.io/streambricks/
6
6
  Project-URL: Source, https://github.com/phil65/streambricks
@@ -1,4 +1,4 @@
1
- __version__ = "0.2.2"
1
+ __version__ = "0.2.4"
2
2
 
3
3
 
4
4
  from streambricks.widgets.model_widget import (
@@ -11,9 +11,11 @@ from streambricks.widgets.model_selector import (
11
11
  model_selector as llm_model_selector,
12
12
  )
13
13
  from streambricks.helpers import run
14
+ from streambricks.state import State
14
15
 
15
16
  __all__ = [
16
17
  "MultiSelectItem",
18
+ "State",
17
19
  "llm_model_selector",
18
20
  "model_display",
19
21
  "model_edit",
@@ -0,0 +1,32 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Self, TypeVar
4
+
5
+ from pydantic import BaseModel
6
+ import streamlit as st
7
+
8
+
9
+ T = TypeVar("T", bound=BaseModel)
10
+
11
+
12
+ class State(BaseModel):
13
+ @classmethod
14
+ def get(cls, *, key: str | None = None) -> Self:
15
+ """Get or initialize typed state for Streamlit.
16
+
17
+ Args:
18
+ model_class: Pydantic model class defining the state structure
19
+ key: Optional key to use in session_state (defaults to model class name)
20
+
21
+ Returns:
22
+ An instance of the model representing current state
23
+ """
24
+ state_key = key or cls.__name__
25
+ if state_key not in st.session_state:
26
+ st.session_state[state_key] = cls()
27
+
28
+ current_state = st.session_state[state_key]
29
+ if not isinstance(current_state, cls):
30
+ st.session_state[state_key] = cls()
31
+
32
+ return st.session_state[state_key]
@@ -813,17 +813,23 @@ def get_field_renderer(field_info: dict[str, Any]) -> WidgetFunc[Any]: # noqa:
813
813
  raise ValueError(error_msg)
814
814
 
815
815
 
816
- def render_model_readonly[T](model_class: type[T], instance: T | None = None):
816
+ def render_model_readonly[T](
817
+ model_class: type[T],
818
+ instance: T | None = None,
819
+ exclude: set[str] | None = None,
820
+ ):
817
821
  """Render a model in read-only mode using a clean label-based layout."""
822
+ excluded_fields = exclude or set()
818
823
  if instance is None:
819
824
  st.info("No data available")
820
825
  return
821
826
 
822
- # Create a container for the model display
823
827
  with st.container():
824
828
  # Get all fields from the model
825
829
  for field in fieldz.fields(model_class):
826
830
  field_name = field.name
831
+ if field_name in excluded_fields:
832
+ continue
827
833
  field_value = getattr(instance, field_name, None)
828
834
  field_type = field.type
829
835
  label = field_name.replace("_", " ").title()
@@ -949,16 +955,30 @@ TForm = TypeVar("TForm", bound="BaseModel")
949
955
 
950
956
  @overload
951
957
  def render_model_form(
952
- model_or_instance: type[TForm], *, readonly: bool = False
958
+ model_or_instance: type[TForm],
959
+ *,
960
+ readonly: bool = False,
961
+ exclude: set[str] | None = None,
953
962
  ) -> TForm: ...
954
963
 
955
964
 
956
965
  @overload
957
- def render_model_form(model_or_instance: TForm, *, readonly: bool = False) -> TForm: ...
966
+ def render_model_form(
967
+ model_or_instance: TForm,
968
+ *,
969
+ readonly: bool = False,
970
+ exclude: set[str] | None = None,
971
+ ) -> TForm: ...
958
972
 
959
973
 
960
- def render_model_form(model_or_instance, *, readonly: bool = False) -> Any:
974
+ def render_model_form(
975
+ model_or_instance,
976
+ *,
977
+ readonly: bool = False,
978
+ exclude: set[str] | None = None,
979
+ ) -> Any:
961
980
  """Render a complete form for a model class or instance using compact layout."""
981
+ excluded_fields = exclude or set()
962
982
  if isinstance(model_or_instance, type):
963
983
  model_class = model_or_instance
964
984
  instance = model_class() # Create a default instance
@@ -967,7 +987,7 @@ def render_model_form(model_or_instance, *, readonly: bool = False) -> Any:
967
987
  model_class = instance.__class__
968
988
 
969
989
  if readonly:
970
- render_model_readonly(model_class, instance)
990
+ render_model_readonly(model_class, instance, exclude=excluded_fields)
971
991
  return instance # No changes in read-only mode
972
992
 
973
993
  result = {}
@@ -991,6 +1011,8 @@ def render_model_form(model_or_instance, *, readonly: bool = False) -> Any:
991
1011
  with tabs[i]:
992
1012
  for field in fields:
993
1013
  field_name = field.name
1014
+ if field_name in excluded_fields:
1015
+ continue
994
1016
  current_value = get_with_default(instance, field_name, field)
995
1017
  result[field_name] = render_model_field(
996
1018
  model_class, field_name, current_value
@@ -999,6 +1021,8 @@ def render_model_form(model_or_instance, *, readonly: bool = False) -> Any:
999
1021
  # Single category, render fields directly
1000
1022
  for field in fieldz.fields(model_class):
1001
1023
  field_name = field.name
1024
+ if field_name in excluded_fields:
1025
+ continue
1002
1026
  current_value = get_with_default(instance, field_name, field)
1003
1027
  result[field_name] = render_model_field(
1004
1028
  model_class, field_name, current_value
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes