moose-lib 0.4.232__tar.gz → 0.4.233__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 (42) hide show
  1. {moose_lib-0.4.232 → moose_lib-0.4.233}/PKG-INFO +1 -1
  2. {moose_lib-0.4.232 → moose_lib-0.4.233}/moose_lib/dmv2/__init__.py +5 -1
  3. {moose_lib-0.4.232 → moose_lib-0.4.233}/moose_lib/dmv2/consumption.py +79 -3
  4. {moose_lib-0.4.232 → moose_lib-0.4.233}/moose_lib.egg-info/PKG-INFO +1 -1
  5. {moose_lib-0.4.232 → moose_lib-0.4.233}/README.md +0 -0
  6. {moose_lib-0.4.232 → moose_lib-0.4.233}/moose_lib/__init__.py +0 -0
  7. {moose_lib-0.4.232 → moose_lib-0.4.233}/moose_lib/blocks.py +0 -0
  8. {moose_lib-0.4.232 → moose_lib-0.4.233}/moose_lib/clients/__init__.py +0 -0
  9. {moose_lib-0.4.232 → moose_lib-0.4.233}/moose_lib/clients/redis_client.py +0 -0
  10. {moose_lib-0.4.232 → moose_lib-0.4.233}/moose_lib/commons.py +0 -0
  11. {moose_lib-0.4.232 → moose_lib-0.4.233}/moose_lib/config/__init__.py +0 -0
  12. {moose_lib-0.4.232 → moose_lib-0.4.233}/moose_lib/config/config_file.py +0 -0
  13. {moose_lib-0.4.232 → moose_lib-0.4.233}/moose_lib/config/runtime.py +0 -0
  14. {moose_lib-0.4.232 → moose_lib-0.4.233}/moose_lib/data_models.py +0 -0
  15. {moose_lib-0.4.232 → moose_lib-0.4.233}/moose_lib/dmv2/_registry.py +0 -0
  16. {moose_lib-0.4.232 → moose_lib-0.4.233}/moose_lib/dmv2/ingest_api.py +0 -0
  17. {moose_lib-0.4.232 → moose_lib-0.4.233}/moose_lib/dmv2/ingest_pipeline.py +0 -0
  18. {moose_lib-0.4.232 → moose_lib-0.4.233}/moose_lib/dmv2/materialized_view.py +0 -0
  19. {moose_lib-0.4.232 → moose_lib-0.4.233}/moose_lib/dmv2/olap_table.py +0 -0
  20. {moose_lib-0.4.232 → moose_lib-0.4.233}/moose_lib/dmv2/registry.py +0 -0
  21. {moose_lib-0.4.232 → moose_lib-0.4.233}/moose_lib/dmv2/sql_resource.py +0 -0
  22. {moose_lib-0.4.232 → moose_lib-0.4.233}/moose_lib/dmv2/stream.py +0 -0
  23. {moose_lib-0.4.232 → moose_lib-0.4.233}/moose_lib/dmv2/types.py +0 -0
  24. {moose_lib-0.4.232 → moose_lib-0.4.233}/moose_lib/dmv2/view.py +0 -0
  25. {moose_lib-0.4.232 → moose_lib-0.4.233}/moose_lib/dmv2/workflow.py +0 -0
  26. {moose_lib-0.4.232 → moose_lib-0.4.233}/moose_lib/dmv2-serializer.py +0 -0
  27. {moose_lib-0.4.232 → moose_lib-0.4.233}/moose_lib/internal.py +0 -0
  28. {moose_lib-0.4.232 → moose_lib-0.4.233}/moose_lib/main.py +0 -0
  29. {moose_lib-0.4.232 → moose_lib-0.4.233}/moose_lib/query_param.py +0 -0
  30. {moose_lib-0.4.232 → moose_lib-0.4.233}/moose_lib/streaming/__init__.py +0 -0
  31. {moose_lib-0.4.232 → moose_lib-0.4.233}/moose_lib/streaming/streaming_function_runner.py +0 -0
  32. {moose_lib-0.4.232 → moose_lib-0.4.233}/moose_lib/tasks.py +0 -0
  33. {moose_lib-0.4.232 → moose_lib-0.4.233}/moose_lib.egg-info/SOURCES.txt +0 -0
  34. {moose_lib-0.4.232 → moose_lib-0.4.233}/moose_lib.egg-info/dependency_links.txt +0 -0
  35. {moose_lib-0.4.232 → moose_lib-0.4.233}/moose_lib.egg-info/requires.txt +0 -0
  36. {moose_lib-0.4.232 → moose_lib-0.4.233}/moose_lib.egg-info/top_level.txt +0 -0
  37. {moose_lib-0.4.232 → moose_lib-0.4.233}/setup.cfg +0 -0
  38. {moose_lib-0.4.232 → moose_lib-0.4.233}/setup.py +0 -0
  39. {moose_lib-0.4.232 → moose_lib-0.4.233}/tests/__init__.py +0 -0
  40. {moose_lib-0.4.232 → moose_lib-0.4.233}/tests/conftest.py +0 -0
  41. {moose_lib-0.4.232 → moose_lib-0.4.233}/tests/test_moose.py +0 -0
  42. {moose_lib-0.4.232 → moose_lib-0.4.233}/tests/test_redis_client.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: moose_lib
3
- Version: 0.4.232
3
+ Version: 0.4.233
4
4
  Home-page: https://www.fiveonefour.com/moose
5
5
  Author: Fiveonefour Labs Inc.
6
6
  Author-email: support@fiveonefour.com
@@ -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.233
4
4
  Home-page: https://www.fiveonefour.com/moose
5
5
  Author: Fiveonefour Labs Inc.
6
6
  Author-email: support@fiveonefour.com
File without changes
File without changes
File without changes