Skip to main content

A package with decorators to capture execution time and create log groups for functions.

Project description

CodeAlchemy

codealchemy is a Python package that provides decorators for capturing the execution time of functions and creating log groups for functions. This package can be used to enhance logging and performance monitoring in your Python projects.

Installation

You can install codealchemy using pip:

pip install codealchemy

Usage

Here is how you can use the decorators provided by codealchemy in your Python code:

  1. code execution time
from codealchemy import code_execution_time

@code_execution_time
def example_function():
    import time
    time.sleep(2)
    print("Function executed")

example_function()
  1. Log groups
from codealchemy import log_group
import logging

# Ensure the logger level is set to INFO
logging.getLogger(__name__).setLevel(logging.INFO)

@log_group("MainGroup")
def main_function():
    print("Inside main function")
    print("*"*20)
    logging.info("Inside main function")
    inner_function()

@log_group("InnerGroup")
def inner_function():
    print("Inside inner function")
    print("*"*20)
    logging.info("Inside inner function")
    innermost_function()

@log_group("InnermostGroup")
def innermost_function():
    print("Inside innermost function")
    print("*"*20)
    logging.info("Inside innermost function")
    print("Innermost function executed")

main_function()

image

Decorators

  • code_execution_time: This decorator logs the execution time of the decorated function.
  • log_group(group_name): This decorator logs entry and exit points of the decorated function, grouping logs under a specified group name.

Development

If you want to contribute to the development of codealchemy, you can set up a development environment by following these steps:

  1. Clone the repository:
    git clone https://github.com/girishcodealchemy/codealchemy.git
    
  2. Navigate to the project directory:
    cd codealchemy
    
  3. Install the package in editable mode with development dependencies:
    pip install -e .[dev]
    

Publishing to PyPI

This project uses GitHub Actions to automate the process of publishing the package to PyPI.

GitHub Action Workflow

The GitHub Action is defined in .github/workflows/publish-to-pypi.yml. It triggers on new releases and performs the following steps:

  1. Checkout the code.
  2. Set up Python.
  3. Install dependencies (setuptools, wheel, twine).
  4. Build the package.
  5. Publish the package to PyPI using credentials stored in GitHub Secrets.

Setting Up GitHub Secrets

To securely store your PyPI credentials, add the following secrets to your GitHub repository:

  1. PYPI_USERNAME: Your PyPI username.
  2. PYPI_PASSWORD: Your PyPI password.

Creating a New Release

To trigger the GitHub Action and publish the package to PyPI:

  1. Navigate to your GitHub repository.
  2. Go to the Releases tab.
  3. Click Draft a new release.
  4. Fill in the release details (tag version, release title, description).
  5. Click Publish release.

The GitHub Action will automatically run and upload the package to PyPI.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

codealchemy-1.1.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

codealchemy-1.1-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file codealchemy-1.1.tar.gz.

File metadata

  • Download URL: codealchemy-1.1.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.15

File hashes

Hashes for codealchemy-1.1.tar.gz
Algorithm Hash digest
SHA256 d9f4684798c41907cf2d36d68f46222e3074e7f8af7e8ae1ec93f37866d858b3
MD5 b5a858b634c23ee07700d9706f44db1e
BLAKE2b-256 600e0871b23eef6103903d088dad4b67f7d2e9c7c50df8fdd066747b9577a7a9

See more details on using hashes here.

File details

Details for the file codealchemy-1.1-py3-none-any.whl.

File metadata

  • Download URL: codealchemy-1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.15

File hashes

Hashes for codealchemy-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ad37522f58cf5d1d59b77d40d7321af67ab407f357ae70a6348384077d1efaad
MD5 a996d28b8928053f9e0a6c0f3c6eb533
BLAKE2b-256 157e6fd697f26b323a7e461a35cbcc3572fd7d9fdefef54b83eec96afab6bcc6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page