nui-python-shared-utils 1.3.2__py3-none-any.whl → 1.4.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.
- nui_lambda_shared_utils/__init__.py +22 -3
- nui_lambda_shared_utils/snowflake_client.py +3 -0
- {nui_python_shared_utils-1.3.2.dist-info → nui_python_shared_utils-1.4.1.dist-info}/METADATA +75 -2
- {nui_python_shared_utils-1.3.2.dist-info → nui_python_shared_utils-1.4.1.dist-info}/RECORD +15 -12
- nui_shared_utils/__init__.py +254 -225
- nui_shared_utils/cloudwatch_metrics.py +13 -3
- nui_shared_utils/llm.py +209 -0
- nui_shared_utils/powertools_helpers.py +37 -15
- nui_shared_utils/secrets_helper.py +8 -3
- nui_shared_utils/snowflake_client.py +422 -0
- nui_shared_utils/utils.py +74 -88
- {nui_python_shared_utils-1.3.2.dist-info → nui_python_shared_utils-1.4.1.dist-info}/WHEEL +0 -0
- {nui_python_shared_utils-1.3.2.dist-info → nui_python_shared_utils-1.4.1.dist-info}/entry_points.txt +0 -0
- {nui_python_shared_utils-1.3.2.dist-info → nui_python_shared_utils-1.4.1.dist-info}/licenses/LICENSE +0 -0
- {nui_python_shared_utils-1.3.2.dist-info → nui_python_shared_utils-1.4.1.dist-info}/top_level.txt +0 -0
|
@@ -4,15 +4,21 @@ Backwards-compatibility shim for nui-lambda-shared-utils.
|
|
|
4
4
|
This package has been renamed to nui-python-shared-utils.
|
|
5
5
|
The import name has changed from nui_lambda_shared_utils to nui_shared_utils.
|
|
6
6
|
|
|
7
|
-
This shim
|
|
7
|
+
This shim forwards attribute access to nui_shared_utils so existing consumers
|
|
8
8
|
continue to work without changes. New code should use:
|
|
9
9
|
|
|
10
10
|
from nui_shared_utils import ...
|
|
11
11
|
|
|
12
12
|
This shim will be removed in the next major version (2.0.0).
|
|
13
|
+
|
|
14
|
+
Forwarding is lazy (PEP 562 ``__getattr__``) to preserve the cold-start
|
|
15
|
+
optimisation in the underlying package: ``from nui_lambda_shared_utils.jwt_auth
|
|
16
|
+
import check_auth`` only imports ``jwt_auth`` and its dependencies, not the
|
|
17
|
+
full slack/es/db client surface.
|
|
13
18
|
"""
|
|
14
19
|
|
|
15
20
|
import warnings
|
|
21
|
+
from typing import Any, List
|
|
16
22
|
|
|
17
23
|
warnings.warn(
|
|
18
24
|
"nui_lambda_shared_utils is deprecated. Use nui_shared_utils instead. "
|
|
@@ -21,5 +27,18 @@ warnings.warn(
|
|
|
21
27
|
stacklevel=2,
|
|
22
28
|
)
|
|
23
29
|
|
|
24
|
-
|
|
25
|
-
|
|
30
|
+
import nui_shared_utils as _target
|
|
31
|
+
|
|
32
|
+
__all__ = list(_target.__all__)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def __getattr__(name: str) -> Any:
|
|
36
|
+
# Delegate to the new package's lazy resolver. Cache on this module so
|
|
37
|
+
# subsequent accesses avoid the round-trip.
|
|
38
|
+
value = getattr(_target, name)
|
|
39
|
+
globals()[name] = value
|
|
40
|
+
return value
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def __dir__() -> List[str]:
|
|
44
|
+
return sorted(set(globals()) | set(__all__))
|
{nui_python_shared_utils-1.3.2.dist-info → nui_python_shared_utils-1.4.1.dist-info}/METADATA
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: nui-python-shared-utils
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.4.1
|
|
4
4
|
Summary: Shared Python utilities for AWS Lambda, CLI tools, and agents with Slack, Elasticsearch, and monitoring integrations
|
|
5
5
|
Home-page: https://github.com/nuimarkets/nui-python-shared-utils
|
|
6
6
|
Author: NUI Markets
|
|
@@ -64,6 +64,10 @@ Requires-Dist: aws-lambda-powertools<4.0.0,>=3.6.0; extra == "powertools"
|
|
|
64
64
|
Requires-Dist: coloredlogs>=15.0; extra == "powertools"
|
|
65
65
|
Provides-Extra: jwt
|
|
66
66
|
Requires-Dist: rsa>=4.9; extra == "jwt"
|
|
67
|
+
Provides-Extra: snowflake
|
|
68
|
+
Requires-Dist: snowflake-sql-api<0.2.0,>=0.1.1; extra == "snowflake"
|
|
69
|
+
Provides-Extra: llm
|
|
70
|
+
Requires-Dist: anthropic[bedrock]<1.0.0,>=0.45.0; extra == "llm"
|
|
67
71
|
Provides-Extra: all
|
|
68
72
|
Requires-Dist: elasticsearch<8.0.0,>=7.17.0; extra == "all"
|
|
69
73
|
Requires-Dist: pymysql>=1.0.0; extra == "all"
|
|
@@ -86,6 +90,8 @@ Requires-Dist: twine>=4.0.0; extra == "dev"
|
|
|
86
90
|
Requires-Dist: build>=0.8.0; extra == "dev"
|
|
87
91
|
Requires-Dist: rsa>=4.9; extra == "dev"
|
|
88
92
|
Requires-Dist: cryptography>=41.0.0; extra == "dev"
|
|
93
|
+
Requires-Dist: snowflake-sql-api<0.2.0,>=0.1.1; extra == "dev"
|
|
94
|
+
Requires-Dist: anthropic[bedrock]<1.0.0,>=0.45.0; extra == "dev"
|
|
89
95
|
Dynamic: author
|
|
90
96
|
Dynamic: home-page
|
|
91
97
|
Dynamic: license-file
|
|
@@ -128,6 +134,7 @@ Production-ready shared Python utilities for AWS Lambda functions, CLI tools, an
|
|
|
128
134
|
- **Database Connections** - Connection pooling, automatic retries, and transaction management
|
|
129
135
|
- **CloudWatch Metrics** - Batched publishing with custom dimensions
|
|
130
136
|
- **JWT Authentication** - RS256 token validation for API Gateway Lambdas (lightweight, no PyJWT needed)
|
|
137
|
+
- **Anthropic (Claude) Helper** - Generic client plumbing for LLM calls: API-key or Bedrock IAM auth, forced tool-use, and text calls (prompts and schemas stay in your code)
|
|
131
138
|
- **Error Handling** - Intelligent retry patterns with exponential backoff
|
|
132
139
|
- **Timezone Utilities** - Timezone handling and formatting
|
|
133
140
|
- **Configurable Defaults** - Environment-aware configuration system
|
|
@@ -158,12 +165,14 @@ Production-ready shared Python utilities for AWS Lambda functions, CLI tools, an
|
|
|
158
165
|
pip install nui-python-shared-utils
|
|
159
166
|
|
|
160
167
|
# With specific extras for optional dependencies
|
|
161
|
-
pip install nui-python-shared-utils[all] #
|
|
168
|
+
pip install nui-python-shared-utils[all] # Core optional integrations (excludes Snowflake and LLM)
|
|
162
169
|
pip install nui-python-shared-utils[powertools] # AWS Powertools only
|
|
163
170
|
pip install nui-python-shared-utils[slack] # Slack only
|
|
164
171
|
pip install nui-python-shared-utils[elasticsearch] # Elasticsearch only
|
|
165
172
|
pip install nui-python-shared-utils[database] # Database only
|
|
166
173
|
pip install nui-python-shared-utils[jwt] # JWT authentication only
|
|
174
|
+
pip install nui-python-shared-utils[snowflake] # Snowflake SQL API client
|
|
175
|
+
pip install nui-python-shared-utils[llm] # Anthropic (Claude) client helper
|
|
167
176
|
```
|
|
168
177
|
|
|
169
178
|
### Basic Configuration
|
|
@@ -291,6 +300,35 @@ async with db.get_connection() as conn:
|
|
|
291
300
|
|
|
292
301
|
**[→ See full database guide](docs/getting-started/quickstart.md#database-connections)**
|
|
293
302
|
|
|
303
|
+
### Snowflake (SQL API)
|
|
304
|
+
|
|
305
|
+
Pure-Python Snowflake client (no `snowflake-connector-python`), keypair auth via
|
|
306
|
+
Secrets Manager, with NUI session defaults (`TIMEZONE=Pacific/Auckland`, role
|
|
307
|
+
`NUI_LAMBDA`) that you can override via `timezone=` and `role=`, plus a redacting
|
|
308
|
+
query-logging hook.
|
|
309
|
+
|
|
310
|
+
```python
|
|
311
|
+
from nui_shared_utils import create_snowflake_client
|
|
312
|
+
|
|
313
|
+
# Loads account/user/private_key from Secrets Manager ("snowflake-credentials"
|
|
314
|
+
# by default; override with SNOWFLAKE_CREDENTIALS_SECRET or secret_name=).
|
|
315
|
+
# The NUI defaults are overridable, so the client stays generic for any account.
|
|
316
|
+
client = create_snowflake_client(
|
|
317
|
+
warehouse="COMPUTE_WH",
|
|
318
|
+
database="ANALYTICS",
|
|
319
|
+
timezone="UTC", # override the Pacific/Auckland default
|
|
320
|
+
role="MY_APP_ROLE", # override the NUI_LAMBDA default
|
|
321
|
+
)
|
|
322
|
+
rows = client.query("SELECT id, name FROM orders WHERE status = ?", ["confirmed"])
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
Sync is the default; use `create_async_snowflake_client(...)` inside a Lambda
|
|
326
|
+
or FastAPI app already on an event loop. Snowflake SQL API bindings use
|
|
327
|
+
positional `?` placeholders, not connector-style `%s` placeholders. Requires
|
|
328
|
+
the `[snowflake]` extra.
|
|
329
|
+
|
|
330
|
+
**[→ See full Snowflake guide](docs/guides/snowflake-integration.md)**
|
|
331
|
+
|
|
294
332
|
### CloudWatch Metrics
|
|
295
333
|
|
|
296
334
|
```python
|
|
@@ -323,6 +361,41 @@ def lambda_handler(event, context):
|
|
|
323
361
|
|
|
324
362
|
**[→ See JWT authentication guide](docs/guides/jwt-authentication.md)**
|
|
325
363
|
|
|
364
|
+
### Anthropic (Claude) Helper
|
|
365
|
+
|
|
366
|
+
Generic plumbing for Claude calls: build a client (API-key or Bedrock IAM), make
|
|
367
|
+
a forced tool-use call or a text call, and get the parsed result back. Prompts,
|
|
368
|
+
tool schemas, model ids, and result post-processing stay in your code.
|
|
369
|
+
|
|
370
|
+
```python
|
|
371
|
+
from nui_shared_utils import build_anthropic_client, call_tool
|
|
372
|
+
|
|
373
|
+
# API-key auth: explicit key -> ANTHROPIC_API_KEY env -> Secrets Manager
|
|
374
|
+
client = build_anthropic_client(secret_name="my/anthropic-key")
|
|
375
|
+
# Or Bedrock IAM (no key): build_anthropic_client(mode="bedrock", region="us-east-1")
|
|
376
|
+
|
|
377
|
+
tool = {
|
|
378
|
+
"name": "classify",
|
|
379
|
+
"description": "Classify the text.",
|
|
380
|
+
"input_schema": {
|
|
381
|
+
"type": "object",
|
|
382
|
+
"properties": {"label": {"type": "string"}, "score": {"type": "number"}},
|
|
383
|
+
"required": ["label", "score"],
|
|
384
|
+
"additionalProperties": False,
|
|
385
|
+
},
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
# Forced tool-use; returns the tool's input dict, or None on any model/parse failure.
|
|
389
|
+
result = call_tool(client, tool=tool, prompt="Great product!", model="claude-haiku-4-5", max_tokens=256)
|
|
390
|
+
if result is not None:
|
|
391
|
+
print(result["label"], result["score"])
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
Requires the `[llm]` extra. `call_tool` is best-effort (returns `None`, never
|
|
395
|
+
raises); `call_text` returns `{text, input_tokens, output_tokens}`.
|
|
396
|
+
|
|
397
|
+
**[→ See full LLM integration guide](docs/guides/llm-integration.md)**
|
|
398
|
+
|
|
326
399
|
### Error Handling
|
|
327
400
|
|
|
328
401
|
```python
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
nui_lambda_shared_utils/__init__.py,sha256=
|
|
1
|
+
nui_lambda_shared_utils/__init__.py,sha256=FaaYBqgNxSQ0x7jlf5fw2pQoMh8Pbmw7uZiVfavI_IY,1320
|
|
2
2
|
nui_lambda_shared_utils/base_client.py,sha256=c7t2_IfISQ39Y1AY6MOj-SlX2tkpzNpp47RRMfu5xqY,135
|
|
3
3
|
nui_lambda_shared_utils/cli.py,sha256=3TtfQy0x3P0QKiNDiz0j3kze7Hs26CMeQE8X_948OEQ,127
|
|
4
4
|
nui_lambda_shared_utils/cloudwatch_metrics.py,sha256=Qwj52AIVrxg7HEEMjmgvDptCJ5Csr_w3NJBI1v34sFw,142
|
|
@@ -14,17 +14,18 @@ nui_lambda_shared_utils/powertools_helpers.py,sha256=xTnbiyE_5bl9saizsKYd1U4rQBP
|
|
|
14
14
|
nui_lambda_shared_utils/secrets_helper.py,sha256=wuThNFPFnU0K8N7I0UGMsyk9oJmOSYTR08xJy2MC8-M,138
|
|
15
15
|
nui_lambda_shared_utils/slack_client.py,sha256=_itnosOoODXq1dAX2dMReQi0gZBARjcGqwtRjh1MFPc,136
|
|
16
16
|
nui_lambda_shared_utils/slack_formatter.py,sha256=gwCkhfVdOvg44WW6hBogvfmcHsZxSZ-mzXUq6ft1k84,139
|
|
17
|
+
nui_lambda_shared_utils/snowflake_client.py,sha256=p-gI8vEF_QyFU0Zts8I5jwIPzrAuYopAKXsv76MNZio,151
|
|
17
18
|
nui_lambda_shared_utils/timezone.py,sha256=eLXPmhgFazj76K1aWiO5CSZbuiSlbXEGY8X-MxDKbjw,132
|
|
18
19
|
nui_lambda_shared_utils/utils.py,sha256=sWDeHr9Jm3A6yaIqgP9b6_lHoPJox8gD6G1-eiYAgq4,129
|
|
19
20
|
nui_lambda_shared_utils/slack_setup/__init__.py,sha256=q78NzSznsSd3ri5OUohWxQt7r6q0zdrE3gF2hvpHnD8,140
|
|
20
21
|
nui_lambda_shared_utils/slack_setup/channel_creator.py,sha256=xaeqzyEAqVqYj2EhN69UvcyZQ6LdFKYODPPCwxHInLA,172
|
|
21
22
|
nui_lambda_shared_utils/slack_setup/channel_definitions.py,sha256=3TkdLzWvEMBMDy5jqOPMUGRgKQ3z9TN58D43V7O7LpE,180
|
|
22
23
|
nui_lambda_shared_utils/slack_setup/setup_helpers.py,sha256=ex_RiUfiZqH9qGLQwmedezMbfp35uI-VQPevducfbBk,168
|
|
23
|
-
nui_python_shared_utils-1.
|
|
24
|
-
nui_shared_utils/__init__.py,sha256=
|
|
24
|
+
nui_python_shared_utils-1.4.1.dist-info/licenses/LICENSE,sha256=vGe2mC5yLUb8toYlY3T36ZwCB5zQUW5hlCtEMiqokhM,1071
|
|
25
|
+
nui_shared_utils/__init__.py,sha256=WOpBwxBqJK_wq8l3s5TCCs4j__lMTbI7TjraTXfmH4c,11851
|
|
25
26
|
nui_shared_utils/base_client.py,sha256=I1lKQGhrKyvujV2zps0TrtEdPDqMCwRQaIh6ceGONXQ,11016
|
|
26
27
|
nui_shared_utils/cli.py,sha256=JJpSoQWKvAz4b8cO30yFNi5vY9jmqrCHzbFpvrVTkbU,8747
|
|
27
|
-
nui_shared_utils/cloudwatch_metrics.py,sha256=
|
|
28
|
+
nui_shared_utils/cloudwatch_metrics.py,sha256=p0J-s63UJDGK14TRGt0k8yoj7aWSSM55UKdgcuaT1dU,12098
|
|
28
29
|
nui_shared_utils/config.py,sha256=ZbkUKDxnHMJiHNv-TlWKjotmf2mH1Vz3GaIXgGfWg7E,4524
|
|
29
30
|
nui_shared_utils/db_client.py,sha256=HyVKJ1Su0dVPV1QI2MU5UtT8myDRCjKgV60xRL4SEdE,21726
|
|
30
31
|
nui_shared_utils/error_handler.py,sha256=pJ6b_mI0Ait8QRbs9UmLzYUN-Ft0l_dnpudVO_6LRSE,12171
|
|
@@ -32,19 +33,21 @@ nui_shared_utils/es_client.py,sha256=rLyexuL6_RXQpuMC4A2SeJDk30medx2qxOgWIG3A_7o
|
|
|
32
33
|
nui_shared_utils/es_query_builder.py,sha256=UuheQf8b2UXaOiJlYCKYIfKfVERDZ3ag1P0OOOWm9do,12158
|
|
33
34
|
nui_shared_utils/jwt_auth.py,sha256=2Ag1zZKxd2R8QBz3aQA4h8OtKHQvUVKrjUp6lXpJxJU,9143
|
|
34
35
|
nui_shared_utils/lambda_helpers.py,sha256=psHVotpmOfnmyQCoOt4MSIEj7VwWcy6gZM3vYSZwjOk,3041
|
|
36
|
+
nui_shared_utils/llm.py,sha256=adNUO8Qbeb3__GvpROxWSUERkpiazKiGJFE5xzU5eZ0,8351
|
|
35
37
|
nui_shared_utils/log_processors.py,sha256=x5gz1LEkbmoMCZ3ZB6q-mbn26dSzwh1trz4wSkBGxqk,5538
|
|
36
|
-
nui_shared_utils/powertools_helpers.py,sha256=
|
|
37
|
-
nui_shared_utils/secrets_helper.py,sha256=
|
|
38
|
+
nui_shared_utils/powertools_helpers.py,sha256=qc-lYLfY-QX20gALfPOJcihrtJhiCU-fJW8rsPT7LJE,11037
|
|
39
|
+
nui_shared_utils/secrets_helper.py,sha256=_jQkMWzjayZ8vvyHG2yuuxur-SQYUUONfcsZ0MF8qOw,7025
|
|
38
40
|
nui_shared_utils/slack_client.py,sha256=_qR7Q1GU7gvYhUxiaBxEohhoEYznqr8kz9enGfeDtn8,24759
|
|
39
41
|
nui_shared_utils/slack_formatter.py,sha256=95g6XfAJst7RVhd0M0ahiF3gWWW5j96WYkCg5tLS6Zg,10894
|
|
42
|
+
nui_shared_utils/snowflake_client.py,sha256=e3jH6_2mMqbtP1TE8-mUFFYrfGW9eqUPT5tlcgeCqx8,16181
|
|
40
43
|
nui_shared_utils/timezone.py,sha256=TvtSZV7w3Vvz3NbMTcJSNbUf0ZxPwpFS-xfgye1h-4Q,3583
|
|
41
|
-
nui_shared_utils/utils.py,sha256=
|
|
44
|
+
nui_shared_utils/utils.py,sha256=gOpw80tZGC24QsyesR8EySRODY-TFXG8cXUvggPBsRI,8184
|
|
42
45
|
nui_shared_utils/slack_setup/__init__.py,sha256=OElyS3xk4F_YKH5uUUTDpN0ah1dOO3e52muIPjAMPW8,320
|
|
43
46
|
nui_shared_utils/slack_setup/channel_creator.py,sha256=0gyCBIS0EC96SVn1Z2dD4Fpzk0xNdHSWyiCxoUQIUe8,10667
|
|
44
47
|
nui_shared_utils/slack_setup/channel_definitions.py,sha256=atfz5ZhpqefOeLh1gShbWd-TLzgjPmhv95bfuTdmZog,5676
|
|
45
48
|
nui_shared_utils/slack_setup/setup_helpers.py,sha256=pzzXMs12GI9sdZttWeYzgLPgC0xqPz7ZLHM1GUPNNXc,7219
|
|
46
|
-
nui_python_shared_utils-1.
|
|
47
|
-
nui_python_shared_utils-1.
|
|
48
|
-
nui_python_shared_utils-1.
|
|
49
|
-
nui_python_shared_utils-1.
|
|
50
|
-
nui_python_shared_utils-1.
|
|
49
|
+
nui_python_shared_utils-1.4.1.dist-info/METADATA,sha256=jYHBmx1R9T3PEGS2aLOY0DvcuZFm7DuebJL4VaV3z_c,22632
|
|
50
|
+
nui_python_shared_utils-1.4.1.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
51
|
+
nui_python_shared_utils-1.4.1.dist-info/entry_points.txt,sha256=TrJ3Z4kz3oXfy6InXn20jHu7rnTwo-4EA0KRFX3fkL0,66
|
|
52
|
+
nui_python_shared_utils-1.4.1.dist-info/top_level.txt,sha256=sNceq5okmEB54L-gm4a0OgGhnPlU62zYmlUoXKn-Fa8,41
|
|
53
|
+
nui_python_shared_utils-1.4.1.dist-info/RECORD,,
|