# Handyman
Common utility framework for ML Services
## Install
1. To install the handyman library, please use the following command in case of [_pip_](https://pip.pypa.io/en/stable/):
```
pip install handyman
```
* Or add handyman as a poetry dependency.
```
handyman = 0.3.5
```
> Requires Python 3.7 or greater
## Usage
The handyman library currently consists of the following packages:
* `exceptions`
* `io`
* `json_utils`
* `log`
* `prometheus`
* `sentry`
* `crypto`
* `events`
To use any of the packages stated above, please use:
```py
from handyman import <package name>
```
### Crypto Module
Full example of new client onboarding to encryption/decryption to deletion of the client
##### Generate data key for client (onboarding)
``` python
from handyman.crypto import generate_new_data_key
# Random client uuid for example usage purpose
client_uuid = '6a624995-a0f4-43e1-b331-1716457962ce'
# Generate data key for new client (while onboarding)
generate_new_data_key(client_uuid)
# Output - ('vault:v1:tXZ4nHIs3G8xhbLWMuMM8kzdLDgG7pr8B/uyNTz8svK2maNFZM8tkwU/ribGQQO6/5K7Pg2TeOSLia2b', None)
# Store the variable for example usage purpose
encrypted_data_key = 'vault:v1:tXZ4nHIs3G8xhbLWMuMM8kzdLDgG7pr8B/uyNTz8svK2maNFZM8tkwU/ribGQQO6/5K7Pg2TeOSLia2b'
```
##### Encrypt data with newly created client
``` python
from handyman.crypto import encrypt_string
# Encrypt plaintext
encrypt_string("hello world", client_uuid, encrypted_data_key)
# Output - ('GICD7oOmX0KbaBzeqzvOxtmK2ntjRH7kiFMmgKH8F6FYbvibASCM', None)
# Store the variable for example usage purpose
encrypted_data = 'GICD7oOmX0KbaBzeqzvOxtmK2ntjRH7kiFMmgKH8F6FYbvibASCM'
```
##### Decrypt data with the same client
``` python
from handyman.crypto import decrypt_base64_string
# Decrypt data (2nd return parameter is an exception if any)
decrypt_base64_string(encrypted_data, client_uuid, encrypted_data_key)
# Output - (b'hello world', None)
# Decrypt data to string (2nd return parameter is an exception if any)
decrypt_base64_string(encrypted_data, client_uuid, encrypted_data_key, decode_to_str=True)
# Output - ('hello world', None)
```
##### Delete client (offboarding)
``` python
from handyman.crypto import transit_delete_key
# Delete client (offboarding)
transit_delete_key(client_uuid)
```
### Events Module
The purpose of this module is to seamlessly integrate usage of event driven systems for python codebases.
Example usage -
``` python
from handyman.events import send_messages, Events, use_credentials
# Set custom aws credentials (from env/file)
use_credentials("<aws_access_key_id>", "<aws_secret_access_key>", "<aws_region>")
# Send messages
(success, failed_messages), err = send_messages('<queue_name>', ["hello", "world"], Events.<event_type>)
# success - bool
# failed_messages - messages failed to send with message id
# err - Exceptions captured
```
To send a cost event:
```py
import handyman.events as events
events.send_cost_event(
events.Service.ASR, events.Vendor.GOOGLE, "client_uuid", "flow_uuid", "call_uuid", "conversation_uuid"
)
# if you want to count single event as multiple hits
events.send_cost_event(
events.Service.ASR, events.Vendor.GOOGLE, "client_uuid", "flow_uuid", "call_uuid", "conversation_uuid", num_hits=2
)
```
## Publish
Create a distribution package:
python setup.py sdist
Publish to PyPi:
pip install twine
twine upload dist/*
You will be prompted to enter username and password, if you don't have credentials contact `@devops`.
Raw data
{
"_id": null,
"home_page": "https://gitlab.com/vernacularai/tools/handyman",
"name": "handyman",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.5",
"maintainer_email": "",
"keywords": "",
"author": "Skit.ai",
"author_email": "deepankar@vernacular.ai",
"download_url": "https://files.pythonhosted.org/packages/a9/3f/5d6f2bb5754c1bd5732ef6d599b865f1480dcce11ec69b8d8e14f1af13b2/handyman-0.3.6.tar.gz",
"platform": "Posix; MacOS X; Windows",
"description": "# Handyman\n\nCommon utility framework for ML Services\n\n## Install\n\n1. To install the handyman library, please use the following command in case of [_pip_](https://pip.pypa.io/en/stable/):\n\n```\n pip install handyman\n```\n\n* Or add handyman as a poetry dependency.\n\n```\n handyman = 0.3.5\n```\n\n> Requires Python 3.7 or greater\n\n## Usage\n\nThe handyman library currently consists of the following packages:\n\n* `exceptions`\n* `io`\n* `json_utils`\n* `log`\n* `prometheus`\n* `sentry`\n* `crypto`\n* `events`\n\nTo use any of the packages stated above, please use:\n\n```py\nfrom handyman import <package name>\n```\n\n### Crypto Module\n\nFull example of new client onboarding to encryption/decryption to deletion of the client\n\n##### Generate data key for client (onboarding)\n``` python\n from handyman.crypto import generate_new_data_key\n\n # Random client uuid for example usage purpose\n client_uuid = '6a624995-a0f4-43e1-b331-1716457962ce'\n\n # Generate data key for new client (while onboarding)\n generate_new_data_key(client_uuid)\n # Output - ('vault:v1:tXZ4nHIs3G8xhbLWMuMM8kzdLDgG7pr8B/uyNTz8svK2maNFZM8tkwU/ribGQQO6/5K7Pg2TeOSLia2b', None)\n\n # Store the variable for example usage purpose\n encrypted_data_key = 'vault:v1:tXZ4nHIs3G8xhbLWMuMM8kzdLDgG7pr8B/uyNTz8svK2maNFZM8tkwU/ribGQQO6/5K7Pg2TeOSLia2b'\n```\n\n##### Encrypt data with newly created client\n``` python\n from handyman.crypto import encrypt_string\n\n # Encrypt plaintext\n encrypt_string(\"hello world\", client_uuid, encrypted_data_key)\n # Output - ('GICD7oOmX0KbaBzeqzvOxtmK2ntjRH7kiFMmgKH8F6FYbvibASCM', None)\n\n # Store the variable for example usage purpose\n encrypted_data = 'GICD7oOmX0KbaBzeqzvOxtmK2ntjRH7kiFMmgKH8F6FYbvibASCM'\n```\n\n##### Decrypt data with the same client\n``` python\n from handyman.crypto import decrypt_base64_string\n\n # Decrypt data (2nd return parameter is an exception if any)\n decrypt_base64_string(encrypted_data, client_uuid, encrypted_data_key)\n # Output - (b'hello world', None)\n # Decrypt data to string (2nd return parameter is an exception if any)\n decrypt_base64_string(encrypted_data, client_uuid, encrypted_data_key, decode_to_str=True)\n # Output - ('hello world', None)\n```\n\n##### Delete client (offboarding)\n``` python\n from handyman.crypto import transit_delete_key\n\n # Delete client (offboarding)\n transit_delete_key(client_uuid)\n```\n\n### Events Module\n\nThe purpose of this module is to seamlessly integrate usage of event driven systems for python codebases.\n\nExample usage -\n\n``` python\n from handyman.events import send_messages, Events, use_credentials\n\n # Set custom aws credentials (from env/file)\n use_credentials(\"<aws_access_key_id>\", \"<aws_secret_access_key>\", \"<aws_region>\")\n\n # Send messages\n (success, failed_messages), err = send_messages('<queue_name>', [\"hello\", \"world\"], Events.<event_type>)\n # success - bool\n # failed_messages - messages failed to send with message id\n # err - Exceptions captured\n```\n\nTo send a cost event:\n```py\nimport handyman.events as events\n\nevents.send_cost_event(\n events.Service.ASR, events.Vendor.GOOGLE, \"client_uuid\", \"flow_uuid\", \"call_uuid\", \"conversation_uuid\"\n)\n\n# if you want to count single event as multiple hits\nevents.send_cost_event(\n events.Service.ASR, events.Vendor.GOOGLE, \"client_uuid\", \"flow_uuid\", \"call_uuid\", \"conversation_uuid\", num_hits=2\n)\n```\n\n\n## Publish\n\nCreate a distribution package:\n\n python setup.py sdist\n\nPublish to PyPi:\n\n\n pip install twine\n\n twine upload dist/*\n\nYou will be prompted to enter username and password, if you don't have credentials contact `@devops`.\n",
"bugtrack_url": null,
"license": "Apache 2.0",
"summary": "Skit utils package for ML Services",
"version": "0.3.6",
"project_urls": {
"Homepage": "https://gitlab.com/vernacularai/tools/handyman"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "a93f5d6f2bb5754c1bd5732ef6d599b865f1480dcce11ec69b8d8e14f1af13b2",
"md5": "b6965d3385ec00d4e2bfdec821e10e37",
"sha256": "edb6502b0f7d12387c9474ffb9d85c282feed9a3ac604f0d462336a91898b3c6"
},
"downloads": -1,
"filename": "handyman-0.3.6.tar.gz",
"has_sig": false,
"md5_digest": "b6965d3385ec00d4e2bfdec821e10e37",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.5",
"size": 20464,
"upload_time": "2023-06-20T05:53:55",
"upload_time_iso_8601": "2023-06-20T05:53:55.561753Z",
"url": "https://files.pythonhosted.org/packages/a9/3f/5d6f2bb5754c1bd5732ef6d599b865f1480dcce11ec69b8d8e14f1af13b2/handyman-0.3.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-06-20 05:53:55",
"github": false,
"gitlab": true,
"bitbucket": false,
"codeberg": false,
"gitlab_user": "vernacularai",
"gitlab_project": "tools",
"lcname": "handyman"
}