notionhelper 0.3.0__py3-none-any.whl → 0.3.1__py3-none-any.whl

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.
notionhelper/helper.py CHANGED
@@ -655,7 +655,51 @@ class NotionHelper:
655
655
  response = requests.patch(update_url, headers=headers, json=data)
656
656
  return response.json()
657
657
 
658
+ def dict_to_notion_schema(self, data: Dict[str, Any], title_key: str) -> Dict[str, Any]:
659
+ """Converts a dictionary into a Notion property schema for database creation.
660
+
661
+ Parameters:
662
+ data (dict): Dictionary containing sample values to infer types from.
663
+ title_key (str): The key that should be used as the title property.
664
+
665
+ Returns:
666
+ dict: A dictionary defining the Notion property schema.
667
+ """
668
+ properties = {}
669
+
670
+ for key, value in data.items():
671
+ # Handle NumPy types
672
+ if hasattr(value, "item"):
673
+ value = value.item()
674
+
675
+ # Debug output to help diagnose type issues
676
+ print(f"DEBUG: key='{key}', value={value}, type={type(value).__name__}, isinstance(bool)={isinstance(value, bool)}, isinstance(int)={isinstance(value, int)}")
677
+
678
+ if key == title_key:
679
+ properties[key] = {"title": {}}
680
+ # IMPORTANT: Check for bool BEFORE (int, float) because bool is a subclass of int in Python
681
+ elif isinstance(value, bool):
682
+ properties[key] = {"checkbox": {}}
683
+ print(f" → Assigned as CHECKBOX")
684
+ elif isinstance(value, (int, float)):
685
+ properties[key] = {"number": {"format": "number"}}
686
+ print(f" → Assigned as NUMBER")
687
+ else:
688
+ properties[key] = {"rich_text": {}}
689
+ print(f" → Assigned as RICH_TEXT")
690
+
691
+ return properties
692
+
658
693
  def dict_to_notion_props(self, data: Dict[str, Any], title_key: str) -> Dict[str, Any]:
694
+ """Converts a dictionary into Notion property values for page creation.
695
+
696
+ Parameters:
697
+ data (dict): Dictionary containing the values to convert.
698
+ title_key (str): The key that should be used as the title property.
699
+
700
+ Returns:
701
+ dict: A dictionary defining the Notion property values.
702
+ """
659
703
  notion_props = {}
660
704
  for key, value in data.items():
661
705
  # Handle NumPy types
@@ -759,29 +803,19 @@ class NotionHelper:
759
803
  def create_ml_database(self, parent_page_id: str, db_title: str, config: Dict, metrics: Dict, file_property_name: str = "Output Files") -> str:
760
804
  """
761
805
  Analyzes dicts to create a new Notion Database with the correct schema.
806
+ Uses dict_to_notion_schema() for universal type conversion.
762
807
  """
763
- # --- ENSURE ALL LINES BELOW ARE INDENTED BY 8 SPACES (assuming 4 for class) ---
764
808
  combined = {**config, **metrics}
765
809
  title_key = list(config.keys())[0]
766
810
 
767
- properties = {}
768
-
769
- # 1. Map dictionary keys to Notion Property Types
770
- for key, value in combined.items():
771
- if key == title_key:
772
- properties[key] = {"title": {}}
773
- elif isinstance(value, (int, float)):
774
- properties[key] = {"number": {"format": "number"}}
775
- elif isinstance(value, bool):
776
- properties[key] = {"checkbox": {}}
777
- else:
778
- properties[key] = {"rich_text": {}}
811
+ # Use the universal dict_to_notion_schema() method
812
+ properties = self.dict_to_notion_schema(combined, title_key)
779
813
 
780
- # 2. Add 'Run Status'
814
+ # Add 'Run Status' if not already present
781
815
  if "Run Status" not in properties:
782
816
  properties["Run Status"] = {"rich_text": {}}
783
817
 
784
- # 3. Add the Multi-file property
818
+ # Add the Multi-file property
785
819
  properties[file_property_name] = {"files": {}}
786
820
 
787
821
  print(f"Creating database '{db_title}' with {len(properties)} columns...")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: notionhelper
3
- Version: 0.3.0
3
+ Version: 0.3.1
4
4
  Summary: NotionHelper is a Python library that simplifies interactions with the Notion API, enabling easy management of databases, pages, and files within Notion workspaces.
5
5
  Author-email: Jan du Plessis <drjanduplessis@icloud.com>
6
6
  Requires-Python: >=3.10
@@ -27,7 +27,7 @@ Description-Content-Type: text/markdown
27
27
 
28
28
  # NotionHelper
29
29
 
30
- ![NotionHelper](https://github.com/janduplessis883/notionhelper/blob/master/images/helper_logo.png?raw=true)
30
+ ![NotionHelper](https://github.com/janduplessis883/notionhelper/blob/master/images/notionh3.png?raw=true)
31
31
 
32
32
  `NotionHelper` is a Python library that provides a convenient interface for interacting with the Notion API, specifically designed to leverage the **Notion API Version 2025-09-03**. It simplifies common tasks such as managing databases, data sources, pages, and file uploads, allowing you to integrate Notion's powerful features into your applications with ease.
33
33
 
@@ -0,0 +1,5 @@
1
+ notionhelper/__init__.py,sha256=_ShvAiiI4rspEoAjP71AHLPL1wrmcIlDBn0YUSqSMi8,61
2
+ notionhelper/helper.py,sha256=NJdthOSNIqp1ESaDkV-V1Kb2x35LcQlAfG-KTyDnEl8,36279
3
+ notionhelper-0.3.1.dist-info/METADATA,sha256=NcMT0DgyLX096LdLa5UGlUOg184bmGuWT2eiJkwxkGo,19906
4
+ notionhelper-0.3.1.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
5
+ notionhelper-0.3.1.dist-info/RECORD,,
@@ -1,5 +0,0 @@
1
- notionhelper/__init__.py,sha256=_ShvAiiI4rspEoAjP71AHLPL1wrmcIlDBn0YUSqSMi8,61
2
- notionhelper/helper.py,sha256=KYF3o9-ItooavhnqFC0geM41bA1fHv_oZNL1SQuCmsA,34780
3
- notionhelper-0.3.0.dist-info/METADATA,sha256=JgI1O1nhmQ68knnYL46e79kZMLApQzBzD04Fxlx1Vb0,19909
4
- notionhelper-0.3.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
5
- notionhelper-0.3.0.dist-info/RECORD,,