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.5.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

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

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

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for executiontime-0.4.5.tar.gz
Algorithm Hash digest
SHA256 2f4fc9fcefca4716466911c56a45ddbba32b49cdf79f1003671824a417faf320
MD5 3a875fa501376f6fa3ac9a6f18870e14
BLAKE2b-256 f7790e21eb0e0b72fde98e1c91f08c2132a019d8b23d614c61dcf0fb207af9ce

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for executiontime-0.4.5-py3-none-any.whl
Algorithm Hash digest
SHA256 8d460c264b54e629357bd1ae115dbe345e332e79972465e882529406e6591d29
MD5 aac358fbea76ef440be70a47227ff026
BLAKE2b-256 298a1d4d492e63664ddac5f17934ca4d03c3237b4bfaa5a46a719db6b4a0a3c8

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