Skip to main content

Like functools.singledispatch but for values

Project description

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

Project details


Download files

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

Source Distribution

datadispatch-1.0.0.tar.gz (1.8 kB view details)

Uploaded Source

Built Distribution

datadispatch-1.0.0-py3-none-any.whl (2.6 kB view details)

Uploaded Python 3

File details

Details for the file datadispatch-1.0.0.tar.gz.

File metadata

  • Download URL: datadispatch-1.0.0.tar.gz
  • Upload date:
  • Size: 1.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6

File hashes

Hashes for datadispatch-1.0.0.tar.gz
Algorithm Hash digest
SHA256 3c0456934e99f21137332deebbda05713dc07fcb142dfc01ef83d6b17aeaf08e
MD5 d879a864c989e0b624bda156761a67b6
BLAKE2b-256 afc92a1d98bf6a1e2ca41465dd77dc025d8a13b713c6d4378227c8938258c5d4

See more details on using hashes here.

File details

Details for the file datadispatch-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: datadispatch-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 2.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6

File hashes

Hashes for datadispatch-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 527ad534881d7f6144a8ff643c260a3d2ae0d50e8ee24ec4b0fdae72d6c7beab
MD5 14ae19926efbe23dc168cde811616583
BLAKE2b-256 806ad38daeb232e560803057c202ada249c5f53a7d532eae216660af42a23781

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page