This guide covers installation, dependency management, and environment setup for nui-python-shared-utils.
- Python 3.9 or higher
- AWS credentials configured for Secrets Manager access
- Optional: AWS CLI for credential management
# Basic installation with core dependencies
pip install nui-python-shared-utilsThe package uses optional extras to minimize Lambda bundle size. Install only the integrations you need:
# Slack integration only
pip install nui-python-shared-utils[slack]
# Elasticsearch integration only
pip install nui-python-shared-utils[elasticsearch]
# Database integration only
pip install nui-python-shared-utils[database]
# JWT authentication only
pip install nui-python-shared-utils[jwt]
# All integrations
pip install nui-python-shared-utils[all]
# Development dependencies
pip install nui-python-shared-utils[dev]For local development and testing:
# Clone the repository
git clone https://github.com/nuimarkets/nui-python-shared-utils.git
cd nui-python-shared-utils
# Install in development mode with all dependencies
pip install -e .[dev]boto3- AWS SDK for Pythonpytz- Timezone handlingclick- CLI frameworkpyyaml- YAML configuration parsing
elasticsearch>=7.17.0,<8.0.0- Elasticsearch client
pymysql>=1.0.0- MySQL driverpsycopg2-binary>=2.9.0- PostgreSQL driver
slack-sdk>=3.19.0- Official Slack SDK
rsa>=4.9- Pure Python RSA implementation (~100KB, no C extensions)
pytest>=7.0.0- Testing frameworkpytest-cov>=4.0.0- Coverage reportingpytest-mock>=3.10.0- Mocking utilitiesmoto>=4.0.0- AWS service mockingblack>=22.0.0- Code formattingmypy>=0.990- Type checkingboto3-stubs[essential]>=1.20.0- Type stubs for boto3twine>=4.0.0- Package publishingbuild>=0.8.0- Package building
# Create virtual environment
python -m venv venv
# Activate (Linux/Mac)
source venv/bin/activate
# Activate (Windows)
venv\Scripts\activate
# Install package
pip install nui-python-shared-utils[all]# Create environment
conda create -n nui-utils python=3.9
# Activate environment
conda activate nui-utils
# Install package
pip install nui-python-shared-utils[all]The package requires AWS credentials with Secrets Manager access:
# Configure AWS CLI (if not already done)
aws configure
# Or set environment variables
export AWS_ACCESS_KEY_ID=your-access-key
export AWS_SECRET_ACCESS_KEY=your-secret-key
export AWS_DEFAULT_REGION=us-east-1Your AWS credentials need these permissions:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"secretsmanager:GetSecretValue"
],
"Resource": "arn:aws:secretsmanager:*:*:secret:*"
},
{
"Effect": "Allow",
"Action": [
"cloudwatch:PutMetricData"
],
"Resource": "*"
}
]
}For AWS Lambda deployment, consider using the package as a layer:
# Create layer directory structure
mkdir python
pip install nui-python-shared-utils[all] -t python/
# Create layer zip
zip -r nui-utils-layer.zip python/
# Upload to AWS Lambda Layers (via AWS CLI)
aws lambda publish-layer-version \
--layer-name nui-lambda-shared-utils \
--description "NUI Lambda Shared Utilities" \
--zip-file fileb://nui-utils-layer.zip \
--compatible-runtimes python3.9 python3.10 python3.11# In your Lambda function code
import nui_shared_utils as nui
# Configure and use
nui.configure(
es_host="your-es-host:9200",
slack_credentials_secret="prod/slack-token"
)Test your installation:
import nui_shared_utils as nui
# Check version
print(nui.__version__) # Should print version number
# Test configuration
config = nui.get_config()
print(config.to_dict()) # Should show default configuration
# Test optional imports (will be None if not installed)
print(f"Elasticsearch: {nui.ElasticsearchClient is not None}")
print(f"Database: {nui.DatabaseClient is not None}")ImportError: No module named 'elasticsearch'
Solution: Install with the appropriate extra:
pip install nui-python-shared-utils[elasticsearch]NoCredentialsError: Unable to locate credentials
Solution: Configure AWS credentials using aws configure or environment variables.
ERROR: pip's dependency resolver does not currently consider all the ways...
Solution: Use a fresh virtual environment or update conflicting packages.
- Check the Troubleshooting Guide
- Review GitHub Issues
- Consult the Configuration Guide for setup details