Skip to main content

Like functools.singledispatch but for values

Project description


datadispatch provides a dispatch mechanism (a.k.a. polymorphism) like functools.singledispatch, but it operates on data instead of types. This is useful if you are creating simple data-centric applications where you want polymorphism à la carte without resorting to types or classes.

datadispatch is available through pip: pip install datadispatch

Usage example

from datadispatch import datadispatch

@datadispatch(lambda args, _: args[0].get('type'))
def handle(message):
  raise ValueError('cannot handle message: {}'.format(message))

def _(message):
  return 'you sent ping'

def _(message):
  return 'you sent pong'

  {'type': 'ping', 'payload': 'hello'}

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
datadispatch-1.0.0-py3-none-any.whl (2.6 kB) Copy SHA256 hash SHA256 Wheel py3
datadispatch-1.0.0.tar.gz (1.8 kB) Copy SHA256 hash SHA256 Source None

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