moose-lib 0.4.232__py3-none-any.whl → 0.4.234__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.
@@ -44,6 +44,8 @@ from .ingest_pipeline import (
44
44
  from .consumption import (
45
45
  EgressConfig,
46
46
  ConsumptionApi,
47
+ get_moose_base_url,
48
+ set_moose_base_url,
47
49
  )
48
50
 
49
51
  from .sql_resource import (
@@ -115,6 +117,8 @@ __all__ = [
115
117
  # Consumption
116
118
  'EgressConfig',
117
119
  'ConsumptionApi',
120
+ 'get_moose_base_url',
121
+ 'set_moose_base_url',
118
122
 
119
123
  # SQL
120
124
  'SqlResource',
@@ -141,4 +145,4 @@ __all__ = [
141
145
  'get_sql_resource',
142
146
  'get_workflows',
143
147
  'get_workflow',
144
- ]
148
+ ]
@@ -4,13 +4,42 @@ Consumption (Egress) API definitions for Moose Data Model v2 (dmv2).
4
4
  This module provides classes for defining and configuring consumption APIs
5
5
  that allow querying data through user-defined functions.
6
6
  """
7
- from typing import Any, Callable, Optional, Tuple
7
+ import os
8
+ from typing import Any, Callable, Optional, Tuple, Generic
9
+
10
+ import requests
8
11
  from pydantic import BaseModel
9
12
  from pydantic.json_schema import JsonSchemaValue
10
13
 
11
14
  from .types import BaseTypedResource, T, U
12
15
  from ._registry import _egress_apis
13
16
 
17
+ # Global base URL configuration
18
+ _global_base_url: Optional[str] = None
19
+
20
+
21
+ def set_moose_base_url(url: str) -> None:
22
+ """Set the global base URL for consumption API calls.
23
+
24
+ Args:
25
+ url: The base URL to use for API calls
26
+ """
27
+ global _global_base_url
28
+ _global_base_url = url
29
+
30
+
31
+ def get_moose_base_url() -> Optional[str]:
32
+ """Get the configured base URL from global setting or environment variable.
33
+
34
+ Returns:
35
+ The base URL if configured, None otherwise
36
+ """
37
+ # Priority: programmatically set > environment variable
38
+ if _global_base_url:
39
+ return _global_base_url
40
+ return os.getenv('MOOSE_BASE_URL')
41
+
42
+
14
43
  class EgressConfig(BaseModel):
15
44
  """Configuration for Consumption (Egress) APIs.
16
45
 
@@ -21,7 +50,8 @@ class EgressConfig(BaseModel):
21
50
  version: Optional[str] = None
22
51
  metadata: Optional[dict] = None
23
52
 
24
- class ConsumptionApi(BaseTypedResource):
53
+
54
+ class ConsumptionApi(BaseTypedResource, Generic[U]):
25
55
  """Represents a Consumption (Egress) API endpoint.
26
56
 
27
57
  Allows querying data, typically powered by a user-defined function.
@@ -98,4 +128,50 @@ class ConsumptionApi(BaseTypedResource):
98
128
  from pydantic.type_adapter import TypeAdapter
99
129
  return TypeAdapter(self.return_type).json_schema(
100
130
  ref_template='#/components/schemas/{model}'
101
- )
131
+ )
132
+
133
+ def call(self, params: T, base_url: Optional[str] = None) -> U:
134
+ """Call the consumption API with the given parameters.
135
+
136
+ Args:
137
+ params: Parameters matching the input model T
138
+ base_url: Optional base URL override. If not provided, uses the global
139
+ base URL set via set_base_url() or MOOSE_BASE_URL environment variable.
140
+
141
+ Returns:
142
+ Response data matching the output model U
143
+
144
+ Raises:
145
+ ValueError: If no base URL is configured
146
+ """
147
+ # Determine which base URL to use
148
+ effective_base_url = base_url or get_moose_base_url()
149
+ if not effective_base_url:
150
+ raise ValueError(
151
+ "No base URL configured. Set it via set_base_url(), "
152
+ "MOOSE_BASE_URL environment variable, or pass base_url parameter."
153
+ )
154
+
155
+ # Construct the API endpoint URL
156
+ url = f"{effective_base_url.rstrip('/')}/consumption/{self.name}"
157
+
158
+ # Convert Pydantic model to dictionary
159
+ params_dict = params.model_dump()
160
+
161
+ # Build query parameters, handling lists as repeated params
162
+ query_params = []
163
+ for key, value in params_dict.items():
164
+ if isinstance(value, list):
165
+ # For list values, add each item as a separate query param
166
+ for item in value:
167
+ query_params.append((key, str(item)))
168
+ elif value is not None:
169
+ query_params.append((key, str(value)))
170
+
171
+ # Make the HTTP request
172
+ response = requests.get(url, params=query_params)
173
+ response.raise_for_status() # Raise an exception for bad status codes
174
+
175
+ # Parse JSON response and return as the expected type
176
+ response_data = response.json()
177
+ return self._u.model_validate(response_data)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: moose_lib
3
- Version: 0.4.232
3
+ Version: 0.4.234
4
4
  Home-page: https://www.fiveonefour.com/moose
5
5
  Author: Fiveonefour Labs Inc.
6
6
  Author-email: support@fiveonefour.com
@@ -12,9 +12,9 @@ moose_lib/clients/redis_client.py,sha256=UBCdxwgZpIOIOy2EnPyxJIAYjw_qmNwGsJQCQ66
12
12
  moose_lib/config/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
13
  moose_lib/config/config_file.py,sha256=NyjY6YFraBel7vBk18lLkpGaPR1viKMAEv4ZldyfLIA,2585
14
14
  moose_lib/config/runtime.py,sha256=gF1wrUCbp0MxRU92k0vyItvWX2x6P1FuBRzM61nJE_U,2776
15
- moose_lib/dmv2/__init__.py,sha256=zyGK2YDN4zQ2SMn9-SAiOuhpU46STePuJjK18LEserg,2269
15
+ moose_lib/dmv2/__init__.py,sha256=Po8jzSI-lc9LTSKo_F3rURRcDdraH-vzhkuEdpzakDY,2370
16
16
  moose_lib/dmv2/_registry.py,sha256=agdZ7xzS99Caou60Q2pEErzEwyNYHqwy6XqV79eEmwg,504
17
- moose_lib/dmv2/consumption.py,sha256=71wdv6ZuEi8Om7aX3Lq-d6bAoc1-iw3Wudb8dHESJKI,4072
17
+ moose_lib/dmv2/consumption.py,sha256=vt1APul1O21yPHaB0MRjF_9ohz5MJs5QIpDCnzFwyJA,6656
18
18
  moose_lib/dmv2/ingest_api.py,sha256=Snek9NGwaJl_BuImSWGtQq91m9D3AJ4qBoGiKZ-9yTQ,2323
19
19
  moose_lib/dmv2/ingest_pipeline.py,sha256=Y1gsvHZjlW07gMapLnBRJEsoAPv7ThvLABoLmVV7BHE,6714
20
20
  moose_lib/dmv2/materialized_view.py,sha256=kcx-sJFTM-cH3Uc1GoldgFGodjoz0AegAQEMmohdS38,3826
@@ -31,7 +31,7 @@ tests/__init__.py,sha256=0Gh4yzPkkC3TzBGKhenpMIxJcRhyrrCfxLSfpTZnPMQ,53
31
31
  tests/conftest.py,sha256=ZVJNbnr4DwbcqkTmePW6U01zAzE6QD0kNAEZjPG1f4s,169
32
32
  tests/test_moose.py,sha256=mBsx_OYWmL8ppDzL_7Bd7xR6qf_i3-pCIO3wm2iQNaA,2136
33
33
  tests/test_redis_client.py,sha256=d9_MLYsJ4ecVil_jPB2gW3Q5aWnavxmmjZg2uYI3LVo,3256
34
- moose_lib-0.4.232.dist-info/METADATA,sha256=j2mQHB0PxerGavuyssF4aTt4LznMV0hhR4i81rPu3Zo,729
35
- moose_lib-0.4.232.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
36
- moose_lib-0.4.232.dist-info/top_level.txt,sha256=XEns2-4aCmGp2XjJAeEH9TAUcGONLnSLy6ycT9FSJh8,16
37
- moose_lib-0.4.232.dist-info/RECORD,,
34
+ moose_lib-0.4.234.dist-info/METADATA,sha256=HhXW1_4DXkbb8aTw_bGLCEozDbAg-jdz1QELLeogF5E,729
35
+ moose_lib-0.4.234.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
36
+ moose_lib-0.4.234.dist-info/top_level.txt,sha256=XEns2-4aCmGp2XjJAeEH9TAUcGONLnSLy6ycT9FSJh8,16
37
+ moose_lib-0.4.234.dist-info/RECORD,,