cutility


Namecutility JSON
Version 1.0.1 PyPI version JSON
download
home_pagehttps://github.com/sagarshq/cutility
SummaryCommon Utility functions for development
upload_time2024-09-07 10:10:50
maintainerNone
docs_urlNone
authorSagar Sarkale
requires_python>=3.7
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # cutility

Common utilities for faster development

## Table of Contents

- [cutility](#cutility)
  - [Table of Contents](#table-of-contents)
  - [Installation](#installation)
  - [Usage](#usage)
    - [Utils](#utils)
      - [Measure Execution Time](#measure-execution-time)
      - [Check Path Existence](#check-path-existence)
      - [Load Environment Variables](#load-environment-variables)
    - [Loggers](#loggers)
      - [Simple Logger](#simple-logger)
    - [IO](#io)
      - [Read and Write Files](#read-and-write-files)
    - [Dir Handler](#dir-handler)
    - [Cleaners](#cleaners)
      - [Generic Cleaner](#generic-cleaner)
      - [Simple Text Cleaner](#simple-text-cleaner)
      - [PII Text Cleaner](#pii-text-cleaner)
    - [Path Manager](#path-manager)
  - [Project Structure](#project-structure)
  - [Contributing](#contributing)
  - [License](#license)

## Installation

You can install `cutility` using pip:

```bash
pip install --upgrade cutility
```

## Usage

### Utils

#### Measure Execution Time

```python
from cutility.utils import get_exec_time

@get_exec_time
def foo():
    import time
    time.sleep(1)

foo()
# Output: Time taken to execute 'foo': 0:00:01.005044
```

#### Check Path Existence

```python
from cutility.utils import check_path_exist

exists = check_path_exist("./data/temp.txt")
print(exists)  # Output: False
```

#### Load Environment Variables

```python
from cutility.utils import load_env

ENV = load_env("./.env")
print(ENV)
print(os.getenv("DATA_ROOT"))
print(os.getenv("PROJECT_ROOT"))
print(os.getenv("CONFIG_PATH"))
```

### Loggers

#### Simple Logger

```python
from cutility.loggers import get_simple_logger

log = get_simple_logger()
log.i("Hello world of loggers")
# Output: [2023-12-17 02:21:03,847] - [INFO] : Hello world of loggers
```

### IO

#### Read and Write Files

```python
from cutility.io import readers, writers

# Read and write text files
text_content = readers.read_text("./data/example_r.txt")
writers.write_text(text_content, "./data/example_w.txt")

# Read and write JSON files
json_data = readers.read_json("./data/example_r.json")
writers.write_json(json_data, "./data/example_w.json")

# Read and write YAML files
yaml_data = readers.read_yaml("./data/example_r.yaml")
writers.write_yaml(yaml_data, "./data/example_w.yaml")
```

### Dir Handler

```python
from cutility import get_dir_handler

dirh = get_dir_handler(project_root="./", data_root="./data", verbose=True)
print(dirh.get_data_root())
print(dirh.get_project_root())
```

### Cleaners

#### Generic Cleaner

```python
from cutility.cleaners import GenericSimpleTextCleaner

gtc = GenericSimpleTextCleaner()
sample_text = """Check out this link: https://example.com. 😎 #Python @user1, sample@gmail.com 123-456-7908"""

cleaning_steps = [
    (gtc.replace_contacts, {"repl": " {{PHONE}} "}),
    (gtc.replace_emails, {"repl": " {{EMAIL}} "}),
    (gtc.clean_emojis, {}),
    (gtc.clean_hashtags, {}),
    (gtc.clean_web_links, {}),
]

cleaned_text = gtc.apply_text_cleaning_functions(sample_text, cleaning_steps)
print(cleaned_text)
```

#### Simple Text Cleaner

```python
from cutility.cleaners import SimpleTextCleaner

cleaned_text = SimpleTextCleaner.clean_emojis("🌟 Sed euismod justo t semper justo. 😊")
print(cleaned_text)
```

#### PII Text Cleaner

```python
from cutility.cleaners import PiiTextCleaner

text = "My contact number is +1(123) 456 7890 and my email is email@company.com"
cleaned_text = PiiTextCleaner.replace_emails(PiiTextCleaner.replace_contacts(text))
print(cleaned_text)
```

### Path Manager

```python
from cutility import PathManager, create_path_manager

pm = create_path_manager(project_root="./", data_root="./data", verbose=True)
print(pm.data_root)
print(pm.project_root)

# Load YAML configuration
config = pm.load_yaml_config("my_config")
print(config)

# Create directory structure
pm.create_directory_structure("./output", ["logs", "data", "results"])
```

## Project Structure

```
./src
└── cutility
    ├── __init__.py
    ├── _version.py
    ├── cleaners
    │   ├── __init__.py
    │   ├── clean.py
    │   ├── pii_cleaner.py
    │   └── text_cleaner.py
    ├── dir_handler.py
    ├── io
    │   ├── __init__.py
    │   ├── readers
    │   └── writers
    ├── loggers
    │   ├── __init__.py
    │   └── _simple_logger.py
    └── utils
        ├── __init__.py
        ├── env_loader.py
        ├── exec_time.py
        └── path.py
```

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## License

This project is licensed under the [Apache 2.0 License](LICENSE).

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/sagarshq/cutility",
    "name": "cutility",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": null,
    "author": "Sagar Sarkale",
    "author_email": "sagarsarkale.work@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/ee/88/83f333552077e162301cd2857f48b6827f9cfaa86c189caead7b7dba49d1/cutility-1.0.1.tar.gz",
    "platform": null,
    "description": "# cutility\n\nCommon utilities for faster development\n\n## Table of Contents\n\n- [cutility](#cutility)\n  - [Table of Contents](#table-of-contents)\n  - [Installation](#installation)\n  - [Usage](#usage)\n    - [Utils](#utils)\n      - [Measure Execution Time](#measure-execution-time)\n      - [Check Path Existence](#check-path-existence)\n      - [Load Environment Variables](#load-environment-variables)\n    - [Loggers](#loggers)\n      - [Simple Logger](#simple-logger)\n    - [IO](#io)\n      - [Read and Write Files](#read-and-write-files)\n    - [Dir Handler](#dir-handler)\n    - [Cleaners](#cleaners)\n      - [Generic Cleaner](#generic-cleaner)\n      - [Simple Text Cleaner](#simple-text-cleaner)\n      - [PII Text Cleaner](#pii-text-cleaner)\n    - [Path Manager](#path-manager)\n  - [Project Structure](#project-structure)\n  - [Contributing](#contributing)\n  - [License](#license)\n\n## Installation\n\nYou can install `cutility` using pip:\n\n```bash\npip install --upgrade cutility\n```\n\n## Usage\n\n### Utils\n\n#### Measure Execution Time\n\n```python\nfrom cutility.utils import get_exec_time\n\n@get_exec_time\ndef foo():\n    import time\n    time.sleep(1)\n\nfoo()\n# Output: Time taken to execute 'foo': 0:00:01.005044\n```\n\n#### Check Path Existence\n\n```python\nfrom cutility.utils import check_path_exist\n\nexists = check_path_exist(\"./data/temp.txt\")\nprint(exists)  # Output: False\n```\n\n#### Load Environment Variables\n\n```python\nfrom cutility.utils import load_env\n\nENV = load_env(\"./.env\")\nprint(ENV)\nprint(os.getenv(\"DATA_ROOT\"))\nprint(os.getenv(\"PROJECT_ROOT\"))\nprint(os.getenv(\"CONFIG_PATH\"))\n```\n\n### Loggers\n\n#### Simple Logger\n\n```python\nfrom cutility.loggers import get_simple_logger\n\nlog = get_simple_logger()\nlog.i(\"Hello world of loggers\")\n# Output: [2023-12-17 02:21:03,847] - [INFO] : Hello world of loggers\n```\n\n### IO\n\n#### Read and Write Files\n\n```python\nfrom cutility.io import readers, writers\n\n# Read and write text files\ntext_content = readers.read_text(\"./data/example_r.txt\")\nwriters.write_text(text_content, \"./data/example_w.txt\")\n\n# Read and write JSON files\njson_data = readers.read_json(\"./data/example_r.json\")\nwriters.write_json(json_data, \"./data/example_w.json\")\n\n# Read and write YAML files\nyaml_data = readers.read_yaml(\"./data/example_r.yaml\")\nwriters.write_yaml(yaml_data, \"./data/example_w.yaml\")\n```\n\n### Dir Handler\n\n```python\nfrom cutility import get_dir_handler\n\ndirh = get_dir_handler(project_root=\"./\", data_root=\"./data\", verbose=True)\nprint(dirh.get_data_root())\nprint(dirh.get_project_root())\n```\n\n### Cleaners\n\n#### Generic Cleaner\n\n```python\nfrom cutility.cleaners import GenericSimpleTextCleaner\n\ngtc = GenericSimpleTextCleaner()\nsample_text = \"\"\"Check out this link: https://example.com. \ud83d\ude0e #Python @user1, sample@gmail.com 123-456-7908\"\"\"\n\ncleaning_steps = [\n    (gtc.replace_contacts, {\"repl\": \" {{PHONE}} \"}),\n    (gtc.replace_emails, {\"repl\": \" {{EMAIL}} \"}),\n    (gtc.clean_emojis, {}),\n    (gtc.clean_hashtags, {}),\n    (gtc.clean_web_links, {}),\n]\n\ncleaned_text = gtc.apply_text_cleaning_functions(sample_text, cleaning_steps)\nprint(cleaned_text)\n```\n\n#### Simple Text Cleaner\n\n```python\nfrom cutility.cleaners import SimpleTextCleaner\n\ncleaned_text = SimpleTextCleaner.clean_emojis(\"\ud83c\udf1f Sed euismod justo t semper justo. \ud83d\ude0a\")\nprint(cleaned_text)\n```\n\n#### PII Text Cleaner\n\n```python\nfrom cutility.cleaners import PiiTextCleaner\n\ntext = \"My contact number is +1(123) 456 7890 and my email is email@company.com\"\ncleaned_text = PiiTextCleaner.replace_emails(PiiTextCleaner.replace_contacts(text))\nprint(cleaned_text)\n```\n\n### Path Manager\n\n```python\nfrom cutility import PathManager, create_path_manager\n\npm = create_path_manager(project_root=\"./\", data_root=\"./data\", verbose=True)\nprint(pm.data_root)\nprint(pm.project_root)\n\n# Load YAML configuration\nconfig = pm.load_yaml_config(\"my_config\")\nprint(config)\n\n# Create directory structure\npm.create_directory_structure(\"./output\", [\"logs\", \"data\", \"results\"])\n```\n\n## Project Structure\n\n```\n./src\n\u2514\u2500\u2500 cutility\n    \u251c\u2500\u2500 __init__.py\n    \u251c\u2500\u2500 _version.py\n    \u251c\u2500\u2500 cleaners\n    \u2502   \u251c\u2500\u2500 __init__.py\n    \u2502   \u251c\u2500\u2500 clean.py\n    \u2502   \u251c\u2500\u2500 pii_cleaner.py\n    \u2502   \u2514\u2500\u2500 text_cleaner.py\n    \u251c\u2500\u2500 dir_handler.py\n    \u251c\u2500\u2500 io\n    \u2502   \u251c\u2500\u2500 __init__.py\n    \u2502   \u251c\u2500\u2500 readers\n    \u2502   \u2514\u2500\u2500 writers\n    \u251c\u2500\u2500 loggers\n    \u2502   \u251c\u2500\u2500 __init__.py\n    \u2502   \u2514\u2500\u2500 _simple_logger.py\n    \u2514\u2500\u2500 utils\n        \u251c\u2500\u2500 __init__.py\n        \u251c\u2500\u2500 env_loader.py\n        \u251c\u2500\u2500 exec_time.py\n        \u2514\u2500\u2500 path.py\n```\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## License\n\nThis project is licensed under the [Apache 2.0 License](LICENSE).\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Common Utility functions for development",
    "version": "1.0.1",
    "project_urls": {
        "Homepage": "https://github.com/sagarshq/cutility"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "328efec44829b0f7891b7308053d0f9090b6f3895d80bd9e3f4ddd6d9df750c8",
                "md5": "d99c23ae2d9f6ccdcab0f39787dc81d3",
                "sha256": "3cda232f02ef3f3f3378ab808ab48d139b0a5185372cc74eb12f02a736bd44da"
            },
            "downloads": -1,
            "filename": "cutility-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d99c23ae2d9f6ccdcab0f39787dc81d3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 18524,
            "upload_time": "2024-09-07T10:10:49",
            "upload_time_iso_8601": "2024-09-07T10:10:49.688037Z",
            "url": "https://files.pythonhosted.org/packages/32/8e/fec44829b0f7891b7308053d0f9090b6f3895d80bd9e3f4ddd6d9df750c8/cutility-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ee8883f333552077e162301cd2857f48b6827f9cfaa86c189caead7b7dba49d1",
                "md5": "9bac2a64d770b264b852872e1a0be915",
                "sha256": "1e2112a538d2fe512dfb7e4c64cacfbb0f944f96557d84a583a8ec4fed23cde9"
            },
            "downloads": -1,
            "filename": "cutility-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "9bac2a64d770b264b852872e1a0be915",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 19399,
            "upload_time": "2024-09-07T10:10:50",
            "upload_time_iso_8601": "2024-09-07T10:10:50.685547Z",
            "url": "https://files.pythonhosted.org/packages/ee/88/83f333552077e162301cd2857f48b6827f9cfaa86c189caead7b7dba49d1/cutility-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-07 10:10:50",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "sagarshq",
    "github_project": "cutility",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "cutility"
}
        
Elapsed time: 0.35971s