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-2.10.1.tar.gz (250.8 kB view details)

Uploaded Source

Built Distributions

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

plum-2.10.1-py3-none-any.whl (49.4 kB view details)

Uploaded Python 3

plum-2.10.1-cp313-cp313-win_amd64.whl (246.5 kB view details)

Uploaded CPython 3.13Windows x86-64

plum-2.10.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (332.8 kB view details)

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

plum-2.10.1-cp313-cp313-macosx_10_13_x86_64.whl (283.1 kB view details)

Uploaded CPython 3.13macOS 10.13+ x86-64

plum-2.10.1-cp312-cp312-win_amd64.whl (245.8 kB view details)

Uploaded CPython 3.12Windows x86-64

plum-2.10.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (334.4 kB view details)

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

plum-2.10.1-cp312-cp312-macosx_10_13_x86_64.whl (284.9 kB view details)

Uploaded CPython 3.12macOS 10.13+ x86-64

plum-2.10.1-cp311-cp311-win_amd64.whl (244.1 kB view details)

Uploaded CPython 3.11Windows x86-64

plum-2.10.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (328.3 kB view details)

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

plum-2.10.1-cp311-cp311-macosx_10_9_x86_64.whl (278.9 kB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

plum-2.10.1-cp310-cp310-win_amd64.whl (244.3 kB view details)

Uploaded CPython 3.10Windows x86-64

plum-2.10.1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (335.4 kB view details)

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

plum-2.10.1-cp310-cp310-macosx_10_9_x86_64.whl (283.4 kB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

File details

Details for the file plum-2.10.1.tar.gz.

File metadata

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

File hashes

Hashes for plum-2.10.1.tar.gz
Algorithm Hash digest
SHA256 040e402f32c170cae7afc638e09b306fadb4036719c9e2a366243dd6b9ee4ae4
MD5 1e9445a3b4b7b000a6d3d0579fafe189
BLAKE2b-256 3fc2ba818f1d9a5ba8ee13a5f1509efeaf6236ed366cf338176d30a3ebbae750

See more details on using hashes here.

Provenance

The following attestation bundles were made for plum-2.10.1.tar.gz:

Publisher: publish_new_pypi_name.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-2.10.1-py3-none-any.whl.

File metadata

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

File hashes

Hashes for plum-2.10.1-py3-none-any.whl
Algorithm Hash digest
SHA256 10d84cb6812ded63a0155eadbd2740c2f8bc6f006c182bdd46de69380e42062b
MD5 2c4ba968a7c6c7588f3d2434a0de9950
BLAKE2b-256 ab470355204ea28395561c9cb0b9fc357b0c6b9d3f682c55ab324b66627db614

See more details on using hashes here.

Provenance

The following attestation bundles were made for plum-2.10.1-py3-none-any.whl:

Publisher: publish_new_pypi_name.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-2.10.1-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: plum-2.10.1-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 246.5 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for plum-2.10.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 7bd5d11dd79f2a006871710f6688cf64e0760ed72c72288c0c1f97881c4e7acc
MD5 c389f68fa6282e7542960343258b4e27
BLAKE2b-256 0023cc069ec5f1170f5b6050a789220e7d80c0865b5f58526b6ad942341669ea

See more details on using hashes here.

Provenance

The following attestation bundles were made for plum-2.10.1-cp313-cp313-win_amd64.whl:

Publisher: publish_new_pypi_name.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-2.10.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for plum-2.10.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 16ec6b288b02d77208d4d6288a9ff121d3f7342d0fe6570007a389c35967fd1c
MD5 6a95996973222395563ed8ea99d9c40e
BLAKE2b-256 5c4e435880a6496f4aef568bfb122706565f07efa8536807d111665107ba3ffb

See more details on using hashes here.

Provenance

The following attestation bundles were made for plum-2.10.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl:

Publisher: publish_new_pypi_name.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-2.10.1-cp313-cp313-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for plum-2.10.1-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 db193d9b02edc16bae25ec01f80bb1aed34142f79098f736095d70a40012fa2f
MD5 7a6dfea770bb93bc9081dc102678a3c1
BLAKE2b-256 7b667e5e44a43a05039a91f46445dc1bb1a5cad0742f0abc8cec72887b0caf97

See more details on using hashes here.

Provenance

The following attestation bundles were made for plum-2.10.1-cp313-cp313-macosx_10_13_x86_64.whl:

Publisher: publish_new_pypi_name.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-2.10.1-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: plum-2.10.1-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 245.8 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for plum-2.10.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 0027e05ab57e9598897ebb7f0fe150f9ca811d608e26d640ced5b66736714ab2
MD5 339e3d97ced4b12ee5a6911f9eaa2874
BLAKE2b-256 aed610dfc7166fd3588f61482e7b9e54527bad0accea47579b5eb0d0a6281631

See more details on using hashes here.

Provenance

The following attestation bundles were made for plum-2.10.1-cp312-cp312-win_amd64.whl:

Publisher: publish_new_pypi_name.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-2.10.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for plum-2.10.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 858c8d51d6e11944fb413624a92e8912ec0a6c7c28d1c791b0ce93f743a0c858
MD5 9d196c67af835fcecd0b65aad69fe809
BLAKE2b-256 42a75322bdef70ed3f7bc81d475fc5822adf813d23641564bf78df0d2979bd44

See more details on using hashes here.

Provenance

The following attestation bundles were made for plum-2.10.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl:

Publisher: publish_new_pypi_name.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-2.10.1-cp312-cp312-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for plum-2.10.1-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 bd782bc08cff746363d6485c3b2404941671fbc553edc8343d601f4d8b0e85cc
MD5 1fd571be3ab8cf85a024318524bc3da8
BLAKE2b-256 67f107f9da6b9b8055ad974ad581235864457711f59a62f3e14a2f0415330b7e

See more details on using hashes here.

Provenance

The following attestation bundles were made for plum-2.10.1-cp312-cp312-macosx_10_13_x86_64.whl:

Publisher: publish_new_pypi_name.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-2.10.1-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: plum-2.10.1-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 244.1 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for plum-2.10.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 ba1e80d1b162e9d77f45096953a6ad48be25479086e40025eb17ff89d3aadbf9
MD5 a7d8c34bab32f9f02d7101cfa6e6e527
BLAKE2b-256 5de39ff636e5453e323a193e1290ce5c5981cdeb035ec7434519c15208b9d098

See more details on using hashes here.

Provenance

The following attestation bundles were made for plum-2.10.1-cp311-cp311-win_amd64.whl:

Publisher: publish_new_pypi_name.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-2.10.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for plum-2.10.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 da05409ab22cd48a11a445a06e01f6eb8a7a0654c90ce2cb22129d5f15ced72c
MD5 2055c596a3e831e9099e069fca8b7c99
BLAKE2b-256 7fb9cf4dd09cf48a6165296d07032200577898c1c70904b68aa5912a1baba4af

See more details on using hashes here.

Provenance

The following attestation bundles were made for plum-2.10.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl:

Publisher: publish_new_pypi_name.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-2.10.1-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for plum-2.10.1-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 d5249e7061827f348997c552fb476c4003c2c56347cfcfde10fabcd376297277
MD5 bdee92da220ac82faef8ab5042af97e7
BLAKE2b-256 f669a23caeeee7fc17a6ee10df6bbe63639620439cce3043b53df0d674a1add4

See more details on using hashes here.

Provenance

The following attestation bundles were made for plum-2.10.1-cp311-cp311-macosx_10_9_x86_64.whl:

Publisher: publish_new_pypi_name.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-2.10.1-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: plum-2.10.1-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 244.3 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for plum-2.10.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 a851d1549b6a36556d9947fc77c96bd0abdf29fcf7c0f75067411eae4838b491
MD5 4bfc81811aa9af868e8326240715b745
BLAKE2b-256 08a900ca6d380b6cd335ae8849883d95ccaa341a4091b98e7d217f9a9376df61

See more details on using hashes here.

Provenance

The following attestation bundles were made for plum-2.10.1-cp310-cp310-win_amd64.whl:

Publisher: publish_new_pypi_name.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-2.10.1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for plum-2.10.1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8fe8f90a6b1ce665ec1b14a2cc451a7e26f35991a06350fec60e5866f1ccd05a
MD5 9abc2bfc4320a11ea708a1a99a40ae09
BLAKE2b-256 7361359610b8735d897184e3ac5dc3ec5bb6374e4dd116f9204ced16970d836f

See more details on using hashes here.

Provenance

The following attestation bundles were made for plum-2.10.1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl:

Publisher: publish_new_pypi_name.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-2.10.1-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for plum-2.10.1-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 26ab02f70290e1d73866b4a96437ab6d6de0ddc6bf16e425009d0ed3840c0319
MD5 ede3b49ded842b3e426cf2356a94b77f
BLAKE2b-256 b33ae160de0664052d49af750b5b7b2934af8832b463eecac49aeacd4e6cb16f

See more details on using hashes here.

Provenance

The following attestation bundles were made for plum-2.10.1-cp310-cp310-macosx_10_9_x86_64.whl:

Publisher: publish_new_pypi_name.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.1 This release

14 files

2.10.0

14 files

2.9.0

14 files

2.8.0

14 files

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