Skip to main content

Plum: Multiple Dispatch in Python

DOI CI Coverage Status Latest Docs Code style: black

Everybody likes multiple dispatch, just like everybody likes plums.

The design philosophy of Plum is to provide an implementation of multiple dispatch that is Pythonic, yet close to how Julia does it. See here for a comparison between Plum, multipledispatch, and multimethod.

Note: Plum 2 is now powered by Beartype! If you notice any issues with the new release, please open an issue.

Installation

Plum requires Python 3.10 or higher.

pip install plum-dispatch

Documentation

See here.

What's This?

Plum brings your type annotations to life:

from numbers import Number

from plum import dispatch


@dispatch
def f(x: str):
    return "This is a string!"


@dispatch
def f(x: int):
    return "This is an integer!"


@dispatch
def f(x: Number):
    return "This is a number, but I don't know which type."
>>> f("1")
'This is a string!'

>>> f(1)
'This is an integer!'

>>> f(1.0)
'This is a number, but I don't know which type.'

>>> f(object())
NotFoundLookupError: `f(<object object at 0x7fd3b01cd330>)` could not be resolved.

Closest candidates are the following:
    f(x: str)
        <function f at 0x7fd400644ee0> @ /<ipython-input-2-c9f6cdbea9f3>:6
    f(x: int)
        <function f at 0x7fd3a0235ca0> @ /<ipython-input-2-c9f6cdbea9f3>:11
    f(x: numbers.Number)
        <function f at 0x7fd3a0235d30> @ /<ipython-input-2-c9f6cdbea9f3>:16

[!IMPORTANT] Dispatch, as implemented by Plum, is based on the positional arguments to a function. Keyword arguments are not used in the decision making for which method to call. In particular, this means that positional arguments without a default value must always be given as positional arguments!

Example:

from plum import dispatch

@dispatch
def f(x: int):
   return x

>>> f(1)        # OK
1

>> try: f(x=1)  # Not OK
... except Exception as e: print(f"{type(e).__name__}: {e}")
NotFoundLookupError: `f()` could not be resolved...

This also works for multiple arguments, enabling some neat design patterns:

from numbers import Number, Real, Rational

from plum import dispatch


@dispatch
def multiply(x: Number, y: Number):
    return "Performing fallback implementation of multiplication..."


@dispatch
def multiply(x: Real, y: Real):
    return "Performing specialised implementation for reals..."


@dispatch
def multiply(x: Rational, y: Rational):
    return "Performing specialised implementation for rationals..."
>>> multiply(1, 1)
'Performing specialised implementation for rationals...'

>>> multiply(1.0, 1.0)
'Performing specialised implementation for reals...'

>>> multiply(1j, 1j)
'Performing fallback implementation of multiplication...'

>>> multiply(1, 1.0)  # For mixed types, it automatically chooses the right optimisation!
'Performing specialised implementation for reals...'

Projects Using Plum

The following projects are using Plum to do multiple dispatch! Would you like to add your project here? Please feel free to open a PR to add it to the list!

  • Coordinax implements coordinates in JAX.
  • fasttransform provides the main building block of data pipelines in fastai.
  • GPAR is an implementation of the Gaussian Process Autoregressive Model.
  • GPCM is an implementation of various Gaussian Process Convolution Models.
  • Galax does galactic and gravitational dynamics.
  • Geometric Kernels implements kernels on non-Euclidean spaces, such as Riemannian manifolds, graphs, and meshes.
  • LAB uses Plum to provide backend-agnostic linear algebra (something that works with PyTorch/TF/JAX/etc).
  • MLKernels implements standard kernels.
  • MMEval is a unified evaluation library for multiple machine learning libraries.
  • Matrix extends LAB and implements structured matrix types, such as low-rank matrices and Kronecker products.
  • NetKet, a library for machine learning with JAX/Flax targeted at quantum physics, uses Plum extensively to pick the right, efficient implementation for a large combination of objects that interact.
  • NeuralProcesses is a framework for composing Neural Processes.
  • OILMM is an implementation of the Orthogonal Linear Mixing Model.
  • PySAGES is a suite for advanced general ensemble simulations.
  • Quax implements multiple dispatch over abstract array types in JAX.
  • Unxt implements unitful quantities in JAX.
  • Varz uses Plum to provide backend-agnostic tools for non-linear optimisation.

See the docs for a comparison of Plum to other implementations of multiple dispatch.

Download files

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

Source Distribution

plum_dispatch-2.10.0.tar.gz (250.2 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

plum_dispatch-2.10.0-py3-none-any.whl (49.0 kB view details)

Uploaded Python 3

plum_dispatch-2.10.0-cp313-cp313-win_amd64.whl (246.0 kB view details)

Uploaded CPython 3.13Windows x86-64

plum_dispatch-2.10.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (334.0 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

plum_dispatch-2.10.0-cp313-cp313-macosx_10_13_x86_64.whl (284.5 kB view details)

Uploaded CPython 3.13macOS 10.13+ x86-64

plum_dispatch-2.10.0-cp312-cp312-win_amd64.whl (245.1 kB view details)

Uploaded CPython 3.12Windows x86-64

plum_dispatch-2.10.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (335.5 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

plum_dispatch-2.10.0-cp312-cp312-macosx_10_13_x86_64.whl (286.1 kB view details)

Uploaded CPython 3.12macOS 10.13+ x86-64

plum_dispatch-2.10.0-cp311-cp311-win_amd64.whl (242.6 kB view details)

Uploaded CPython 3.11Windows x86-64

plum_dispatch-2.10.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (329.3 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

plum_dispatch-2.10.0-cp311-cp311-macosx_10_9_x86_64.whl (279.9 kB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

plum_dispatch-2.10.0-cp310-cp310-win_amd64.whl (242.7 kB view details)

Uploaded CPython 3.10Windows x86-64

plum_dispatch-2.10.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (336.6 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

plum_dispatch-2.10.0-cp310-cp310-macosx_10_9_x86_64.whl (284.6 kB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

File details

Details for the file plum_dispatch-2.10.0.tar.gz.

File metadata

  • Download URL: plum_dispatch-2.10.0.tar.gz
  • Upload date:
  • Size: 250.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for plum_dispatch-2.10.0.tar.gz
Algorithm Hash digest
SHA256 fd5caa4e0edb50a0d7974599335f2a37c4b9c083891e54d768aad8256059acd3
MD5 605084bce7c25f0a1a6be2b0327e1b85
BLAKE2b-256 f6e1b78b7423b6760d6663067730b495c51db2432391628496be1446d810d960

See more details on using hashes here.

Provenance

The following attestation bundles were made for plum_dispatch-2.10.0.tar.gz:

Publisher: publish.yml on beartype/plum

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file plum_dispatch-2.10.0-py3-none-any.whl.

File metadata

  • Download URL: plum_dispatch-2.10.0-py3-none-any.whl
  • Upload date:
  • Size: 49.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for plum_dispatch-2.10.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0a9d0d7d40e37f69c4995fb52458b9b904d75562cb3a937d512ed7b8e91fadfe
MD5 670b93298f7078de5823796ef1c642fc
BLAKE2b-256 ee050f30609bdac313902ae604b4d1ef7b22b31e7e53bab5e4679ab951c1250e

See more details on using hashes here.

Provenance

The following attestation bundles were made for plum_dispatch-2.10.0-py3-none-any.whl:

Publisher: publish.yml on beartype/plum

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file plum_dispatch-2.10.0-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for plum_dispatch-2.10.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 e4f0025a9ed36062688fbeec693cadd572c060ce051c89f65815b53ca4b59186
MD5 dafd89d4c1af587bd77a26e7fb0659ed
BLAKE2b-256 14bbe384aca55ffcfd389679b2c8684fc0f333bb59c3d5a3eae99f4e596db979

See more details on using hashes here.

Provenance

The following attestation bundles were made for plum_dispatch-2.10.0-cp313-cp313-win_amd64.whl:

Publisher: publish.yml on beartype/plum

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file plum_dispatch-2.10.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for plum_dispatch-2.10.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 346b77d680d52c2eedd375ed1eb49edaa07931e98ad89b83bc4c16363c98a661
MD5 f84a92b6094e3947c9446411a6e925f5
BLAKE2b-256 83eeacb2c8e7a8c894026666d5bec3cb776ee8a7315f1db6e3aaa0f95b60a75b

See more details on using hashes here.

Provenance

The following attestation bundles were made for plum_dispatch-2.10.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl:

Publisher: publish.yml on beartype/plum

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file plum_dispatch-2.10.0-cp313-cp313-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for plum_dispatch-2.10.0-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 d56c5cbd2156177f3d04a33b9838693b14ad8ff48c9c0e96d2b0d2ae18b6d995
MD5 aa55f5236aff4615c7620e81c2cb12a2
BLAKE2b-256 16dfe5f3f296aef568aa8c627d7b66097fe3d41109bacd7a38029f3d8683c052

See more details on using hashes here.

Provenance

The following attestation bundles were made for plum_dispatch-2.10.0-cp313-cp313-macosx_10_13_x86_64.whl:

Publisher: publish.yml on beartype/plum

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file plum_dispatch-2.10.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for plum_dispatch-2.10.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 ec275cd92a754ced95748ef05238af1bad3adbf693e47dd71e439e8bec5a6717
MD5 6798c529662b65639e4619c0efc973bd
BLAKE2b-256 4dd251d61ba5a98212a764a1eafad7b103f4e5c062928914dbdc9b164a744eeb

See more details on using hashes here.

Provenance

The following attestation bundles were made for plum_dispatch-2.10.0-cp312-cp312-win_amd64.whl:

Publisher: publish.yml on beartype/plum

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file plum_dispatch-2.10.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for plum_dispatch-2.10.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 19d5451fa5e1ea03d2f1c7c0a68a7c13f913ac766610bd4a29bbb6d5792275f0
MD5 c0ee297c94bceda0c0f07ebb0da46d25
BLAKE2b-256 a76e2e96ad53bde141f81f29fb71afe3828ada3dc66b66fbb2427fff6cfc9ccd

See more details on using hashes here.

Provenance

The following attestation bundles were made for plum_dispatch-2.10.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl:

Publisher: publish.yml on beartype/plum

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file plum_dispatch-2.10.0-cp312-cp312-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for plum_dispatch-2.10.0-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 42aa57a828bda338da137c69c3e6b52c2efd8a4bbca601ecbdbf89c6e0e64e0d
MD5 d913d7386310164e7b20b14263e91cb5
BLAKE2b-256 fa7ef012112cc9d2559632c87dfccfc521e67d607d6e9bde5eeb974ff09d1fc6

See more details on using hashes here.

Provenance

The following attestation bundles were made for plum_dispatch-2.10.0-cp312-cp312-macosx_10_13_x86_64.whl:

Publisher: publish.yml on beartype/plum

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file plum_dispatch-2.10.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for plum_dispatch-2.10.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 56c80a8395d09e69fae9ef9cd1d4fb257f284b8da7fe09e20477d5e2080075cd
MD5 dac51bdc40b1a342738900656dce2627
BLAKE2b-256 63b27c53a02ca978181173d0edcbc44b913a42938815872d3008178bc4afbea8

See more details on using hashes here.

Provenance

The following attestation bundles were made for plum_dispatch-2.10.0-cp311-cp311-win_amd64.whl:

Publisher: publish.yml on beartype/plum

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file plum_dispatch-2.10.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for plum_dispatch-2.10.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1383d84a97dfb2f97bf5ddd8d7a50479ce4ad9f9c5cfad7c6d7406a60487c25d
MD5 20ccf3d1b7bd2163a0db42b5eb61a520
BLAKE2b-256 583b7137018e8f037301c483102e60149e08183de03295e703961a058e834e62

See more details on using hashes here.

Provenance

The following attestation bundles were made for plum_dispatch-2.10.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl:

Publisher: publish.yml on beartype/plum

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file plum_dispatch-2.10.0-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for plum_dispatch-2.10.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 053cb6949b99b14d2d6b7935b545a2c73079f596a8ee21033e870379392bced4
MD5 89fdf2170b3e27e6bcca1c5b34ca2146
BLAKE2b-256 add96927bacd5809585c2c9b0e84194dfcadf91e6a27f0f90590b51b4aa8507c

See more details on using hashes here.

Provenance

The following attestation bundles were made for plum_dispatch-2.10.0-cp311-cp311-macosx_10_9_x86_64.whl:

Publisher: publish.yml on beartype/plum

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file plum_dispatch-2.10.0-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for plum_dispatch-2.10.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 411528c45263bbf65a0a59ea4fbf1691112cb625903974deb13ec7afd5ab69cc
MD5 b55bc24c931804bec23266f1fb1c0261
BLAKE2b-256 271dc8ad6fd807e0e5f5d3e2a6a796c6d555e955c6f67b4fbdce1eeabfd93448

See more details on using hashes here.

Provenance

The following attestation bundles were made for plum_dispatch-2.10.0-cp310-cp310-win_amd64.whl:

Publisher: publish.yml on beartype/plum

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file plum_dispatch-2.10.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for plum_dispatch-2.10.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 da8ae39bbae990b96242ec93d263a51e80df5a4e8a41c5c77b7482ea1ac66942
MD5 9ce2e227e37ed78b1a6a36f2a16acd3b
BLAKE2b-256 91749b57ceecea9afc7a1fe441471074cf5e4b226b92f41be736e00aa6a97e33

See more details on using hashes here.

Provenance

The following attestation bundles were made for plum_dispatch-2.10.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl:

Publisher: publish.yml on beartype/plum

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file plum_dispatch-2.10.0-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for plum_dispatch-2.10.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 87bc118922cde767b51f7815a7a338d055500bff85fc90dc0ea8b94fd01b18de
MD5 16b7477ce55e74582e4aa0e323c4abe8
BLAKE2b-256 a52793cb6644b2b3f7d6b7083ea229e940910fc8a528209ac9a0a80aad99dc56

See more details on using hashes here.

Provenance

The following attestation bundles were made for plum_dispatch-2.10.0-cp310-cp310-macosx_10_9_x86_64.whl:

Publisher: publish.yml on beartype/plum

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

2.10.0 This release

14 files

2.9.0

14 files

2.8.0

14 files

2.7.1

14 files

2.7.0

14 files

2.6.1

2 files

2.6.0

2 files

2.5.8

2 files

2.5.7

2 files

2.5.6

2 files

2.5.5

2 files

2.5.4

2 files

2.5.3

2 files

2.5.2

2 files

2.5.1.post1

2 files

2.5.1

2 files

2.5.0

2 files

2.4.4

2 files

2.4.3

2 files

2.4.2

2 files

2.4.1

2 files

2.4

2 files

2.3.6

2 files

2.3.5

2 files

2.3.4

2 files

2.3.3

2 files

2.3.2

2 files

2.3.1

2 files

2.3.0

2 files

2.2.2

2 files

2.2.1

2 files

2.2.0

2 files

2.1.1

2 files

2.1.0

2 files

2.0.1

2 files

2.0.0

2 files

1.7.4

2 files

1.7.3

2 files

1.7.2

2 files

1.7.1

2 files

1.7

1 file

1.6

36 files

1.5.16

36 files

1.5.15

36 files

1.5.14

36 files

1.5.13

36 files

1.5.12

36 files

1.5.11

36 files

1.5.10

43 files

1.5.9

43 files

1.5.8

43 files

1.5.7

43 files

1.5.6

40 files

1.5.5

1 file

1.5.4

1 file

1.5.3

1 file

1.5.2

1 file

1.5.1

1 file

1.5.0

1 file

1.4.0

1 file

1.3.3

1 file

1.3.2

1 file

1.3.1

1 file

1.3.0

1 file

1.2.0

1 file

1.1.1

1 file

1.1.0

1 file

1.0.0

1 file

0.2.5

1 file

0.2.4

1 file

0.2.3

1 file

0.2.2

1 file

0.2.1

1 file

0.2.0

1 file

0.1.6

1 file

0.1.5

1 file

0.1.4

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page