Skip to main content

A convenient way to create parametrized decorators.

Project description

Paramdec is a convenient way to create parametrized decorators.


Create your parametrized decorator:

>>> from paramdec import paramdec
>>> @paramdec
... def my_dec(func, foo=42, bar=None):
...     def wrapper(*func_args, **func_kwargs):
...         # Process foo and bar
...         return func(*func_args, **func_kwargs)
...     return wrapper

Use it with parameters:

>>> @my_dec(bar="bar")
>>> def func(): pass

Or without parameters:

>>> @my_dec()
>>> def func(): pass

Or even without parentheses:

>>> @my_dec
>>> def func(): pass

Also, consider using functools.wraps for your decorators.


  • No positional args supported.

The rationale behind this is the fact that I have not found any pythonic way to make a decorator differentiate between a function to be decorated and a callback. So if you pass a single callable positional argument to a parametrized decorator, it will mistakenly decide that it was called not as a factory but as a casual decorator.

Project details

Release history Release notifications

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
paramdec-2.1.0-py2.py3-none-any.whl (4.9 kB) Copy SHA256 hash SHA256 Wheel py2.py3

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page