Skip to main content

A simple function decorator to display its execution time on the console or in the logs.

Project description

executiontime

License: MIT

This module provides a simple function decorator to display its execution time on the console or in the logs.

Installation

Simply install the package with pip:

pip install executiontime

Usage

You simply need to decorate the function and specify a message template. If you do not provide a message, one will be created for you based on the names of the decorated function and its module.

from executiontime import printexecutiontime

@printexecutiontime("My function's execution took {0}")
def my_function():
    pass

if __name__ == '__main__':
    my_function()

By default, the message will be displayed on the console. But it is also possible to specify a log function, for example.

from logging import info, INFO, basicConfig
from executiontime import printexecutiontime

@printexecutiontime("My function's execution took {0}", display=info)
def my_function():
    pass

if __name__ == '__main__':
    basicConfig(level=INFO)
    my_function()

It is also easy to add a little bit of color:

from executiontime import printexecutiontime, LIGHTBLUE

@printexecutiontime("My function's execution took {0}", color=LIGHTBLUE)
def my_function():
    pass

if __name__ == '__main__':
    my_function()

Changelog

  • v0.4.4
    • No need of a time zone to calculate an elapsed time.
  • v0.4.3
    • Improve publish.sh script to get current PyPI version.
  • v0.4.2
    • Update dependencies
  • v0.4.1
    • The message is now optional and a default one is provided, based on the names of the decorated function and its module.
  • v0.4.0
    • Refresh the dependencies
    • Replace deprecated datetime.utcnow()

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

executiontime-0.4.4.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

executiontime-0.4.4-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file executiontime-0.4.4.tar.gz.

File metadata

  • Download URL: executiontime-0.4.4.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.12.3 Linux/5.15.167.4-microsoft-standard-WSL2

File hashes

Hashes for executiontime-0.4.4.tar.gz
Algorithm Hash digest
SHA256 40ac4bc3e84e03bb0991752c6ab1f15d7ff41a33e6dba277c0594121878b4631
MD5 5a4b90b33c548f58cc1b35e60cf2eac4
BLAKE2b-256 d4cce889bbac9412257a31c1bb976fb695eae88cb448d3f92115fe9c6c2e8fc7

See more details on using hashes here.

File details

Details for the file executiontime-0.4.4-py3-none-any.whl.

File metadata

  • Download URL: executiontime-0.4.4-py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.12.3 Linux/5.15.167.4-microsoft-standard-WSL2

File hashes

Hashes for executiontime-0.4.4-py3-none-any.whl
Algorithm Hash digest
SHA256 7b845e80d9c3b3249242336f1adb7cec26e8192528145619266a09e0462f5b70
MD5 20c56f5396c8990641fc0592bcd4a199
BLAKE2b-256 630c08876944ee61a250c0a5bf7552bcc254e688ade9601aa3b9169db5bcc668

See more details on using hashes here.

Supported by

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