Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

datadispatch

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

datadispatch

Like functools.singledispatch but for values

  • 1.0.0
  • PyPI
  • Socket score

Maintainers
1

datadispatch

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))


@handle.register('ping')
def _(message):
  return 'you sent ping'


@handle.register('pong')
def _(message):
  return 'you sent pong'


print(handle(
  {'type': 'ping', 'payload': 'hello'}
))

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc