A collection of helper functions and decorators that I occasionally use to get my life in order.
Project description
A collection of helper functions and decorators that I occasionally use to get my life in order.
Installation
pip install mj_helpers
profileit
Usage:
from profileit import profileit @profileit def foo(): return do_stuff()
In a Python shell:
>>> from .foo import foo >>> foo() >>> form pstats import Stats >>> stats = Stats('/tmp/foo.profile') >>> stats.sort_stats('cumulative').print_stats(50) Fri Nov 27 08:34:14 2015 /tmp/foo.profile 2 function calls in 0.000 seconds Ordered by: cumulative time ncalls tottime percall cumtime percall filename:lineno(function) 1 0.000 0.000 0.000 0.000 <ipython-input-8-8f35865ca12d>:1(foo) 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
If installed via pip or python setup.py:
mj_stats /tmp/foo.profile /tmp/bar.profile --sorting=cumulative --limit=50
log_it
In Python:
from log_decorator import log_it class SomeClass(object): @staticmethod @log_it() def foo_static_method(bar, spam='spam', eggs=None, *args, **kwargs): pass @classmethod @log_it() def foo_class_method(cls, bar, spam='spam', eggs=None, *args, **kwargs): pass @log_it(): def bar(self, foo, spam='spam', eggs=None, *args, **kwargs): pass
Console:
>>> SomeClass.foo_static_method('bar') DEBUG:__main__:Entering foo(bar='bar', spam='spam', eggs=None) DEBUG:__main__:Exit foo -- Time in function: 0.00s >>> SomeClass.foo_class_method('bar') DEBUG:__main__:Entering foo(cls='cls', bar='bar', spam='spam', eggs=None) DEBUG:__main__:Exit foo -- Time in function: 0.00s >>> SomeClass().bar('foo', *['spam_arg', 'eggs_arg', 'another_arg'], a_kwarg='a_kwarg') DEBUG:__main__:Entering bar(self='self', foo='foo', spam='spam_arg', eggs='eggs_arg', *('another_arg',), **{'a_kwarg': 'a_kwarg'}) DEBUG:__main__:Exit bar -- Time in function: 0.00s
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
mj_helpers-0.0.0.tar.gz
(5.2 kB
view hashes)
Built Distribution
Close
Hashes for mj_helpers-0.0.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f46a9bda8920e9d9f1bd28ee1dfab889299982b7dc341680ae0ece482ad6534 |
|
MD5 | 4ff58f0d40882a84aec833d711227982 |
|
BLAKE2b-256 | 2acb2cb169287c6672e09a8d161691970d5ee6b6b799ec7df4f6f57f529145ef |