# b-utils-infra
`b-utils-infra` is a collection of utility functions and classes designed to streamline and enhance your Python
projects. The
library is organized into several modules, each catering to different categories of utilities, including logging, client
interactions, data manipulation with pandas, and general-purpose functions.
# Supported Python Versions
Python >= 3.10
# Unsupported Python Versions
Python < 3.10
## Installation
You can install `b-utils-infra` using pip:
```bash
pip install b-utils-infra
```
## Structure
The library is organized into the following modules:
1. logging.py: Utilities for logging with SlackAPI and writing to a file.
2. ai.py: Utilities for working with AI models, such as token count, tokenization, and text generation.
3. translation.py: Utilities for working with translation APIs (Supported Google Translate and DeepL).
4. services.py: Services-related utilities, such as creating google service.
5. pandas.py: Utilities for working with pandas dataframes, (df cleaning, insertion into databases...)
6. generic.py: Miscellaneous utilities that don't fit into the other specific categories (retry, run in thread,
validate, etc.).
## Usage
Here are few examples, for more details, please refer to the docstrings in the source code.
Logging Utilities
```python
from b_utils_infra.logging import SlackLogger
logger = SlackLogger(project_name="your-project-name", slack_token="your-slack-token", slack_channel_id="channel-id")
logger.info("This is an info message")
logger.error(exc=Exception, header_message="Header message appears above the exception message in the Slack message")
```
Services Utilities
```python
from b_utils_infra.services import get_google_service
google_sheet_service = get_google_service(google_token_path='common/google_token.json',
google_credentials_path='common/google_credentials.json',
service_name='sheets')
```
Pandas Utilities
```python
import pandas as pd
from b_utils_infra.pandas import clean_dataframe, insert_df_into_db_in_chunks
from connections import sqlalchemy_client # Your database connection client
df = pd.read_csv("data.csv")
clean_df = clean_dataframe(df)
with sqlalchemy_client.connect() as db_connection:
insert_df_into_db_in_chunks(
df=clean_df,
table_name="table_name",
conn=db_connection,
if_exists='append',
truncate_table=True,
index=False,
dtype=None,
chunk_size=20_000
)
```
Generic Utilities
```python
from b_utils_infra.generic import retry_with_timeout, validate_numeric_value, run_threaded, Timer
@retry_with_timeout(retries=3, timeout=5)
def fetch_data(arg1, arg2):
# function logic here
pass
with Timer() as t:
fetch_data("arg1", "arg2")
print(t.seconds_taken) # Output: Time taken to run fetch_data function (in seconds)
print(t.minutes_taken) # Output: Time taken to run fetch_data function (in minutes)
run_threaded(fetch_data, arg1="arg1", arg2="arg2")
is_valid = validate_numeric_value(123)
print(is_valid) # Output: True
```
## License
This project is licensed under the MIT License. See the LICENSE file for details.
# Changelog
## [0.2.0] - 2024-06-26:
### Added
- Support for `google-cloud-translate` V3 API.
- Support for OpenAI modules `gpt-4o` and `gpt-4o-2024-05-13` in `ai.calculate_openai_price`
### Fixed
- Issue with json parsing in `ai.TextGenerator.get_ai_response`.
### Changed
- Default openai model to `gpt-4o-2024` in `ai.TextGenerator.get_ai_response`.
- Updated Readme file with more examples.
## [0.1.0] - 2024-06-25 initial release
### Added
- Initial release of the package.
Raw data
{
"_id": null,
"home_page": "https://github.com/Fahadukr/b-utils-infra",
"name": "b-utils-infra",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": null,
"author": "Fahad Mawlood",
"author_email": "fahadukr@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/f3/99/b2291f188615ed4281331d640be6c27d7ee4e1d7169e6b1d0529d2c33b21/b-utils-infra-0.2.1.tar.gz",
"platform": null,
"description": "# b-utils-infra\r\n\r\n`b-utils-infra` is a collection of utility functions and classes designed to streamline and enhance your Python\r\nprojects. The\r\nlibrary is organized into several modules, each catering to different categories of utilities, including logging, client\r\ninteractions, data manipulation with pandas, and general-purpose functions.\r\n\r\n# Supported Python Versions\r\n\r\nPython >= 3.10\r\n\r\n# Unsupported Python Versions\r\n\r\nPython < 3.10\r\n\r\n## Installation\r\n\r\nYou can install `b-utils-infra` using pip:\r\n\r\n```bash\r\npip install b-utils-infra\r\n```\r\n\r\n## Structure\r\n\r\nThe library is organized into the following modules:\r\n\r\n1. logging.py: Utilities for logging with SlackAPI and writing to a file.\r\n2. ai.py: Utilities for working with AI models, such as token count, tokenization, and text generation.\r\n3. translation.py: Utilities for working with translation APIs (Supported Google Translate and DeepL).\r\n4. services.py: Services-related utilities, such as creating google service.\r\n5. pandas.py: Utilities for working with pandas dataframes, (df cleaning, insertion into databases...)\r\n6. generic.py: Miscellaneous utilities that don't fit into the other specific categories (retry, run in thread,\r\n validate, etc.).\r\n\r\n## Usage\r\n\r\nHere are few examples, for more details, please refer to the docstrings in the source code.\r\n\r\nLogging Utilities\r\n\r\n```python\r\nfrom b_utils_infra.logging import SlackLogger\r\n\r\nlogger = SlackLogger(project_name=\"your-project-name\", slack_token=\"your-slack-token\", slack_channel_id=\"channel-id\")\r\nlogger.info(\"This is an info message\")\r\nlogger.error(exc=Exception, header_message=\"Header message appears above the exception message in the Slack message\")\r\n```\r\n\r\nServices Utilities\r\n\r\n```python\r\nfrom b_utils_infra.services import get_google_service\r\n\r\ngoogle_sheet_service = get_google_service(google_token_path='common/google_token.json',\r\n google_credentials_path='common/google_credentials.json',\r\n service_name='sheets')\r\n```\r\n\r\nPandas Utilities\r\n\r\n```python\r\nimport pandas as pd\r\nfrom b_utils_infra.pandas import clean_dataframe, insert_df_into_db_in_chunks\r\n\r\nfrom connections import sqlalchemy_client # Your database connection client\r\n\r\ndf = pd.read_csv(\"data.csv\")\r\nclean_df = clean_dataframe(df)\r\nwith sqlalchemy_client.connect() as db_connection:\r\n insert_df_into_db_in_chunks(\r\n df=clean_df,\r\n table_name=\"table_name\",\r\n conn=db_connection,\r\n if_exists='append',\r\n truncate_table=True,\r\n index=False,\r\n dtype=None,\r\n chunk_size=20_000\r\n )\r\n```\r\n\r\nGeneric Utilities\r\n\r\n```python\r\nfrom b_utils_infra.generic import retry_with_timeout, validate_numeric_value, run_threaded, Timer\r\n\r\n\r\n@retry_with_timeout(retries=3, timeout=5)\r\ndef fetch_data(arg1, arg2):\r\n # function logic here\r\n pass\r\n\r\n\r\nwith Timer() as t:\r\n fetch_data(\"arg1\", \"arg2\")\r\nprint(t.seconds_taken) # Output: Time taken to run fetch_data function (in seconds)\r\nprint(t.minutes_taken) # Output: Time taken to run fetch_data function (in minutes)\r\n\r\nrun_threaded(fetch_data, arg1=\"arg1\", arg2=\"arg2\")\r\n\r\nis_valid = validate_numeric_value(123)\r\nprint(is_valid) # Output: True\r\n```\r\n\r\n## License\r\n\r\nThis project is licensed under the MIT License. See the LICENSE file for details.\r\n\r\n\r\n\r\n# Changelog\r\n\r\n## [0.2.0] - 2024-06-26:\r\n\r\n### Added\r\n\r\n- Support for `google-cloud-translate` V3 API.\r\n- Support for OpenAI modules `gpt-4o` and `gpt-4o-2024-05-13` in `ai.calculate_openai_price`\r\n\r\n### Fixed\r\n\r\n- Issue with json parsing in `ai.TextGenerator.get_ai_response`.\r\n\r\n### Changed\r\n\r\n- Default openai model to `gpt-4o-2024` in `ai.TextGenerator.get_ai_response`.\r\n- Updated Readme file with more examples.\r\n\r\n## [0.1.0] - 2024-06-25 initial release\r\n\r\n### Added\r\n\r\n- Initial release of the package.\r\n",
"bugtrack_url": null,
"license": null,
"summary": "A collection of utility functions and classes for Python projects.",
"version": "0.2.1",
"project_urls": {
"Homepage": "https://github.com/Fahadukr/b-utils-infra"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "20c35c4b7807a8586bbd298b8a1fae51741bc29c9bb2b4dd24ea3751dc7041ee",
"md5": "ffdc79850881855693f1140c3e5a4053",
"sha256": "bc3762eeee359d4762dc64102bb1751cc8cc1e20959163764bbcd1c6a20de082"
},
"downloads": -1,
"filename": "b_utils_infra-0.2.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ffdc79850881855693f1140c3e5a4053",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 14407,
"upload_time": "2024-06-25T23:56:11",
"upload_time_iso_8601": "2024-06-25T23:56:11.778016Z",
"url": "https://files.pythonhosted.org/packages/20/c3/5c4b7807a8586bbd298b8a1fae51741bc29c9bb2b4dd24ea3751dc7041ee/b_utils_infra-0.2.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "f399b2291f188615ed4281331d640be6c27d7ee4e1d7169e6b1d0529d2c33b21",
"md5": "cf112ad486c061bea22b91d9773c3bf8",
"sha256": "8f0668a37f0f9c54d9bea8a15885caa7b1144a82dab740b42379be437ca4176a"
},
"downloads": -1,
"filename": "b-utils-infra-0.2.1.tar.gz",
"has_sig": false,
"md5_digest": "cf112ad486c061bea22b91d9773c3bf8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 14270,
"upload_time": "2024-06-25T23:56:16",
"upload_time_iso_8601": "2024-06-25T23:56:16.738447Z",
"url": "https://files.pythonhosted.org/packages/f3/99/b2291f188615ed4281331d640be6c27d7ee4e1d7169e6b1d0529d2c33b21/b-utils-infra-0.2.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-06-25 23:56:16",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Fahadukr",
"github_project": "b-utils-infra",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "b-utils-infra"
}