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
To insert data into the data lake, you need to set the following environment variables:
DATALAKE_SERVER_ADDRESS=your_server_address
To get data from the data lake, you need to set the following environment variables:
REDSHIFT_QUERY_BASE_URL=your_redshift_url
REDSHIFT_SECRET=your_secret
REDSHIFT_ROLE_ARN=your_role_arn
MESSAGE_TEMPLATES_METRIC_NAME=your_metric_name (if you want to get message templates)
TRACES_METRIC_NAME=your_trace_metric_name (if you want to get traces)
EVENTS_METRIC_NAME=your_event_metric_name (if you want to get events)
Although you will need some AWS credentials to get data from the data lake, you can use the following environment variables:
AWS_ACCESS_KEY_ID=your_access_key_id
AWS_SECRET_ACCESS_KEY=your_secret_access_key
AWS_DEFAULT_REGION=your_region
This is important that we will use assumed role to get data from the data lake.
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. Send Event Data
from weni_datalake_sdk.clients.client import send_event_data
from weni_datalake_sdk.paths.events_path import EventPath
# Prepare your data
data = {
"event_name": "event_name",
"key": "key",
"value": "value",
"value_type": "value_type",
"date": "2021-01-01",
"project": "project_uuid",
"contact_urn": "contact_urn",
"metadata": {
"field1": "value1",
"field2": "value2"
}
}
2. Get 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_uuid="template_uuid"
)
3. Get 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. Get Events
from weni_datalake_sdk.clients.redshift.events import get_events
# Get events with query parameters
result = get_events(
query_params={
"date_start": "2021-01-01", # date_start is required
"date_end": "2021-01-01", # date_end is required
"project": "project_uuid", # project is optional
"event_type": "event_type", # event_type is optional
"contact_urn": "contact_urn", # contact_urn is optional
"event_name": "event_name", # event_name is optional
"key": "key", # key is optional
"value": "value", # value is optional
"value_type": "value_type" # value_type is optional
}
)
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.3.0a3.tar.gz.
File metadata
- Download URL: weni_datalake_sdk-0.3.0a3.tar.gz
- Upload date:
- Size: 29.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.5 CPython/3.11.13 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e3b4fab3581545689bb4ac9602cd05f09846502cb868f6d6c54e1e9088e15a93
|
|
| MD5 |
217e24261b2852fdb4523bae890bb74b
|
|
| BLAKE2b-256 |
26a18ec65806ed475dfddff13e4978b4369a8740c2335a46e1fd7672bcd39424
|
File details
Details for the file weni_datalake_sdk-0.3.0a3-py3-none-any.whl.
File metadata
- Download URL: weni_datalake_sdk-0.3.0a3-py3-none-any.whl
- Upload date:
- Size: 44.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.5 CPython/3.11.13 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47084adc6bb92f4b89cbec958ecb0c8f98489484902f4a82c199632389eb54eb
|
|
| MD5 |
5cfbac69da33ca66a7f38f0801e549b2
|
|
| BLAKE2b-256 |
0e29c362381e59e2a7ffae2d10619af9f1119d6a4dd6b261d81270b152aed91c
|