Lib to connect python/django modules to redshift
Project description
Weni Datalake SDK
The Weni Datalake SDK is a Python library that provides an interface to interact with Weni's data lake services. It supports operations for sending data, managing message templates, and handling traces.
Installation
pip install weni-datalake-sdk
Environment Variables
Before using the SDK, make sure to set up the following environment variables:
DATALAKE_SERVER_ADDRESS=your_server_address
REDSHIFT_QUERY_BASE_URL=your_redshift_url
REDSHIFT_SECRET=your_secret
REDSHIFT_ROLE_ARN=your_role_arn
MESSAGE_TEMPLATES_METRIC_NAME=your_metric_name
TRACES_METRIC_NAME=your_trace_metric_name
Usage Examples
1. Sending Data
✅ Correct Usage:
from weni_datalake_sdk.clients.client import send_data
from weni_datalake_sdk.paths.your_path import YourPath
# Prepare your data
data = {
"field1": "value1",
"field2": "value2"
}
# Send data using a path class
send_data(YourPath, data)
# Or using an instantiated path
path = YourPath()
send_data(path, data)
❌ Incorrect Usage:
# DON'T: Send data without proper path validation
send_data("invalid_path", data)
# DON'T: Send data without required environment variables
# Make sure DATALAKE_SERVER_ADDRESS is set
2. Working with Message Templates
✅ Correct Usage:
from weni_datalake_sdk.clients.redshift.message_templates import get_message_templates
# Get templates with specific parameters
result = get_message_templates(
contact_urn="contact123",
template_id="template456",
query_params={"additional": "params"}
)
# Get templates with just query parameters
result = get_message_templates(
query_params={"status": "active"}
)
❌ Incorrect Usage:
# DON'T: Call without required environment variables
# Make sure MESSAGE_TEMPLATES_METRIC_NAME is set
# DON'T: Pass invalid parameter types
get_message_templates(contact_urn=123) # Should be string
3. Working with Traces
✅ Correct Usage:
from weni_datalake_sdk.clients.redshift.traces import get_traces
# Get traces with query parameters
result = get_traces(
query_params={
"start_date": "2024-01-01",
"end_date": "2024-01-31"
}
)
❌ Incorrect Usage:
# DON'T: Call without required environment variables
# Make sure TRACES_METRIC_NAME is set
# DON'T: Pass invalid query parameters
get_traces(query_params="invalid") # Should be a dictionary
4. Sending Message Template Data
✅ Correct Usage:
from weni_datalake_sdk.clients.client import send_message_template_data
from weni_datalake_sdk.paths.message_template import MessageTemplatePath
template_data = {
"template_id": "template123",
"content": "Hello, {{name}}!",
"status": "approved"
}
status = send_message_template_data(MessageTemplatePath, template_data)
Error Handling
The SDK includes proper error handling. Always wrap your calls in try-except blocks:
try:
result = get_message_templates(template_id="template123")
except Exception as e:
print(f"Error: {e}")
Best Practices
- Environment Variables: Always ensure all required environment variables are set before using the SDK.
- Path Validation: Use proper path classes instead of raw strings.
- Error Handling: Implement proper error handling in your code.
- Data Types: Ensure you're passing the correct data types for each parameter.
- Security: Never hardcode sensitive information like tokens or credentials.
Common Issues and Solutions
-
Connection Issues
- Ensure
DATALAKE_SERVER_ADDRESSis correct and accessible - Check your network connectivity
- Ensure
-
Authentication Errors
- Verify your AWS credentials are properly configured
- Check if
REDSHIFT_SECRETandREDSHIFT_ROLE_ARNare correct
-
Missing Environment Variables
- Double-check all required environment variables are set
- Use a
.envfile for local development
Contributing
For contributing to this SDK, please follow these steps:
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
License
[Include license information here]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file weni_datalake_sdk-0.2.1a0.tar.gz.
File metadata
- Download URL: weni_datalake_sdk-0.2.1a0.tar.gz
- Upload date:
- Size: 23.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.11.6 Linux/5.15.167.4-microsoft-standard-WSL2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
32ef294accdfdbbdb64b3202ff261be33457cac8f5f91d9c06f4daeef28130a8
|
|
| MD5 |
354664b64a773c6bab6c033ef3b93ea6
|
|
| BLAKE2b-256 |
48eaf6ee38942c8ef7d7f25f6559b21f4f5b73f728474a1e5dad35b7ff6008fa
|
File details
Details for the file weni_datalake_sdk-0.2.1a0-py3-none-any.whl.
File metadata
- Download URL: weni_datalake_sdk-0.2.1a0-py3-none-any.whl
- Upload date:
- Size: 33.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.11.6 Linux/5.15.167.4-microsoft-standard-WSL2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a1ab2216dae2cb7d236f29b68b28ddf01e5e391b155fb09ad811b3c3a0300c4a
|
|
| MD5 |
f91183b8fa1c69d5b5af2ca9aee02e2d
|
|
| BLAKE2b-256 |
59f09bd30409385676fb2f34573531bccd292c62206be06be6557f7bb26aac1a
|