Skip to main content

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()

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.6.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.6-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: executiontime-0.4.6.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.6.tar.gz
Algorithm Hash digest
SHA256 3423217b74891eb8aa2cd18292c1ad92c489407c837e1b9a7bda4623ecf64e60
MD5 94ba8893ee1bf937a7f7eccae08e9388
BLAKE2b-256 d4bb9b685f0aa7b3f75554e6f4b03958273cb5c0f8f813649bc790606bcd0db4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: executiontime-0.4.6-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.6-py3-none-any.whl
Algorithm Hash digest
SHA256 2b5cdc19145759814117ea654a821548de450b11058d1649e7783a279af71f2b
MD5 1fe3777162af8c99b4554de64225924d
BLAKE2b-256 8d70a481abc604ffcc6bc710ac8890826202630e512d8d688c1bd4ba90666d15

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.4.6 This release

2 files

0.4.5

2 files

0.4.4

2 files

0.4.3

2 files

0.4.2

2 files

0.4.1

2 files

0.4.0

2 files

0.3.6

2 files

0.3.5

2 files

0.3.4

2 files

0.3.3

2 files

0.3.2

2 files

0.3.1

2 files

0.3.0

2 files

0.2.1

2 files

0.2.0

2 files

0.1.2

2 files

0.1.1

2 files

0.1

1 file

Supported by

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