nui-python-shared-utils 1.3.0__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 +252 -0
- nui_lambda_shared_utils/base_client.py +323 -0
- nui_lambda_shared_utils/cli.py +225 -0
- nui_lambda_shared_utils/cloudwatch_metrics.py +367 -0
- nui_lambda_shared_utils/config.py +136 -0
- nui_lambda_shared_utils/db_client.py +623 -0
- nui_lambda_shared_utils/error_handler.py +372 -0
- nui_lambda_shared_utils/es_client.py +460 -0
- nui_lambda_shared_utils/es_query_builder.py +315 -0
- nui_lambda_shared_utils/jwt_auth.py +277 -0
- nui_lambda_shared_utils/lambda_helpers.py +84 -0
- nui_lambda_shared_utils/log_processors.py +172 -0
- nui_lambda_shared_utils/powertools_helpers.py +263 -0
- nui_lambda_shared_utils/secrets_helper.py +187 -0
- nui_lambda_shared_utils/slack_client.py +675 -0
- nui_lambda_shared_utils/slack_formatter.py +307 -0
- nui_lambda_shared_utils/slack_setup/__init__.py +14 -0
- nui_lambda_shared_utils/slack_setup/channel_creator.py +295 -0
- nui_lambda_shared_utils/slack_setup/channel_definitions.py +187 -0
- nui_lambda_shared_utils/slack_setup/setup_helpers.py +211 -0
- nui_lambda_shared_utils/timezone.py +117 -0
- nui_lambda_shared_utils/utils.py +291 -0
- nui_python_shared_utils-1.3.0.dist-info/METADATA +470 -0
- nui_python_shared_utils-1.3.0.dist-info/RECORD +28 -0
- nui_python_shared_utils-1.3.0.dist-info/WHEEL +5 -0
- nui_python_shared_utils-1.3.0.dist-info/entry_points.txt +2 -0
- nui_python_shared_utils-1.3.0.dist-info/licenses/LICENSE +21 -0
- nui_python_shared_utils-1.3.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,470 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: nui-python-shared-utils
|
|
3
|
+
Version: 1.3.0
|
|
4
|
+
Summary: Shared Python utilities for AWS Lambda, CLI tools, and agents with Slack, Elasticsearch, and monitoring integrations
|
|
5
|
+
Home-page: https://github.com/nuimarkets/nui-python-shared-utils
|
|
6
|
+
Author: NUI Markets
|
|
7
|
+
Author-email: NUI Markets <develop@nuimarkets.com>
|
|
8
|
+
License: MIT License
|
|
9
|
+
|
|
10
|
+
Copyright (c) 2025 NUI Markets Ltd
|
|
11
|
+
|
|
12
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
13
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
14
|
+
in the Software without restriction, including without limitation the rights
|
|
15
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
16
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
17
|
+
furnished to do so, subject to the following conditions:
|
|
18
|
+
|
|
19
|
+
The above copyright notice and this permission notice shall be included in all
|
|
20
|
+
copies or substantial portions of the Software.
|
|
21
|
+
|
|
22
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
23
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
24
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
25
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
26
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
27
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
28
|
+
SOFTWARE.
|
|
29
|
+
Project-URL: Homepage, https://github.com/nuimarkets/nui-python-shared-utils
|
|
30
|
+
Project-URL: Bug Tracker, https://github.com/nuimarkets/nui-python-shared-utils/issues
|
|
31
|
+
Project-URL: Documentation, https://github.com/nuimarkets/nui-python-shared-utils/blob/main/README.md
|
|
32
|
+
Project-URL: Source, https://github.com/nuimarkets/nui-python-shared-utils
|
|
33
|
+
Keywords: aws,lambda,utilities,slack,elasticsearch,monitoring,serverless,python,shared
|
|
34
|
+
Classifier: Development Status :: 4 - Beta
|
|
35
|
+
Classifier: Intended Audience :: Developers
|
|
36
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
37
|
+
Classifier: Operating System :: OS Independent
|
|
38
|
+
Classifier: Programming Language :: Python :: 3
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
40
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
41
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
42
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
43
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
44
|
+
Classifier: Topic :: System :: Monitoring
|
|
45
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
|
|
46
|
+
Classifier: Environment :: Console
|
|
47
|
+
Classifier: Framework :: AWS CDK
|
|
48
|
+
Requires-Python: >=3.9
|
|
49
|
+
Description-Content-Type: text/markdown
|
|
50
|
+
License-File: LICENSE
|
|
51
|
+
Requires-Dist: boto3>=1.20.0
|
|
52
|
+
Requires-Dist: pytz>=2021.3
|
|
53
|
+
Requires-Dist: click>=8.0.0
|
|
54
|
+
Requires-Dist: pyyaml>=6.0
|
|
55
|
+
Provides-Extra: elasticsearch
|
|
56
|
+
Requires-Dist: elasticsearch<8.0.0,>=7.17.0; extra == "elasticsearch"
|
|
57
|
+
Provides-Extra: database
|
|
58
|
+
Requires-Dist: pymysql>=1.0.0; extra == "database"
|
|
59
|
+
Requires-Dist: psycopg2-binary>=2.9.0; extra == "database"
|
|
60
|
+
Provides-Extra: slack
|
|
61
|
+
Requires-Dist: slack-sdk>=3.19.0; extra == "slack"
|
|
62
|
+
Provides-Extra: powertools
|
|
63
|
+
Requires-Dist: aws-lambda-powertools<4.0.0,>=3.6.0; extra == "powertools"
|
|
64
|
+
Requires-Dist: coloredlogs>=15.0; extra == "powertools"
|
|
65
|
+
Provides-Extra: jwt
|
|
66
|
+
Requires-Dist: rsa>=4.9; extra == "jwt"
|
|
67
|
+
Provides-Extra: all
|
|
68
|
+
Requires-Dist: elasticsearch<8.0.0,>=7.17.0; extra == "all"
|
|
69
|
+
Requires-Dist: pymysql>=1.0.0; extra == "all"
|
|
70
|
+
Requires-Dist: psycopg2-binary>=2.9.0; extra == "all"
|
|
71
|
+
Requires-Dist: slack-sdk>=3.19.0; extra == "all"
|
|
72
|
+
Requires-Dist: aws-lambda-powertools<4.0.0,>=3.6.0; extra == "all"
|
|
73
|
+
Requires-Dist: coloredlogs>=15.0; extra == "all"
|
|
74
|
+
Requires-Dist: rsa>=4.9; extra == "all"
|
|
75
|
+
Provides-Extra: dev
|
|
76
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
77
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
78
|
+
Requires-Dist: pytest-mock>=3.10.0; extra == "dev"
|
|
79
|
+
Requires-Dist: moto>=4.0.0; extra == "dev"
|
|
80
|
+
Requires-Dist: black>=22.0.0; extra == "dev"
|
|
81
|
+
Requires-Dist: mypy>=0.990; extra == "dev"
|
|
82
|
+
Requires-Dist: boto3-stubs[essential]>=1.20.0; extra == "dev"
|
|
83
|
+
Requires-Dist: types-PyYAML>=6.0.0; extra == "dev"
|
|
84
|
+
Requires-Dist: types-pytz>=2021.3.0; extra == "dev"
|
|
85
|
+
Requires-Dist: twine>=4.0.0; extra == "dev"
|
|
86
|
+
Requires-Dist: build>=0.8.0; extra == "dev"
|
|
87
|
+
Requires-Dist: rsa>=4.9; extra == "dev"
|
|
88
|
+
Requires-Dist: cryptography>=41.0.0; extra == "dev"
|
|
89
|
+
Dynamic: author
|
|
90
|
+
Dynamic: home-page
|
|
91
|
+
Dynamic: license-file
|
|
92
|
+
Dynamic: requires-python
|
|
93
|
+
|
|
94
|
+
# NUI Python Shared Utilities
|
|
95
|
+
|
|
96
|
+
[](https://badge.fury.io/py/nui-python-shared-utils)
|
|
97
|
+
[](https://www.python.org/downloads/)
|
|
98
|
+
[](https://opensource.org/licenses/MIT)
|
|
99
|
+
|
|
100
|
+
Production-ready shared Python utilities for AWS Lambda functions, CLI tools, and agents. Provides standardized integrations for Slack, Elasticsearch, database, and monitoring. Built and battle-tested on the NUI platform with sensible defaults configurable for any environment.
|
|
101
|
+
|
|
102
|
+
## Table of Contents
|
|
103
|
+
|
|
104
|
+
- [Who This Package Is For](#who-this-package-is-for)
|
|
105
|
+
- [Key Features](#key-features)
|
|
106
|
+
- [Documentation](#documentation)
|
|
107
|
+
- [Quick Start](#quick-start)
|
|
108
|
+
- [Usage Examples](#usage-examples)
|
|
109
|
+
- [Configuration](#configuration)
|
|
110
|
+
- [AWS Infrastructure Requirements](#aws-infrastructure-requirements)
|
|
111
|
+
- [Testing](#testing)
|
|
112
|
+
- [Contributing](#contributing)
|
|
113
|
+
- [Documentation & Support](#documentation--support)
|
|
114
|
+
- [License](#license)
|
|
115
|
+
|
|
116
|
+
## Who This Package Is For
|
|
117
|
+
|
|
118
|
+
**NUI Team**: Drop-in utilities with NUI platform defaults pre-configured. Handles common patterns like Slack notifications, Elasticsearch logging, database connections, and CloudWatch metrics out of the box.
|
|
119
|
+
|
|
120
|
+
**External Teams**: Solid AWS Lambda patterns for serverless operations. Default configurations reflect NUI conventions (Elasticsearch index patterns, AWS Secrets Manager naming, Slack workspace structure) but are fully overridable via environment variables or programmatic configuration. Consider this package as production-tested reference implementations that you can adapt to your infrastructure.
|
|
121
|
+
|
|
122
|
+
## Key Features
|
|
123
|
+
|
|
124
|
+
- **AWS Powertools Integration** - Standardized logging, metrics, and error handling for Lambda functions
|
|
125
|
+
- **AWS Secrets Manager Integration** - Secure credential management with caching
|
|
126
|
+
- **Slack Messaging** - Rich formatting, threading, file uploads, and channel management
|
|
127
|
+
- **Elasticsearch Operations** - Query builders, index management, and health monitoring
|
|
128
|
+
- **Database Connections** - Connection pooling, automatic retries, and transaction management
|
|
129
|
+
- **CloudWatch Metrics** - Batched publishing with custom dimensions
|
|
130
|
+
- **JWT Authentication** - RS256 token validation for API Gateway Lambdas (lightweight, no PyJWT needed)
|
|
131
|
+
- **Error Handling** - Intelligent retry patterns with exponential backoff
|
|
132
|
+
- **Timezone Utilities** - Timezone handling and formatting
|
|
133
|
+
- **Configurable Defaults** - Environment-aware configuration system
|
|
134
|
+
|
|
135
|
+
## Documentation
|
|
136
|
+
|
|
137
|
+
**New to this package?** Start with our comprehensive guides:
|
|
138
|
+
|
|
139
|
+
- **[Quick Start Guide](docs/getting-started/quickstart.md)** - Common patterns and complete examples
|
|
140
|
+
- **[Installation Guide](docs/getting-started/installation.md)** - Setup and dependency management
|
|
141
|
+
- **[Configuration Guide](docs/getting-started/configuration.md)** - Environment setup and AWS Secrets
|
|
142
|
+
- **[Slack Integration Guide](docs/guides/slack-integration.md)** - Messaging, blocks, threading, and files
|
|
143
|
+
- **[Testing Guide](docs/development/testing.md)** - Test strategies and coverage
|
|
144
|
+
|
|
145
|
+
**Complete documentation**: See [docs/](docs/README.md) for all guides and references.
|
|
146
|
+
|
|
147
|
+
**Component Guides:**
|
|
148
|
+
|
|
149
|
+
- **[AWS Powertools Integration Guide](docs/guides/powertools-integration.md)** - Logging, metrics, error handling
|
|
150
|
+
- **[Slack Integration Guide](docs/guides/slack-integration.md)** - Messaging, blocks, threading, files
|
|
151
|
+
- **[Testing Guide](docs/development/testing.md)** - Test strategies and coverage
|
|
152
|
+
|
|
153
|
+
## Quick Start
|
|
154
|
+
|
|
155
|
+
### Installation
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
pip install nui-python-shared-utils
|
|
159
|
+
|
|
160
|
+
# With specific extras for optional dependencies
|
|
161
|
+
pip install nui-python-shared-utils[all] # All integrations
|
|
162
|
+
pip install nui-python-shared-utils[powertools] # AWS Powertools only
|
|
163
|
+
pip install nui-python-shared-utils[slack] # Slack only
|
|
164
|
+
pip install nui-python-shared-utils[elasticsearch] # Elasticsearch only
|
|
165
|
+
pip install nui-python-shared-utils[database] # Database only
|
|
166
|
+
pip install nui-python-shared-utils[jwt] # JWT authentication only
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Basic Configuration
|
|
170
|
+
|
|
171
|
+
```python
|
|
172
|
+
import nui_lambda_shared_utils as nui
|
|
173
|
+
|
|
174
|
+
# Configure for your environment (optional - uses sensible defaults)
|
|
175
|
+
nui.configure(
|
|
176
|
+
es_host="your-elasticsearch-host:9200",
|
|
177
|
+
es_credentials_secret="your-es-secret-name",
|
|
178
|
+
slack_credentials_secret="your-slack-secret-name",
|
|
179
|
+
db_credentials_secret="your-database-secret-name"
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
# Or use environment variables:
|
|
183
|
+
# ES_HOST, ES_CREDENTIALS_SECRET, SLACK_CREDENTIALS_SECRET, etc.
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## What's Next?
|
|
187
|
+
|
|
188
|
+
After installing the package:
|
|
189
|
+
|
|
190
|
+
1. **Configuration** → Set up environment variables or programmatic config ([guide](docs/getting-started/configuration.md))
|
|
191
|
+
2. **AWS Setup** → Configure Secrets Manager and IAM permissions ([guide](docs/getting-started/configuration.md#aws-infrastructure))
|
|
192
|
+
3. **Integration** → Choose your integration and follow the detailed guide:
|
|
193
|
+
- [Slack Integration](docs/guides/slack-integration.md) - Messaging, formatting, file uploads
|
|
194
|
+
- [Elasticsearch Operations](docs/getting-started/quickstart.md#elasticsearch-operations) - Query builders and search
|
|
195
|
+
- [Database Connections](docs/getting-started/quickstart.md#database-connections) - Connection pooling and queries
|
|
196
|
+
- [CloudWatch Metrics](docs/getting-started/quickstart.md#cloudwatch-metrics) - Performance tracking
|
|
197
|
+
4. **Testing** → Learn testing strategies ([guide](docs/development/testing.md))
|
|
198
|
+
|
|
199
|
+
**Complete documentation**: [docs/](docs/README.md)
|
|
200
|
+
|
|
201
|
+
## Usage Examples
|
|
202
|
+
|
|
203
|
+
Below are minimal examples to get you started. **For complete examples and detailed usage, see [docs/getting-started/quickstart.md](docs/getting-started/quickstart.md)**.
|
|
204
|
+
|
|
205
|
+
### Secrets Management
|
|
206
|
+
|
|
207
|
+
```python
|
|
208
|
+
from nui_lambda_shared_utils import get_secret, get_slack_credentials
|
|
209
|
+
|
|
210
|
+
# Generic secret retrieval
|
|
211
|
+
api_keys = get_secret("my-service/api-keys")
|
|
212
|
+
|
|
213
|
+
# Specialized getters with normalized field names
|
|
214
|
+
slack_creds = get_slack_credentials() # Uses configured secret name
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
**[→ See full secrets management guide](docs/getting-started/configuration.md#aws-secrets-manager)**
|
|
218
|
+
|
|
219
|
+
### AWS Powertools Integration
|
|
220
|
+
|
|
221
|
+
```python
|
|
222
|
+
from nui_lambda_shared_utils import get_powertools_logger, powertools_handler
|
|
223
|
+
|
|
224
|
+
# Create logger with Elasticsearch-compatible formatting
|
|
225
|
+
logger = get_powertools_logger("my-service", level="INFO")
|
|
226
|
+
|
|
227
|
+
# Decorate Lambda handler with logging, metrics, and error handling
|
|
228
|
+
@powertools_handler(
|
|
229
|
+
service_name="my-service",
|
|
230
|
+
metrics_namespace="MyApp/Service",
|
|
231
|
+
slack_alert_channel="#production-alerts"
|
|
232
|
+
)
|
|
233
|
+
@logger.inject_lambda_context
|
|
234
|
+
def lambda_handler(event, context):
|
|
235
|
+
logger.info("Processing event", extra={"event_id": event.get("id")})
|
|
236
|
+
return {"statusCode": 200, "body": "Success"}
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
**Features:**
|
|
240
|
+
|
|
241
|
+
- ✅ Elasticsearch-compatible timestamps (`2025-01-18T04:39:27.788Z`)
|
|
242
|
+
- ✅ Automatic Lambda context injection (function name, request ID, cold start)
|
|
243
|
+
- ✅ CloudWatch metrics publishing
|
|
244
|
+
- ✅ Slack error alerts with graceful degradation
|
|
245
|
+
- ✅ Local development with colored logs
|
|
246
|
+
|
|
247
|
+
**[→ See comprehensive Powertools integration guide](docs/guides/powertools-integration.md)**
|
|
248
|
+
|
|
249
|
+
### Slack Integration
|
|
250
|
+
|
|
251
|
+
```python
|
|
252
|
+
from nui_lambda_shared_utils import SlackClient, SlackBlockBuilder
|
|
253
|
+
|
|
254
|
+
slack = SlackClient()
|
|
255
|
+
|
|
256
|
+
# Simple message
|
|
257
|
+
slack.send_message(channel='#alerts', text='Service deployment complete')
|
|
258
|
+
|
|
259
|
+
# Rich formatted message with blocks
|
|
260
|
+
builder = SlackBlockBuilder()
|
|
261
|
+
blocks = builder.add_header("Alert", emoji="warning").add_section("Status", "Active").build()
|
|
262
|
+
slack.send_message(channel='#incidents', blocks=blocks)
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
**[→ See comprehensive Slack integration guide](docs/guides/slack-integration.md)**
|
|
266
|
+
|
|
267
|
+
### Elasticsearch Operations
|
|
268
|
+
|
|
269
|
+
```python
|
|
270
|
+
from nui_lambda_shared_utils import ElasticsearchClient, ESQueryBuilder
|
|
271
|
+
|
|
272
|
+
es = ElasticsearchClient()
|
|
273
|
+
query_builder = ESQueryBuilder()
|
|
274
|
+
query = query_builder.date_range("@timestamp", "now-1h", "now").term("level", "ERROR").build()
|
|
275
|
+
results = es.search(index="logs-*", body={"query": query})
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
**[→ See full Elasticsearch guide](docs/getting-started/quickstart.md#elasticsearch-operations)**
|
|
279
|
+
|
|
280
|
+
### Database Connections
|
|
281
|
+
|
|
282
|
+
```python
|
|
283
|
+
from nui_lambda_shared_utils import DatabaseClient
|
|
284
|
+
|
|
285
|
+
db = DatabaseClient()
|
|
286
|
+
|
|
287
|
+
# Execute queries with automatic retry and connection pooling
|
|
288
|
+
async with db.get_connection() as conn:
|
|
289
|
+
results = await conn.execute("SELECT * FROM orders WHERE status = %s", ["confirmed"])
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
**[→ See full database guide](docs/getting-started/quickstart.md#database-connections)**
|
|
293
|
+
|
|
294
|
+
### CloudWatch Metrics
|
|
295
|
+
|
|
296
|
+
```python
|
|
297
|
+
from nui_lambda_shared_utils import MetricsPublisher, track_lambda_performance
|
|
298
|
+
|
|
299
|
+
metrics = MetricsPublisher(namespace="MyApplication")
|
|
300
|
+
|
|
301
|
+
@track_lambda_performance(metrics)
|
|
302
|
+
def lambda_handler(event, context):
|
|
303
|
+
metrics.put_metric("ProcessedItems", 150, "Count")
|
|
304
|
+
return {"statusCode": 200}
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
**[→ See full metrics guide](docs/getting-started/quickstart.md#cloudwatch-metrics)**
|
|
308
|
+
|
|
309
|
+
### JWT Authentication
|
|
310
|
+
|
|
311
|
+
```python
|
|
312
|
+
from nui_lambda_shared_utils import require_auth, AuthenticationError
|
|
313
|
+
|
|
314
|
+
def lambda_handler(event, context):
|
|
315
|
+
try:
|
|
316
|
+
claims = require_auth(event) # Validates Bearer token from Authorization header
|
|
317
|
+
except AuthenticationError as e:
|
|
318
|
+
return {"statusCode": 401, "body": "Unauthorized"}
|
|
319
|
+
|
|
320
|
+
user_id = claims["sub"]
|
|
321
|
+
return {"statusCode": 200, "body": f"Hello {user_id}"}
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
**[→ See JWT authentication guide](docs/guides/jwt-authentication.md)**
|
|
325
|
+
|
|
326
|
+
### Error Handling
|
|
327
|
+
|
|
328
|
+
```python
|
|
329
|
+
from nui_lambda_shared_utils import with_retry, handle_lambda_error
|
|
330
|
+
|
|
331
|
+
@handle_lambda_error
|
|
332
|
+
@with_retry(max_attempts=3)
|
|
333
|
+
def lambda_handler(event, context):
|
|
334
|
+
# Your Lambda logic with automatic error handling and retries
|
|
335
|
+
return {"statusCode": 200}
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
**[→ See full error handling guide](docs/getting-started/quickstart.md#error-handling)**
|
|
339
|
+
|
|
340
|
+
## Configuration
|
|
341
|
+
|
|
342
|
+
The package supports multiple configuration methods. **For detailed configuration options, see [docs/getting-started/configuration.md](docs/getting-started/configuration.md)**.
|
|
343
|
+
|
|
344
|
+
### Environment Variables
|
|
345
|
+
|
|
346
|
+
```bash
|
|
347
|
+
ES_HOST=localhost:9200 # Elasticsearch host
|
|
348
|
+
ES_CREDENTIALS_SECRET=elasticsearch-creds # AWS secret name for ES
|
|
349
|
+
DB_CREDENTIALS_SECRET=database-creds # AWS secret name for database
|
|
350
|
+
SLACK_CREDENTIALS_SECRET=slack-bot-token # AWS secret name for Slack
|
|
351
|
+
AWS_REGION=us-east-1 # AWS region
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
### Programmatic Configuration
|
|
355
|
+
|
|
356
|
+
```python
|
|
357
|
+
import nui_lambda_shared_utils as nui
|
|
358
|
+
|
|
359
|
+
nui.configure(
|
|
360
|
+
es_host="localhost:9200",
|
|
361
|
+
slack_credentials_secret="dev/slack-token"
|
|
362
|
+
)
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
**[→ See complete configuration guide](docs/getting-started/configuration.md)**
|
|
366
|
+
|
|
367
|
+
## AWS Infrastructure Requirements
|
|
368
|
+
|
|
369
|
+
This package requires AWS Secrets Manager for credential storage and IAM permissions for CloudWatch metrics.
|
|
370
|
+
|
|
371
|
+
**For detailed AWS setup instructions, see [docs/getting-started/configuration.md#aws-infrastructure](docs/getting-started/configuration.md)**.
|
|
372
|
+
|
|
373
|
+
### Quick Reference
|
|
374
|
+
|
|
375
|
+
**Secrets Manager** - Store credentials as JSON:
|
|
376
|
+
|
|
377
|
+
- Elasticsearch: `{"host": "...", "username": "...", "password": "..."}`
|
|
378
|
+
- Database: `{"host": "...", "port": 3306, "username": "...", "password": "...", "database": "..."}`
|
|
379
|
+
- Slack: `{"bot_token": "xoxb-...", "webhook_url": "..."}`
|
|
380
|
+
- JWT Public Key: `{"TOKEN_PUBLIC_KEY": "-----BEGIN PUBLIC KEY-----\n..."}`
|
|
381
|
+
|
|
382
|
+
**IAM Permissions** - Lambda execution role needs:
|
|
383
|
+
|
|
384
|
+
- `secretsmanager:GetSecretValue` for credential access
|
|
385
|
+
- `cloudwatch:PutMetricData` for metrics publishing
|
|
386
|
+
|
|
387
|
+
**[→ See complete AWS infrastructure guide](docs/getting-started/configuration.md#aws-infrastructure)**
|
|
388
|
+
|
|
389
|
+
## Testing
|
|
390
|
+
|
|
391
|
+
**For comprehensive testing guide, see [docs/development/testing.md](docs/development/testing.md)**.
|
|
392
|
+
|
|
393
|
+
```bash
|
|
394
|
+
# Install with dev dependencies
|
|
395
|
+
pip install nui-python-shared-utils[dev]
|
|
396
|
+
|
|
397
|
+
# Run all tests
|
|
398
|
+
pytest
|
|
399
|
+
|
|
400
|
+
# Run with coverage
|
|
401
|
+
pytest --cov=nui_lambda_shared_utils --cov-report=html
|
|
402
|
+
|
|
403
|
+
# Run specific test categories
|
|
404
|
+
pytest -m unit # Unit tests only
|
|
405
|
+
pytest -m integration # Integration tests (requires AWS)
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
## Contributing
|
|
409
|
+
|
|
410
|
+
We welcome contributions! This package currently supports MySQL/PostgreSQL, Elasticsearch, Slack, and core AWS services (Secrets Manager, CloudWatch). **We're open to expanding support for additional databases (MongoDB, DynamoDB, etc.) and AWS services (SQS, SNS, EventBridge, etc.).**
|
|
411
|
+
|
|
412
|
+
### How to Contribute
|
|
413
|
+
|
|
414
|
+
1. Fork the repository
|
|
415
|
+
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
|
|
416
|
+
3. Commit your changes (`git commit -m 'Add amazing feature'`)
|
|
417
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
418
|
+
5. Open a Pull Request
|
|
419
|
+
|
|
420
|
+
### Contribution Ideas
|
|
421
|
+
|
|
422
|
+
- **Database integrations**: MongoDB, DynamoDB, Redis, Cassandra
|
|
423
|
+
- **AWS services**: SQS, SNS, EventBridge, Step Functions, S3, SES
|
|
424
|
+
- **Messaging platforms**: Microsoft Teams, Discord, PagerDuty
|
|
425
|
+
- **Monitoring**: Datadog, New Relic, Prometheus exporters
|
|
426
|
+
- **Search engines**: OpenSearch, Algolia, Typesense
|
|
427
|
+
- **CLI enhancements**: Additional automation commands for common workflows
|
|
428
|
+
|
|
429
|
+
See our [development guide](docs/development/testing.md) for testing patterns and architecture guidelines.
|
|
430
|
+
|
|
431
|
+
### Built-in CLI Tools
|
|
432
|
+
|
|
433
|
+
The package includes `slack-channel-setup` - a CLI tool for automating Slack workspace channel creation from YAML configuration files. This generic tool works with any Slack workspace and can be used independently of Lambda functions.
|
|
434
|
+
|
|
435
|
+
```bash
|
|
436
|
+
# Install and use
|
|
437
|
+
pip install nui-python-shared-utils[slack]
|
|
438
|
+
slack-channel-setup --config channels.yaml
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
## Documentation & Support
|
|
442
|
+
|
|
443
|
+
### 📚 Documentation
|
|
444
|
+
|
|
445
|
+
- **[Complete Documentation](docs/README.md)** - Comprehensive guides and references
|
|
446
|
+
- **[Quick Start Guide](docs/getting-started/quickstart.md)** - Get up and running fast
|
|
447
|
+
- **[Configuration Guide](docs/getting-started/configuration.md)** - Setup and AWS integration
|
|
448
|
+
- **[Slack Integration Guide](docs/guides/slack-integration.md)** - Detailed Slack features
|
|
449
|
+
- **[Testing Guide](docs/development/testing.md)** - Test strategies and coverage
|
|
450
|
+
|
|
451
|
+
### 🔗 Links
|
|
452
|
+
|
|
453
|
+
- **GitHub Repository**: https://github.com/nuimarkets/nui-python-shared-utils
|
|
454
|
+
- **Issue Tracker**: https://github.com/nuimarkets/nui-python-shared-utils/issues
|
|
455
|
+
- **PyPI Package**: https://pypi.org/project/nui-python-shared-utils/
|
|
456
|
+
- **Changelog**: [CHANGELOG.md](CHANGELOG.md)
|
|
457
|
+
|
|
458
|
+
### 💬 Support
|
|
459
|
+
|
|
460
|
+
- **Bug Reports**: [GitHub Issues](https://github.com/nuimarkets/nui-python-shared-utils/issues)
|
|
461
|
+
- **Feature Requests**: [GitHub Issues](https://github.com/nuimarkets/nui-python-shared-utils/issues)
|
|
462
|
+
- **Questions**: Check [docs/](docs/README.md) first, then open an issue
|
|
463
|
+
|
|
464
|
+
## License
|
|
465
|
+
|
|
466
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
467
|
+
|
|
468
|
+
## About NUI Markets
|
|
469
|
+
|
|
470
|
+
NUI Markets is a technology company focused on building innovative trading and marketplace platforms. This package represents our commitment to open-source tooling and production-grade infrastructure patterns for AWS Lambda development.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
nui_lambda_shared_utils/__init__.py,sha256=0yYLzo2zggr43W2zdybp7PBc5oPsU-kwh1M1r7CuFv4,6617
|
|
2
|
+
nui_lambda_shared_utils/base_client.py,sha256=I1lKQGhrKyvujV2zps0TrtEdPDqMCwRQaIh6ceGONXQ,11016
|
|
3
|
+
nui_lambda_shared_utils/cli.py,sha256=JJpSoQWKvAz4b8cO30yFNi5vY9jmqrCHzbFpvrVTkbU,8747
|
|
4
|
+
nui_lambda_shared_utils/cloudwatch_metrics.py,sha256=Rdyfy-3zAQqZkPL2krzjyB3FXYgrh7Hx56nVeT6eDIw,11836
|
|
5
|
+
nui_lambda_shared_utils/config.py,sha256=ZbkUKDxnHMJiHNv-TlWKjotmf2mH1Vz3GaIXgGfWg7E,4524
|
|
6
|
+
nui_lambda_shared_utils/db_client.py,sha256=HyVKJ1Su0dVPV1QI2MU5UtT8myDRCjKgV60xRL4SEdE,21726
|
|
7
|
+
nui_lambda_shared_utils/error_handler.py,sha256=pJ6b_mI0Ait8QRbs9UmLzYUN-Ft0l_dnpudVO_6LRSE,12171
|
|
8
|
+
nui_lambda_shared_utils/es_client.py,sha256=sSUouJqxc-Sx6NBBn8hXuOPohCd8--d4urRnRufCYrQ,15661
|
|
9
|
+
nui_lambda_shared_utils/es_query_builder.py,sha256=UuheQf8b2UXaOiJlYCKYIfKfVERDZ3ag1P0OOOWm9do,12158
|
|
10
|
+
nui_lambda_shared_utils/jwt_auth.py,sha256=2Ag1zZKxd2R8QBz3aQA4h8OtKHQvUVKrjUp6lXpJxJU,9143
|
|
11
|
+
nui_lambda_shared_utils/lambda_helpers.py,sha256=S47z9_snvntpPDAq5ukibIDHZi4gRA6S2E197h4_PQo,3048
|
|
12
|
+
nui_lambda_shared_utils/log_processors.py,sha256=x5gz1LEkbmoMCZ3ZB6q-mbn26dSzwh1trz4wSkBGxqk,5538
|
|
13
|
+
nui_lambda_shared_utils/powertools_helpers.py,sha256=pVu9MVBC6PEirHBbMC-9nKreP9jk8wd0fQt6OWekzdk,10126
|
|
14
|
+
nui_lambda_shared_utils/secrets_helper.py,sha256=38n6LZXNGY6mK24L6FEpE0JqcJYZRW2_2QTTtq16qYI,6054
|
|
15
|
+
nui_lambda_shared_utils/slack_client.py,sha256=_qR7Q1GU7gvYhUxiaBxEohhoEYznqr8kz9enGfeDtn8,24759
|
|
16
|
+
nui_lambda_shared_utils/slack_formatter.py,sha256=95g6XfAJst7RVhd0M0ahiF3gWWW5j96WYkCg5tLS6Zg,10894
|
|
17
|
+
nui_lambda_shared_utils/timezone.py,sha256=TvtSZV7w3Vvz3NbMTcJSNbUf0ZxPwpFS-xfgye1h-4Q,3583
|
|
18
|
+
nui_lambda_shared_utils/utils.py,sha256=oQQBmPA-0dM-XFRLBEBk_hh9FtRZyoY9_egmviyGemg,8146
|
|
19
|
+
nui_lambda_shared_utils/slack_setup/__init__.py,sha256=OElyS3xk4F_YKH5uUUTDpN0ah1dOO3e52muIPjAMPW8,320
|
|
20
|
+
nui_lambda_shared_utils/slack_setup/channel_creator.py,sha256=0gyCBIS0EC96SVn1Z2dD4Fpzk0xNdHSWyiCxoUQIUe8,10667
|
|
21
|
+
nui_lambda_shared_utils/slack_setup/channel_definitions.py,sha256=atfz5ZhpqefOeLh1gShbWd-TLzgjPmhv95bfuTdmZog,5676
|
|
22
|
+
nui_lambda_shared_utils/slack_setup/setup_helpers.py,sha256=pzzXMs12GI9sdZttWeYzgLPgC0xqPz7ZLHM1GUPNNXc,7219
|
|
23
|
+
nui_python_shared_utils-1.3.0.dist-info/licenses/LICENSE,sha256=vGe2mC5yLUb8toYlY3T36ZwCB5zQUW5hlCtEMiqokhM,1071
|
|
24
|
+
nui_python_shared_utils-1.3.0.dist-info/METADATA,sha256=R0KQDsvlYB_Z42-uT_LZ1-ieLXue3boYQXGgsYyZ08U,19464
|
|
25
|
+
nui_python_shared_utils-1.3.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
26
|
+
nui_python_shared_utils-1.3.0.dist-info/entry_points.txt,sha256=bc4qjyeqRhvYoBi2IPolcjzl_CUo5t3IuMqj3xpOhFc,73
|
|
27
|
+
nui_python_shared_utils-1.3.0.dist-info/top_level.txt,sha256=BS4v7fSMh5wHB6GBfyr_STatz2YZfm22m0GQ7df3uh0,24
|
|
28
|
+
nui_python_shared_utils-1.3.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 NUI Markets Ltd
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
nui_lambda_shared_utils
|