presets

Presets provides an object interface that can override common default parameter settings for all functions within a target module or package.

It’s simple to use. Simply construct a Preset object with the target module as an argument, then set the default parameters via a dict-like interface. After that, your new object will act just as the target module, but it replaces the default arguments of any functions with values that you set.

Example

>>> import librosa as _librosa
>>> from presets import Preset
>>> librosa = Preset(_librosa)
>>> librosa['sr'] = 44100
>>> librosa['n_fft'] = 4096
>>> librosa['hop_length'] = 1024
>>> y, sr = librosa.load(librosa.util.example_audio_file())
>>> sr
44100
>>> stft = librosa.stft(y)

API Reference

Object reference

class presets.Preset(module, dispatch=None, defaults=None)[source]

The Preset class overrides the default parameters of functions within a module.

If the given module contains submodules, these are also encapsulated by Preset objects that share the same default parameter dictionary.

Submodules are detected by examining common prefixes of the module source paths.

Attributes:
module : Python module

The module to encapsulate

dispatch : None or dictionary

A dictionary mapping modules to existing Preset objects. This should be left as None for most situations.

defaults : None or dictionary

An existing dictionary object used to collect default parameters. Note: this will be passed by reference.

Methods

keys() Returns a list of currently set parameter defaults
update(D) Updates the default parameter set by a dictionary D
keys()[source]

Returns a list of currently set parameter defaults

update(D)[source]

Updates the default parameter set by a dictionary D

Changes

v0.1.3

  • Fixed a bug in handling built-in modules
  • Added transparency of wrapped function docstrings and call signatures

v0.1.2

  • Fixed a bug in overriding anonymous keyword arguments
  • Updated inspect usage for python 3.5

v0.1.1

  • Fixed an error in PyPI-based installation

v0.1.0

  • Initial public release