@@ -33,6 +33,7 @@ class CVec:
3333 _refresh_token : Optional [str ]
3434 _publishable_key : Optional [str ]
3535 _api_key : Optional [str ]
36+ _tenant_id : int
3637
3738 def __init__ (
3839 self ,
@@ -64,8 +65,8 @@ def __init__(
6465 "CVEC_API_KEY must be set either as an argument or environment variable"
6566 )
6667
67- # Fetch publishable key from host config
68- self ._publishable_key = self ._fetch_publishable_key ()
68+ # Fetch config ( publishable key and tenant ID)
69+ self ._publishable_key = self ._fetch_config ()
6970
7071 # Handle authentication
7172 email = self ._construct_email_from_api_key ()
@@ -485,15 +486,17 @@ def _refresh_supabase_token(self) -> None:
485486 self ._access_token = data ["access_token" ]
486487 self ._refresh_token = data ["refresh_token" ]
487488
488- def _fetch_publishable_key (self ) -> str :
489+ def _fetch_config (self ) -> str :
489490 """
490- Fetch the publishable key from the host's config endpoint.
491+ Fetch configuration from the host's config endpoint.
492+
493+ Sets the tenant_id on the instance and returns the publishable key.
491494
492495 Returns:
493496 The publishable key from the config response
494497
495498 Raises:
496- ValueError: If the config endpoint is not accessible or doesn't contain the key
499+ ValueError: If the config endpoint is not accessible or doesn't contain required fields
497500 """
498501 try :
499502 config_url = f"{ self .host } /config"
@@ -504,10 +507,14 @@ def _fetch_publishable_key(self) -> str:
504507 config_data = json .loads (response_data .decode ("utf-8" ))
505508
506509 publishable_key = config_data .get ("supabasePublishableKey" )
510+ tenant_id = config_data .get ("tenantId" )
507511
508512 if not publishable_key :
509513 raise ValueError (f"Configuration fetched from { config_url } is invalid" )
514+ if tenant_id is None :
515+ raise ValueError (f"tenantId not found in config from { config_url } " )
510516
517+ self ._tenant_id = int (tenant_id )
511518 return str (publishable_key )
512519
513520 except (HTTPError , URLError ) as e :
@@ -646,19 +653,16 @@ def make_query_request() -> Any:
646653 raise e
647654 raise
648655
649- def get_eav_tables (self , tenant_id : int ) -> List [EAVTable ]:
656+ def get_eav_tables (self ) -> List [EAVTable ]:
650657 """
651- Get all EAV tables for a tenant.
652-
653- Args:
654- tenant_id: The tenant ID to query tables for
658+ Get all EAV tables for the tenant.
655659
656660 Returns:
657661 List of EAVTable objects
658662 """
659663 response_data = self ._query_table (
660664 "eav_tables" ,
661- {"tenant_id" : f"eq.{ tenant_id } " , "order" : "name" },
665+ {"tenant_id" : f"eq.{ self . _tenant_id } " , "order" : "name" },
662666 )
663667 return [EAVTable .model_validate (table ) for table in response_data ]
664668
@@ -680,7 +684,6 @@ def get_eav_columns(self, table_id: str) -> List[EAVColumn]:
680684
681685 def select_from_eav_id (
682686 self ,
683- tenant_id : int ,
684687 table_id : str ,
685688 column_ids : Optional [List [str ]] = None ,
686689 filters : Optional [List [EAVFilter ]] = None ,
@@ -692,7 +695,6 @@ def select_from_eav_id(
692695 interface using names, see select_from_eav().
693696
694697 Args:
695- tenant_id: The tenant ID to query data for
696698 table_id: The UUID of the EAV table to query
697699 column_ids: Optional list of column IDs to include in the result.
698700 If None, all columns are returned.
@@ -715,7 +717,6 @@ def select_from_eav_id(
715717 ... EAVFilter(column_id="z09PL", string_value="ACTIVE"),
716718 ... ]
717719 >>> rows = client.select_from_eav_id(
718- ... tenant_id=1,
719720 ... table_id="550e8400-e29b-41d4-a716-446655440000",
720721 ... column_ids=["MTnaC", "z09PL", "ZNAGI"],
721722 ... filters=filters,
@@ -742,7 +743,7 @@ def select_from_eav_id(
742743 filters_json .append (filter_dict )
743744
744745 params : Dict [str , Any ] = {
745- "tenant_id" : tenant_id ,
746+ "tenant_id" : self . _tenant_id ,
746747 "table_id" : table_id ,
747748 "column_ids" : column_ids ,
748749 "filters" : filters_json ,
@@ -753,7 +754,6 @@ def select_from_eav_id(
753754
754755 def select_from_eav (
755756 self ,
756- tenant_id : int ,
757757 table_name : str ,
758758 column_names : Optional [List [str ]] = None ,
759759 filters : Optional [List [EAVFilter ]] = None ,
@@ -765,7 +765,6 @@ def select_from_eav(
765765 select_from_eav_id(). For direct ID access, use select_from_eav_id().
766766
767767 Args:
768- tenant_id: The tenant ID to query data for
769768 table_name: The name of the EAV table to query
770769 column_names: Optional list of column names to include in the result.
771770 If None, all columns are returned.
@@ -788,7 +787,6 @@ def select_from_eav(
788787 ... EAVFilter(column_name="Status", string_value="ACTIVE"),
789788 ... ]
790789 >>> rows = client.select_from_eav(
791- ... tenant_id=1,
792790 ... table_name="BT/Scrap Entry",
793791 ... column_names=["Weight", "Status", "Is Verified"],
794792 ... filters=filters,
@@ -797,10 +795,14 @@ def select_from_eav(
797795 # Look up the table ID from the table name
798796 tables_response = self ._query_table (
799797 "eav_tables" ,
800- {"tenant_id" : f"eq.{ tenant_id } " , "name" : f"eq.{ table_name } " , "limit" : "1" },
798+ {
799+ "tenant_id" : f"eq.{ self ._tenant_id } " ,
800+ "name" : f"eq.{ table_name } " ,
801+ "limit" : "1" ,
802+ },
801803 )
802804 if not tables_response :
803- raise ValueError (f"Table '{ table_name } ' not found for tenant { tenant_id } " )
805+ raise ValueError (f"Table '{ table_name } ' not found" )
804806 table_id = tables_response [0 ]["id" ]
805807
806808 # Get all columns for the table to build name <-> id mappings
@@ -846,7 +848,6 @@ def select_from_eav(
846848
847849 # Call the ID-based method
848850 response_data = self .select_from_eav_id (
849- tenant_id = tenant_id ,
850851 table_id = table_id ,
851852 column_ids = column_ids ,
852853 filters = id_filters ,
0 commit comments