custom-utils


Namecustom-utils JSON
Version 0.0.313 PyPI version JSON
download
home_pagehttps://github.com/RahulnKumar/custom-utils
SummaryUtilities for database connectors, slack alerter, loggers etc
upload_time2023-05-31 11:30:09
maintainer
docs_urlNone
authorRahul Kumar
requires_python>=3.6.9
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # custom-utils
Pip Package for Database Connectors, Alerter, Log Formatter etc


***

<p float="left">
  <img src=https://img.shields.io/pypi/v/custom-utils />
  <img src=https://www.code-inspector.com/project/29426/score/svg />
  <img src=https://img.shields.io/pypi/dm/custom-utils?logo=Python&style=social /> 
  <a href="https://github.com/RahulnKumar/custom-utils/blob/main/LICENSE"><img alt="GitHub license" src="https://img.shields.io/github/license/RahulnKumar/custom-utils"></a>
</p>
 

## Table of Contents

- [custom-utils](#custom-utils)
  - [Table of Contents](#table-of-contents)
  - [1.  Installation](#1--installation)
  - [2. Connector](#2-connector)
    - [1. S3 Connector](#1-s3-connector)
    - [2. MySQL Connector](#2-mysql-connector)
    - [3.  MongoDB Connector](#3--mongodb-connector)
    - [4.  BigQuery Connector](#4--bigquery-connector)
  - [3. Configurer](#3-configurer)
    - [1. Profile Decorator](#1-profile-decorator)
    - [2.  Log Formatter](#2--log-formatter)
  - [4. Alerter](#4-alerter)
    - [1.  Slack Alerter](#1--slack-alerter)

***

## 1.  Installation<a id="1--installation">    

- **Installation from Pypi repository** (Any one)
	
    `pip install custom-utils`  --> minimal installation  
    `pip install custom-utils[full]` --> full installation (linux/windows)  
    `pip install "custom-utils[full]"` --> full installation (mac)  
    `pip install custom-utils[s3,mysql,bigquery,mongodb,slack]`  --> selective installation 
- **Installation from github repository** (Any one)  
	
    `pip install git+https://github.com/rahulnkumar/custom-utils.git`  
    `pip install git+https://github.com/rahulnkumar/custom-utils.git@<tag_no>`  
    `pip install git+https://github.com/rahulnkumar/custom-utils.git@<branch_name>`    

<img src="https://i.ibb.co/WHwqTpr/pip-cu.gif" alt="pip-cu" border="0">
    
---
    
	
## 2. Connector<a id="2-connector">

    
### 1. S3 Connector<a id="1-s3-connector">     

**Code Snippet Sample :**
```python
## To use S3 either setup AWS CLI or set the credentials from pip package only

## Setup AWS CLI
sudo apt install awscli && aws configure

## Setup Credentials from pip package
from custom_utils.configurer.utils import Credential
Credential.set(ACCESS_KEY="*********", SECRET_KEY="*********")


from custom_utils.connector.s3 import S3
# Upload python object to S3
S3.push_python_object(python_object, s3_uri)

# Pull python object from S3
obj = S3.pull_python_object(s3_uri)

# AWS CLI setup is must to use the following methods 
# Uplaoding local data to S3
S3.push_local_data(file_path, s3_uri)
                                
# Downloading data from S3
S3.pull_s3_data(file_path, s3_uri)
```

**S3 Connector Documentation**
    
```
class S3(builtins.object)
 |  AWS S3 utility functions
 |  
 |  Static methods defined here:
 |  
 |  pull_python_object(s3_uri)
 |      read python object stored in S3 bucket
 |      :param string s3_uri: s3 uri of the object
 |      :return python_object : python object stored in the S3
 |  
 |  pull_s3_data(file_path, s3_uri)
 |      write data stored in local machine into S3 bucket from
 |      :param string s3_uri: target s3 uri
 |      :param string file_path:  local path of the file 
 |      :return None
 |  
 |  push_local_data(file_path, s3_uri)
 |      write data stored in local machine into S3 bucket from
 |      :param string s3_uri: target s3 uri
 |      :param string file_path:  local path of the file 
 |      :return None
 |  
 |  push_python_object(python_object, s3_uri)
 |      write python objects/variables etc  into S3 bucket
 |      :param string bucket: bucket name
 |      :param string sub_bucket: sub-bucket name
 |      :param string file_name: name of the file to be written
 |      :return None
 |  
 |  read_csv(s3_uri)
 |      write data stored in local machine into S3 bucket from
 |      :param string s3_uri: csv file S3 URI
 |      :return df : pandas dataframe
 |  
 |  ----------------------------------------------------------------------
  
```
---
    

---
   
### 2. MySQL Connector<a id="2-mysql-connector">  
  
**Code Snippet Sample :**  
```python
# Query from Custom MySQL Database
from custom_utils.connector.mysql import MySQL 
user = "***"
password = "***"
host = "***"
port = "***"
database = "***"
db_string = f"mysql+mysqlconnector://{user}:{password}@{host}:{port}/{database}"
query = "select * from table_name limit 10"
mysql = MySQL(db_string=db_string)
df = mysql.pull_data(query = query) 
```
    
**MySQL Connector Documentaion**
```
class MySQL(builtins.object)
 |  MySQL(db_string)
 |  
 |  MySQL database utility functions
 |  
 |  Methods defined here:
 |  
 |  __init__(self, db_string)
 |      initialisation method for MySQL Connector
 |      :param string db_string: mysql database connection string
 |  
 |  push_data(self, data, table_name, mode='append')
 |      Execute a query in the mysql table
 |      :param pd.DataFrame data: dataframe to be appended or replaced
 |      :param string table_name: name of the the target table
 |      :param string mode: it can be either replace or append
 |      :return None
 |  
 |  execute_query(self, query)
 |      Execute a query in the mysql table
 |      :param string query: query for execution in the table
 |      :return :
 |  
 |  pull_data(self, query)
 |      Fetch data from mysql as a dataframe.
 |      :param string query: query for fetching data from table
 |      :return pd.DataFrame data
```
    
---
    
    
### 3.  MongoDB Connector<a id="3--mongodb-connector">
    
**Code Snippet Sample :**  
```python
from custom_utils.connector.mongodb import MongoDB
uri = "****"
db = "***"
collection = "****"
mongo = MongoDb(uri = uri, db = db)

#Reading with pull method
data =  mongo.pull_data(collection=collection, list_dict=list_dict)

# Reading with fetch method
query = {'id': {'$in': [1,2]}}
data = mongo.fetch_data(collection, query=query, only_include_keys=["name"])

#Writing into MongoDB
mongo.push_data(collection = collection, data = data)

#Updating value
id_dict = {"id":"2"}
set_dict = {"$set": {"name":"ram"}}
mongo.update_value(id_dict, set_dict,collection=collection, upsert=True)

# Deleting data
mongo.delete_data(collection=collection, overall=False, condition_dict= {"id":None})

```

 **MongoDB Connector Documentaion**
```    
class MongoDB(builtins.object)
 |  MongoDB(db=None, uri=None)
 |  
 |  MongoDB utility functions.
 |  
 |  Methods defined here:
 |  
 |  __init__(self, db=None, uri=None)
 |      initialisation method for MongoDB connector
 |      :param str db: database name
 |      :param str uri: mongo uri string for establishing connection
 |  
 |  delete_data(self, collection, db=None, overall=False, condition_dict=None)
 |      Function for inserting data into db
 |      :param str db : database name
 |      :param str collection : collection name
 |      :param bool overall : delete whole collection if True
 |      :param dict condition_dict : query for deletion
 |      :return:
 |  
 |  fetch_data(self, collection, db=None, query={}, only_include_keys=[])
 |      function to fetch data from the given database and collection on given query
 |      :param str db : db_name in mongo
 |      :param str collection: collection name in mongo for database db
 |      :param dict query : execution query statement; default is {} which means fetch
 |                         all without any filters
 |      :param list only_include_keys : list of keys to be included while fetching rows
 |      :return: pd.DataFrame
 |  
 |  fetch_data_sorted(self, collection, db=None, pipeline=[])
 |      function to fetch data from the given database and collection on given query
 |      :param str db: db_name in mongo
 |      :param str collection: collection name in mongo for database db
 |      :param list pipeline: pipeline required to aggregate
 |      :return: pd.DataFrame
 |  
 |  pull_data(self, list_dict, collection, db=None)
 |      Function for inserting data into db
 |      :param str db : database name
 |      :param str collection : collection name
 |      :param list list_dict : query for fetching data
 |      :return: pd.DataFrame
 |  
 |  push_data(self, data, collection, db=None)
 |      Function for inserting data into db
 |      :param str db : database name
 |      :param str collection : collection name
 |      :param list/pd.DataFrame data : data to be inserted in the form of
 |                                      dataframe or list of dictionaries
 |      :return:
 |  
 |  update_value(self, id_dict, set_dict, collection, db=None, upsert=None)
 |      Function for updating data into db
 |      :param str db : database name
 |      :param str collection : collection name
 |      :param dict id_dict : query for updation
 |      :param dict set_dict : key and value dictionary to be updated
 |      :param bool upsert : whether to upsert or just update
 |      :return:
 |  
 |  upsert_json(self, output_json, upsert_keys, collection, db=None)
 |      Function for inserting data into db
 |      :param str db : database name
 |      :param str collection : collection name
 |      :param dict output_json : list of dictionaries where each dictionary is
 |                                a row with keys as column names
 |      :param list upsert_keys : keys to be upserted
 |      :return:
 |  
 |  ----------------------------------------------------------------------
```
---
	
### 4.  BigQuery Connector<a id="4--bigquery-connector">
    
**Code Snippet Sample :**  
```python

# Fetching data from BigQuery
from custom_utils.connector.bigquery import BigQuery
bq = BigQuery(read_big_query_project = "****",
                    service_account_file_path="***.json")
query = "select * from table_name"
df = bq.pull_data(query)

# Dumping Dataframe in BigQuery
bq.push_data(database="rahul_temp", table="demo", dataframe=df, mode="append")

# Executing any query in BigQuery
query = "INSERT rahul_temp.Demo (id, userId) VALUES(1,1),(1,1)"
BigQuery.execute_query(query)

# Streaming insert in BigQuery
row_to_insert = [{"id": 1, "userid": 1, "languageId": 58,
             "mode":0,"active":1}]
BigQuery.insert_rows_in_bigquery(dataset="rahul_temp", table="Demo", rows_to_insert=row_to_insert)

```
    
**BigQuery Connector Documentaion**
```
class BigQuery(builtins.object)
 |  BigQuery(read_big_query_project, write_big_query_project, service_account_file_path)
 |  
 |  BigQuery database utility functions
 |  
 |  Methods defined here:
 |  
 |  __init__(self, read_big_query_project, write_big_query_project, service_account_file_path)
 |      initialisation method for BigQuery Connector
 |      :param str read_big_query_project : project used while reading from BigQuery
 |      :param str write_big_query_project: project used while writing into BigQuery
 |      :param str service_account_file_path: project specific BigQuery Credential
 |  
 |  push_data(self, database=None, table=None, dataframe=None, mode='append')
 |      Dumps data into from BigQuery
 |      :param string database: target bigquery database
 |      :param string table: target table name
 |      :param pd.DataFrame dataframe: pandas dataframe for dumping into bigquery
 |      :param string mode: it can be either append or replace
 |  
 |  execute_query(self, query, job_config=None, timeout=900, max_retries=0, time_interval=5)
 |      Executes query from from BigQuery table
 |      :param string query: query for execution
 |      :param string query_cofig: config for parameterised query
 |      :param integer timeout : maximum bigquery execution timeout
 |      :param string max_retries: maximum retries if data is not fetched
 |      :param integer time_interval : time interval between retries
 |  
 |  pull_data(self, query=None, job_config=None, max_retries=0, time_interval=5)
 |      Fetches data from from BigQuery
 |      :param string query: query for fetching data from table
 |      :param string query_cofig: config for parameterised query
 |      :param string max_retries: maximum retries if data is not fetched
 |      :param integer time_interval : time interval between retries
 |  
 |  insert_rows_array(self, dataset=None, table=None, rows_to_insert=None)
 |      Streaming insert into from BigQuery
 |      :param string dataset: target bigquery database
 |      :param string table: target table name
 |      :param list rows_to_insert: list of dictionaries where each dictionary is a
 |                                  row with keys as column names
 |  
 |  insert_rows_in_bigquery(self, dataset=None, table=None, rows_to_insert=None)
 |      Streaming insert into from BigQuery
 |      :param string dataset: target bigquery database
 |      :param string table: target table name
 |      :param  rows_to_insert: list of dictionaries where each dictionary is a
 |                              row with keys as column names
```
---
	
	
## 3. Configurer<a id="3-configurer">   
	
### 1. Profile Decorator<a id="1-profile-decorator">    
    
**Code Snippet Sample :**  
```python
from custom_utils.configurer.profiler import profiler
@profiler(sort_by='cumulative', lines_to_print=10, strip_dirs=True)
def product_counter_v3():
    return [1, 2, 3, 4, 5]
```
**Profiler Documentaion**
```python
def profiler(output_file=None, sort_by='cumulative', lines_to_print=None, strip_dirs=False):
    """
    A time profiler decorator

    :param str output_file: Path of the output file. If only name of the file is given, it's saved in the current
    directory. If it's None, the name of the decorated function is used.
    :param str sort_by: SortKey enum or tuple/list of str/SortKey enum Sorting criteria for the Stats object. For a list
    of valid string and SortKey refer to: https://docs.python.org/3/library/profile.html#pstats.Stats.sort_stats
    :param int lines_to_print: Number of lines to print. Default (None) is for all the lines. This is useful in reducing
    the size of the printout, especially that sorting by 'cumulative', the time consuming operations are printed toward
    the top of the file.
    :param bool strip_dirs: Whether to remove the leading path info from file names. This is also useful in reducing the
    size of the printout
    :return: Profile of the decorated function
    """
```
###  2.  Log Formatter<a id="2--log-formatter">
 
**Code Snippet Sample :**
```python
from custom_utils.configurer.utils import LogFormatter
LogFormatter.apply()
```
    
**Log Formatter Documentation**
```
class LogFormatter(logging.Formatter):
    """Log Formatter class for custom-utils package"""

    __date_format = '%d/%b/%Y:%H:%M:%S %Z'

    @staticmethod
    def apply(level=logging.INFO):
        """
        Start logging in json format.
        :return:
```
---
	
	
## 4. Alerter<a id="4-alerter">    
	
###  1.  Slack Alerter<a id="1--slack-alerter">  
    
    
**Code Snippet Sample :**
```python3
from custom_utils.alerter.slack import Slack
slack = Slack(token=SLACK_BOT_TOKEN) # OR Slack() with  SLACK_BOT_TOKEN as env variable
channel="#shield"
message = "testing"    
uids = ["U03PAP8C1RC", "U03PAP8C1RC"]
slack.send_alert(channel, message, uids)
```
    
**Alerter Documentation :**
```python
class Slack(builtins.object)
 |  Slack(token=None)
 |
 |  Class for sending alerts and monitoring stats to a slack channel
 |
 |  Methods defined here:
 |
 |  __init__(self, token=None)
 |      Initialize self.  See help(type(self)) for accurate signature.
 |
 |  send_alert(self, channel: str, message: str, uids: list = [])
 |      This function send alert to a target channel tagging a user
 |                          with a alert message and traceback error.
 |      args:
 |          channel     : Name of the channel (ex : #channel_name)
 |          message     : Pass the message to be displayed in the channel
 |          uids        : List of Slack user_ids  who needs to be tagged
 |
 |      returns: Nothing
 |
 |  ----------------------------------------------------------------------
```
---

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/RahulnKumar/custom-utils",
    "name": "custom-utils",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6.9",
    "maintainer_email": "",
    "keywords": "",
    "author": "Rahul Kumar",
    "author_email": "rahulnkumar7@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/d9/93/8c29756c39e12bad70be5ef6d46b95730558292879636c69e5b965efd845/custom-utils-0.0.313.tar.gz",
    "platform": null,
    "description": "# custom-utils\nPip Package for Database Connectors, Alerter, Log Formatter etc\n\n\n***\n\n<p float=\"left\">\n  <img src=https://img.shields.io/pypi/v/custom-utils />\n  <img src=https://www.code-inspector.com/project/29426/score/svg />\n  <img src=https://img.shields.io/pypi/dm/custom-utils?logo=Python&style=social /> \n  <a href=\"https://github.com/RahulnKumar/custom-utils/blob/main/LICENSE\"><img alt=\"GitHub license\" src=\"https://img.shields.io/github/license/RahulnKumar/custom-utils\"></a>\n</p>\n \n\n## Table of Contents\n\n- [custom-utils](#custom-utils)\n  - [Table of Contents](#table-of-contents)\n  - [1.  Installation](#1--installation)\n  - [2. Connector](#2-connector)\n    - [1. S3 Connector](#1-s3-connector)\n    - [2. MySQL Connector](#2-mysql-connector)\n    - [3.  MongoDB Connector](#3--mongodb-connector)\n    - [4.  BigQuery Connector](#4--bigquery-connector)\n  - [3. Configurer](#3-configurer)\n    - [1. Profile Decorator](#1-profile-decorator)\n    - [2.  Log Formatter](#2--log-formatter)\n  - [4. Alerter](#4-alerter)\n    - [1.  Slack Alerter](#1--slack-alerter)\n\n***\n\n## 1.  Installation<a id=\"1--installation\">    \n\n- **Installation from Pypi repository** (Any one)\n\t\n    `pip install custom-utils`  --> minimal installation  \n    `pip install custom-utils[full]` --> full installation (linux/windows)  \n    `pip install \"custom-utils[full]\"` --> full installation (mac)  \n    `pip install custom-utils[s3,mysql,bigquery,mongodb,slack]`  --> selective installation \n- **Installation from github repository** (Any one)  \n\t\n    `pip install git+https://github.com/rahulnkumar/custom-utils.git`  \n    `pip install git+https://github.com/rahulnkumar/custom-utils.git@<tag_no>`  \n    `pip install git+https://github.com/rahulnkumar/custom-utils.git@<branch_name>`    \n\n<img src=\"https://i.ibb.co/WHwqTpr/pip-cu.gif\" alt=\"pip-cu\" border=\"0\">\n    \n---\n    \n\t\n## 2. Connector<a id=\"2-connector\">\n\n    \n### 1. S3 Connector<a id=\"1-s3-connector\">     \n\n**Code Snippet Sample :**\n```python\n## To use S3 either setup AWS CLI or set the credentials from pip package only\n\n## Setup AWS CLI\nsudo apt install awscli && aws configure\n\n## Setup Credentials from pip package\nfrom custom_utils.configurer.utils import Credential\nCredential.set(ACCESS_KEY=\"*********\", SECRET_KEY=\"*********\")\n\n\nfrom custom_utils.connector.s3 import S3\n# Upload python object to S3\nS3.push_python_object(python_object, s3_uri)\n\n# Pull python object from S3\nobj = S3.pull_python_object(s3_uri)\n\n# AWS CLI setup is must to use the following methods \n# Uplaoding local data to S3\nS3.push_local_data(file_path, s3_uri)\n                                \n# Downloading data from S3\nS3.pull_s3_data(file_path, s3_uri)\n```\n\n**S3 Connector Documentation**\n    \n```\nclass S3(builtins.object)\n |  AWS S3 utility functions\n |  \n |  Static methods defined here:\n |  \n |  pull_python_object(s3_uri)\n |      read python object stored in S3 bucket\n |      :param string s3_uri: s3 uri of the object\n |      :return python_object : python object stored in the S3\n |  \n |  pull_s3_data(file_path, s3_uri)\n |      write data stored in local machine into S3 bucket from\n |      :param string s3_uri: target s3 uri\n |      :param string file_path:  local path of the file \n |      :return None\n |  \n |  push_local_data(file_path, s3_uri)\n |      write data stored in local machine into S3 bucket from\n |      :param string s3_uri: target s3 uri\n |      :param string file_path:  local path of the file \n |      :return None\n |  \n |  push_python_object(python_object, s3_uri)\n |      write python objects/variables etc  into S3 bucket\n |      :param string bucket: bucket name\n |      :param string sub_bucket: sub-bucket name\n |      :param string file_name: name of the file to be written\n |      :return None\n |  \n |  read_csv(s3_uri)\n |      write data stored in local machine into S3 bucket from\n |      :param string s3_uri: csv file S3 URI\n |      :return df : pandas dataframe\n |  \n |  ----------------------------------------------------------------------\n  \n```\n---\n    \n\n---\n   \n### 2. MySQL Connector<a id=\"2-mysql-connector\">  \n  \n**Code Snippet Sample :**  \n```python\n# Query from Custom MySQL Database\nfrom custom_utils.connector.mysql import MySQL \nuser = \"***\"\npassword = \"***\"\nhost = \"***\"\nport = \"***\"\ndatabase = \"***\"\ndb_string = f\"mysql+mysqlconnector://{user}:{password}@{host}:{port}/{database}\"\nquery = \"select * from table_name limit 10\"\nmysql = MySQL(db_string=db_string)\ndf = mysql.pull_data(query = query) \n```\n    \n**MySQL Connector Documentaion**\n```\nclass MySQL(builtins.object)\n |  MySQL(db_string)\n |  \n |  MySQL database utility functions\n |  \n |  Methods defined here:\n |  \n |  __init__(self, db_string)\n |      initialisation method for MySQL Connector\n |      :param string db_string: mysql database connection string\n |  \n |  push_data(self, data, table_name, mode='append')\n |      Execute a query in the mysql table\n |      :param pd.DataFrame data: dataframe to be appended or replaced\n |      :param string table_name: name of the the target table\n |      :param string mode: it can be either replace or append\n |      :return None\n |  \n |  execute_query(self, query)\n |      Execute a query in the mysql table\n |      :param string query: query for execution in the table\n |      :return :\n |  \n |  pull_data(self, query)\n |      Fetch data from mysql as a dataframe.\n |      :param string query: query for fetching data from table\n |      :return pd.DataFrame data\n```\n    \n---\n    \n    \n### 3.  MongoDB Connector<a id=\"3--mongodb-connector\">\n    \n**Code Snippet Sample :**  \n```python\nfrom custom_utils.connector.mongodb import MongoDB\nuri = \"****\"\ndb = \"***\"\ncollection = \"****\"\nmongo = MongoDb(uri = uri, db = db)\n\n#Reading with pull method\ndata =  mongo.pull_data(collection=collection, list_dict=list_dict)\n\n# Reading with fetch method\nquery = {'id': {'$in': [1,2]}}\ndata = mongo.fetch_data(collection, query=query, only_include_keys=[\"name\"])\n\n#Writing into MongoDB\nmongo.push_data(collection = collection, data = data)\n\n#Updating value\nid_dict = {\"id\":\"2\"}\nset_dict = {\"$set\": {\"name\":\"ram\"}}\nmongo.update_value(id_dict, set_dict,collection=collection, upsert=True)\n\n# Deleting data\nmongo.delete_data(collection=collection, overall=False, condition_dict= {\"id\":None})\n\n```\n\n **MongoDB Connector Documentaion**\n```    \nclass MongoDB(builtins.object)\n |  MongoDB(db=None, uri=None)\n |  \n |  MongoDB utility functions.\n |  \n |  Methods defined here:\n |  \n |  __init__(self, db=None, uri=None)\n |      initialisation method for MongoDB connector\n |      :param str db: database name\n |      :param str uri: mongo uri string for establishing connection\n |  \n |  delete_data(self, collection, db=None, overall=False, condition_dict=None)\n |      Function for inserting data into db\n |      :param str db : database name\n |      :param str collection : collection name\n |      :param bool overall : delete whole collection if True\n |      :param dict condition_dict : query for deletion\n |      :return:\n |  \n |  fetch_data(self, collection, db=None, query={}, only_include_keys=[])\n |      function to fetch data from the given database and collection on given query\n |      :param str db : db_name in mongo\n |      :param str collection: collection name in mongo for database db\n |      :param dict query : execution query statement; default is {} which means fetch\n |                         all without any filters\n |      :param list only_include_keys : list of keys to be included while fetching rows\n |      :return: pd.DataFrame\n |  \n |  fetch_data_sorted(self, collection, db=None, pipeline=[])\n |      function to fetch data from the given database and collection on given query\n |      :param str db: db_name in mongo\n |      :param str collection: collection name in mongo for database db\n |      :param list pipeline: pipeline required to aggregate\n |      :return: pd.DataFrame\n |  \n |  pull_data(self, list_dict, collection, db=None)\n |      Function for inserting data into db\n |      :param str db : database name\n |      :param str collection : collection name\n |      :param list list_dict : query for fetching data\n |      :return: pd.DataFrame\n |  \n |  push_data(self, data, collection, db=None)\n |      Function for inserting data into db\n |      :param str db : database name\n |      :param str collection : collection name\n |      :param list/pd.DataFrame data : data to be inserted in the form of\n |                                      dataframe or list of dictionaries\n |      :return:\n |  \n |  update_value(self, id_dict, set_dict, collection, db=None, upsert=None)\n |      Function for updating data into db\n |      :param str db : database name\n |      :param str collection : collection name\n |      :param dict id_dict : query for updation\n |      :param dict set_dict : key and value dictionary to be updated\n |      :param bool upsert : whether to upsert or just update\n |      :return:\n |  \n |  upsert_json(self, output_json, upsert_keys, collection, db=None)\n |      Function for inserting data into db\n |      :param str db : database name\n |      :param str collection : collection name\n |      :param dict output_json : list of dictionaries where each dictionary is\n |                                a row with keys as column names\n |      :param list upsert_keys : keys to be upserted\n |      :return:\n |  \n |  ----------------------------------------------------------------------\n```\n---\n\t\n### 4.  BigQuery Connector<a id=\"4--bigquery-connector\">\n    \n**Code Snippet Sample :**  \n```python\n\n# Fetching data from BigQuery\nfrom custom_utils.connector.bigquery import BigQuery\nbq = BigQuery(read_big_query_project = \"****\",\n                    service_account_file_path=\"***.json\")\nquery = \"select * from table_name\"\ndf = bq.pull_data(query)\n\n# Dumping Dataframe in BigQuery\nbq.push_data(database=\"rahul_temp\", table=\"demo\", dataframe=df, mode=\"append\")\n\n# Executing any query in BigQuery\nquery = \"INSERT rahul_temp.Demo (id, userId) VALUES(1,1),(1,1)\"\nBigQuery.execute_query(query)\n\n# Streaming insert in BigQuery\nrow_to_insert = [{\"id\": 1, \"userid\": 1, \"languageId\": 58,\n             \"mode\":0,\"active\":1}]\nBigQuery.insert_rows_in_bigquery(dataset=\"rahul_temp\", table=\"Demo\", rows_to_insert=row_to_insert)\n\n```\n    \n**BigQuery Connector Documentaion**\n```\nclass BigQuery(builtins.object)\n |  BigQuery(read_big_query_project, write_big_query_project, service_account_file_path)\n |  \n |  BigQuery database utility functions\n |  \n |  Methods defined here:\n |  \n |  __init__(self, read_big_query_project, write_big_query_project, service_account_file_path)\n |      initialisation method for BigQuery Connector\n |      :param str read_big_query_project : project used while reading from BigQuery\n |      :param str write_big_query_project: project used while writing into BigQuery\n |      :param str service_account_file_path: project specific BigQuery Credential\n |  \n |  push_data(self, database=None, table=None, dataframe=None, mode='append')\n |      Dumps data into from BigQuery\n |      :param string database: target bigquery database\n |      :param string table: target table name\n |      :param pd.DataFrame dataframe: pandas dataframe for dumping into bigquery\n |      :param string mode: it can be either append or replace\n |  \n |  execute_query(self, query, job_config=None, timeout=900, max_retries=0, time_interval=5)\n |      Executes query from from BigQuery table\n |      :param string query: query for execution\n |      :param string query_cofig: config for parameterised query\n |      :param integer timeout : maximum bigquery execution timeout\n |      :param string max_retries: maximum retries if data is not fetched\n |      :param integer time_interval : time interval between retries\n |  \n |  pull_data(self, query=None, job_config=None, max_retries=0, time_interval=5)\n |      Fetches data from from BigQuery\n |      :param string query: query for fetching data from table\n |      :param string query_cofig: config for parameterised query\n |      :param string max_retries: maximum retries if data is not fetched\n |      :param integer time_interval : time interval between retries\n |  \n |  insert_rows_array(self, dataset=None, table=None, rows_to_insert=None)\n |      Streaming insert into from BigQuery\n |      :param string dataset: target bigquery database\n |      :param string table: target table name\n |      :param list rows_to_insert: list of dictionaries where each dictionary is a\n |                                  row with keys as column names\n |  \n |  insert_rows_in_bigquery(self, dataset=None, table=None, rows_to_insert=None)\n |      Streaming insert into from BigQuery\n |      :param string dataset: target bigquery database\n |      :param string table: target table name\n |      :param  rows_to_insert: list of dictionaries where each dictionary is a\n |                              row with keys as column names\n```\n---\n\t\n\t\n## 3. Configurer<a id=\"3-configurer\">   \n\t\n### 1. Profile Decorator<a id=\"1-profile-decorator\">    \n    \n**Code Snippet Sample :**  \n```python\nfrom custom_utils.configurer.profiler import profiler\n@profiler(sort_by='cumulative', lines_to_print=10, strip_dirs=True)\ndef product_counter_v3():\n    return [1, 2, 3, 4, 5]\n```\n**Profiler Documentaion**\n```python\ndef profiler(output_file=None, sort_by='cumulative', lines_to_print=None, strip_dirs=False):\n    \"\"\"\n    A time profiler decorator\n\n    :param str output_file: Path of the output file. If only name of the file is given, it's saved in the current\n    directory. If it's None, the name of the decorated function is used.\n    :param str sort_by: SortKey enum or tuple/list of str/SortKey enum Sorting criteria for the Stats object. For a list\n    of valid string and SortKey refer to: https://docs.python.org/3/library/profile.html#pstats.Stats.sort_stats\n    :param int lines_to_print: Number of lines to print. Default (None) is for all the lines. This is useful in reducing\n    the size of the printout, especially that sorting by 'cumulative', the time consuming operations are printed toward\n    the top of the file.\n    :param bool strip_dirs: Whether to remove the leading path info from file names. This is also useful in reducing the\n    size of the printout\n    :return: Profile of the decorated function\n    \"\"\"\n```\n###  2.  Log Formatter<a id=\"2--log-formatter\">\n \n**Code Snippet Sample :**\n```python\nfrom custom_utils.configurer.utils import LogFormatter\nLogFormatter.apply()\n```\n    \n**Log Formatter Documentation**\n```\nclass LogFormatter(logging.Formatter):\n    \"\"\"Log Formatter class for custom-utils package\"\"\"\n\n    __date_format = '%d/%b/%Y:%H:%M:%S %Z'\n\n    @staticmethod\n    def apply(level=logging.INFO):\n        \"\"\"\n        Start logging in json format.\n        :return:\n```\n---\n\t\n\t\n## 4. Alerter<a id=\"4-alerter\">    \n\t\n###  1.  Slack Alerter<a id=\"1--slack-alerter\">  \n    \n    \n**Code Snippet Sample :**\n```python3\nfrom custom_utils.alerter.slack import Slack\nslack = Slack(token=SLACK_BOT_TOKEN) # OR Slack() with  SLACK_BOT_TOKEN as env variable\nchannel=\"#shield\"\nmessage = \"testing\"    \nuids = [\"U03PAP8C1RC\", \"U03PAP8C1RC\"]\nslack.send_alert(channel, message, uids)\n```\n    \n**Alerter Documentation :**\n```python\nclass Slack(builtins.object)\n |  Slack(token=None)\n |\n |  Class for sending alerts and monitoring stats to a slack channel\n |\n |  Methods defined here:\n |\n |  __init__(self, token=None)\n |      Initialize self.  See help(type(self)) for accurate signature.\n |\n |  send_alert(self, channel: str, message: str, uids: list = [])\n |      This function send alert to a target channel tagging a user\n |                          with a alert message and traceback error.\n |      args:\n |          channel     : Name of the channel (ex : #channel_name)\n |          message     : Pass the message to be displayed in the channel\n |          uids        : List of Slack user_ids  who needs to be tagged\n |\n |      returns: Nothing\n |\n |  ----------------------------------------------------------------------\n```\n---\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Utilities for database connectors, slack alerter, loggers etc",
    "version": "0.0.313",
    "project_urls": {
        "Homepage": "https://github.com/RahulnKumar/custom-utils"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4ec5331fccb8652b01cb89552805a3d9e135ee8a624803311a879bc8c6b71341",
                "md5": "621a982bbf3c55da27213b0139923fc5",
                "sha256": "94c9e8741ed93ad6a11f2cfffe3adf1279a662395dccafa92fc5ca070aa73d14"
            },
            "downloads": -1,
            "filename": "custom_utils-0.0.313-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "621a982bbf3c55da27213b0139923fc5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6.9",
            "size": 16971,
            "upload_time": "2023-05-31T11:30:06",
            "upload_time_iso_8601": "2023-05-31T11:30:06.791749Z",
            "url": "https://files.pythonhosted.org/packages/4e/c5/331fccb8652b01cb89552805a3d9e135ee8a624803311a879bc8c6b71341/custom_utils-0.0.313-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d9938c29756c39e12bad70be5ef6d46b95730558292879636c69e5b965efd845",
                "md5": "0896e5b7faa473031ce20bea09850e76",
                "sha256": "45cc7b74760d204e502efe4e1077d9785431c596be311f209a6f8f6b8f402e58"
            },
            "downloads": -1,
            "filename": "custom-utils-0.0.313.tar.gz",
            "has_sig": false,
            "md5_digest": "0896e5b7faa473031ce20bea09850e76",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6.9",
            "size": 17389,
            "upload_time": "2023-05-31T11:30:09",
            "upload_time_iso_8601": "2023-05-31T11:30:09.557014Z",
            "url": "https://files.pythonhosted.org/packages/d9/93/8c29756c39e12bad70be5ef6d46b95730558292879636c69e5b965efd845/custom-utils-0.0.313.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-31 11:30:09",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "RahulnKumar",
    "github_project": "custom-utils",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "custom-utils"
}
        
Elapsed time: 0.07042s