Lib to connect python/django modules to redshift
Project description
Weni Data Lake SDK
The Weni Data Lake 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
In case you are using poetry, you can add the package to your project with the following command:
poetry add 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
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)
2. Working with Message Templates
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"
)
3. Working with Traces
from weni_datalake_sdk.clients.redshift.traces import get_traces
# Get traces with query parameters
result = get_traces(
query_params={
"message_uuid": "123e4567-e89b-12d3-a456-426614174000"
}
)
4. Sending Message Template Data
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
This project is licensed under the MIT License - see the LICENSE file for details.
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.2a0.tar.gz.
File metadata
- Download URL: weni_datalake_sdk-0.2.2a0.tar.gz
- Upload date:
- Size: 26.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.11.6 Linux/6.6.87.1-microsoft-standard-WSL2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e3ea82ff57d4f4ffe31e5d281c7b675c4fbe8a7b7937aeb3e603feca4db38d0e
|
|
| MD5 |
9dad763b90105884870bd84f9bbbe1bf
|
|
| BLAKE2b-256 |
4a908ab53e562395b43e74e17ae339ffee0eabe718b18817e2990a306c9a92c8
|
File details
Details for the file weni_datalake_sdk-0.2.2a0-py3-none-any.whl.
File metadata
- Download URL: weni_datalake_sdk-0.2.2a0-py3-none-any.whl
- Upload date:
- Size: 38.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.11.6 Linux/6.6.87.1-microsoft-standard-WSL2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
286ea0a751c4a2348eb3a096bb13d1657da6874ab7befb711d17fcf1477edd2c
|
|
| MD5 |
66785ab4d9fb7c2fe5da2ef38e216566
|
|
| BLAKE2b-256 |
6b31c13832161c3e8db6be9d6b1a82093eb89a91293eb8aabf96ebfab7763e5b
|