A sample test package
Project description
afl-ai-utils
rm -rf build dist
python3 setup.py sdist bdist_wheel
twine upload --repository pypi dist/*
Installation
pip install afl-ai-utils
Usage
Slack Alerting
from afl_ai_utils.slack_alerts import send_slack_alert
send_slack_alert(info_alert_slack_webhook_url=None, red_alert_slack_webhook_url=None, slack_red_alert_userids=None, payload=None, is_red_alert=False)
"""Send a Slack message to a channel via a webhook.
Args:
info_alert_slack_webhook_url(str): Infor slack channel url
red_alert_slack_webhook_url(str): red alert channel url
slack_red_alert_userids (list): userid's to mention in slack for red alert notification
payload (dict): Dictionary containing Slack message, i.e. {"text": "This is a test"}
is_red_alert (bool): Full Slack webhook URL for your chosen channel.
Returns:
HTTP response code, i.e. <Response [503]>
"""
BigQuery Dataframe to BigQuery
def write_insights_to_bq_table(self, dataframe=None, schema=None, table_id=None, mode=None):
>>> from afl_ai_utils.bigquery_utils import BigQuery
>>> bq = BigQuery("keys.json")
>>> bq.write_insights_to_bq_table(dataframe=None, schema=None, table_id=None, mode=None)
"""Insert a dataframe to bigquery
Args:
dataframe(pandas dataframe): for dataframe to be dumped to bigquery
schema(BigQuery.Schema ): ex:
schema = [
bigquery.SchemaField("date_range_start", bigquery.enums.SqlTypeNames.DATE),
bigquery.SchemaField("date_range_end", bigquery.enums.SqlTypeNames.DATE)
]
table_id (list): table_id in which dataframe need to be inserted e.g project_id.dataset.table_name = table_id
mode(str): To append or replace the table - e.g mode = "append" or mode="replace"
Returns:
returns as success message with number of inserted rows and table name
"""
Execute any query to BigQuery
def execute_query(self, query):
>>> from afl_ai_utils.bigquery_utils import BigQuery
>>> bq = BigQuery("keys.json")
>>> df = bq.execute_query(query = "SELECT * FROM TABLE")
"""
Args:
query (query of any type SELECT/INSERT/DELETE )
Returns:
returns dataframe of execute query result
"""
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
afl-ai-utils-0.0.6.tar.gz
(3.6 kB
view hashes)
Built Distribution
Close
Hashes for afl_ai_utils-0.0.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26a0f8784c9ef1510cc11a8b3da1c6ce8b97f5e8383ad7405259851f5bc6acea |
|
MD5 | 4d78c8a7e52f91c3c83d45c4c2017add |
|
BLAKE2b-256 | 3c6fae8d9c2210f279746dd3f499f1b0368b5c5ce467ab18c48b19c6ef7157db |