Giter Club home page Giter Club logo

penguin's Introduction

Peter the penguin, penguin-py's mascot.

Peter the penguin logo credits go to catalyststuff on freepik.com

๐Ÿง penguin-py ๐Ÿง

Penguin is a lightweight, customizable stopwatch โฑ decorator that helps you determine how long it takes for your functions to run. It supports both synchronous (@penguin) and asynchronous (@penguin_async) functions.

Getting Started ๐Ÿš€

Table of contents:

The source code of this package lives here: https://github.com/espitiaandres/penguin

To install penguin-py with the command line, run this command:

pip install penguin-py.

To install penguin-py using a requirements.txt file, add this line to your requirements.txt file.

penguin-py==0.3.12

For synchronous functions, use the @penguin() decorator.

โœ… To run with default kwargs:

from penguin_py import penguin


@penguin()
def foo(test1, test2=None):
    # Note: this function can be anything!
    for i in range(10000000):
        pass
    return "test", True


test = foo("", test2="")

This will output the following to your logger:

Sample penguin output

โœ… To run with user specified kwargs:

@penguin(
    verbose=True,
    show_args=True,
    show_return=True,
    foreground='cyan',
    background='yellow',
)
def foo(test1, test2=None):
    for i in range(10000000):
        pass
    return "test", True


test = foo("", test2="")

This will output the following to your logger:

Sample penguin output kwargs

Note: For a more detailed list of all kwargs and their defaults, visit this section: List of kwargs

โŒ Since penguin is a decorator that takes in kwargs, do not call it without the brackets ().

from penguin_py import penguin


@penguin
def foo(test1, test2=None):
    # Note: this function can be anything!
    for i in range(10000000):
        pass
    return "test", True


test = foo("", test2=":")

If you do this, you'll get a TypeError relating to arguments.

For asynchronous functions, use the @penguin_async() decorator.

โœ… To run with default kwargs:

from penguin_py import penguin


@penguin_async()
def foo(test1, test2=None):
    # Note: this function can be anything!
    for i in range(10000000):
        pass
    return "test", True


test = foo("", test2="")

This will output the following to your logger:

Sample penguin output

โœ… To run with user specified kwargs:

@penguin(
    verbose=True,
    show_args=True,
    show_return=True,
    foreground='cyan',
    background='yellow',
)
def foo(test1, test2=None):
    for i in range(10000000):
        pass
    return "test", True


test = foo("", test2="")

This will output the following to your logger:

Sample penguin output kwargs

  • verbose: When True, it shows all logs that are described by the other kwargs. When False, each kwarg would determine if that specific log is shown - default: False
  • show_args: When True, it shows the function's signature, with the *args and **kwargs being passed in.
    • default: False
  • show_return: When True, it shows the function's return value(s).
    • default: False
  • foreground: When chosen from this list, ["red", "yellow", "green", "blue", "magenta", "cyan", "grey"], it colour the logger output text the chosen colour.
    • default: "grey"
  • background: When chosen from this list, ["red", "yellow", "green", "blue", "magenta", "cyan", "grey", "black", "white"], it colour the logger output background the chosen colour.
    • default: "black"

Documentation of penguin-py can be found here: https://github.com/espitiaandres/penguin/blob/master/README.md

If you find any bugs or have any suggestions to penguin-py, submit them in the issues tab in the Github repo. This can be found here: https://github.com/espitiaandres/penguin/issues

Distributed under the terms of the MIT license, penguin-py is free and open source software.

penguin's People

Contributors

espitiaandres avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.