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.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-2.10.0-py3-none-any.whl (48.9 kB view details)

Uploaded Python 3

plum-2.10.0-cp313-cp313-win_amd64.whl (245.9 kB view details)

Uploaded CPython 3.13Windows x86-64

plum-2.10.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (333.9 kB view details)

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

plum-2.10.0-cp313-cp313-macosx_10_13_x86_64.whl (284.4 kB view details)

Uploaded CPython 3.13macOS 10.13+ x86-64

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

Uploaded CPython 3.12Windows x86-64

plum-2.10.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (335.4 kB view details)

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

plum-2.10.0-cp312-cp312-macosx_10_13_x86_64.whl (286.0 kB view details)

Uploaded CPython 3.12macOS 10.13+ x86-64

plum-2.10.0-cp311-cp311-win_amd64.whl (242.5 kB view details)

Uploaded CPython 3.11Windows x86-64

plum-2.10.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (329.2 kB view details)

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

plum-2.10.0-cp311-cp311-macosx_10_9_x86_64.whl (279.8 kB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

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

Uploaded CPython 3.10Windows x86-64

plum-2.10.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (336.5 kB view details)

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

plum-2.10.0-cp310-cp310-macosx_10_9_x86_64.whl (284.5 kB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: plum-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-2.10.0.tar.gz
Algorithm Hash digest
SHA256 339e71a4277e5f5ac6837bfaadc208b8d6492132e68de86f2e191c86773c2a64
MD5 639b84c02325e709f35459720c9d893b
BLAKE2b-256 0fc2583bcf3de3baadd58bde31abebeeb44d6632858ca28cc71d412407f4966f

See more details on using hashes here.

Provenance

The following attestation bundles were made for plum-2.10.0.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.0-py3-none-any.whl.

File metadata

  • Download URL: plum-2.10.0-py3-none-any.whl
  • Upload date:
  • Size: 48.9 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fcd5a4eac885a5a68cf57369ca6a78fd3d6441bbb22524355dfd8fb48bfa12f9
MD5 9cd6a0faf24946eaef7f7a2b6c2237d4
BLAKE2b-256 a5a3d38d039ac3a7c8d1637c3bbab5e85ebc12cfb1b7b91b4e973a03512beb8d

See more details on using hashes here.

Provenance

The following attestation bundles were made for plum-2.10.0-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.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: plum-2.10.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 245.9 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.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 51cb1dc7b6b15240b623f3aa0343ac3f75237436f47dd306be05ca7fdc235e9d
MD5 5f16e129da974bb9ce5e0842ee3ac548
BLAKE2b-256 95582d914b0a744dba6e2d09053d20f22b182795d94cdd5d579700a73ce6a200

See more details on using hashes here.

Provenance

The following attestation bundles were made for plum-2.10.0-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.0-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.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f7b8c32b3141a0e9ec3c0ed3175f43dad91bd00dbf5174abb684839fbfcb5f52
MD5 dbb18a25c7f93839e9de7476779304ac
BLAKE2b-256 19d4a47358abdb4d3fd924201cf3a9d30327008e2070985d41c82c049a23e934

See more details on using hashes here.

Provenance

The following attestation bundles were made for plum-2.10.0-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.0-cp313-cp313-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for plum-2.10.0-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 d59a36aef59a03c836ee39f7e484bad5aabd78cb214f78f71a872e85107fb17a
MD5 a0e5e5d9a781640499b3d3df74476813
BLAKE2b-256 f781ee14f74831e7ad810834c758bff6a31222b50e2128c3d4bed53fe11abac0

See more details on using hashes here.

Provenance

The following attestation bundles were made for plum-2.10.0-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.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: plum-2.10.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 245.1 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.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 0b0d137747c8130e360f4c17b8cde983d5459b73354ba72a63b21bf46ce762b5
MD5 594f8077ee217448c0459df7c6ce18ff
BLAKE2b-256 a927b92a3503db76793ca247b58022292b4c85f213198c4607a6d97f557939a5

See more details on using hashes here.

Provenance

The following attestation bundles were made for plum-2.10.0-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.0-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.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b52fc5892c32ab5302083e2f90338b7119538dd77e1319206485ac0917252ef2
MD5 68dfffcc6d16a6063ff798841e26baac
BLAKE2b-256 f327bc7b8be6865444bd5d2e3554bff36f7c91d4c2e31cde5fd158f2ddccdf3b

See more details on using hashes here.

Provenance

The following attestation bundles were made for plum-2.10.0-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.0-cp312-cp312-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for plum-2.10.0-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 3764fda3d7db1e61935b578bce6238c4bd5d99db07b146596e7b2657dfee66b9
MD5 fa873b0a593718695e704de42d79a1ed
BLAKE2b-256 e0dbc928ded74f3c617eb175472b59b34821b9bca25f9411618a46c1e1b82696

See more details on using hashes here.

Provenance

The following attestation bundles were made for plum-2.10.0-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.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: plum-2.10.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 242.5 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.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 5cfbb26cf8b7fa123a04b0add5945af649ecac12e7b51cd029242cb84c1d6712
MD5 80586293bd1a9ea3fb8642b6e5d0ad82
BLAKE2b-256 03a3d5831f5188bc9bb64d81779b66d16b3f12e990fe4ac51592f560c9e05475

See more details on using hashes here.

Provenance

The following attestation bundles were made for plum-2.10.0-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.0-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.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f6687d783ed33d130695adcaaa22ebefd0d515bb72faf19d4b5db83570170137
MD5 fc5f264106d3019fa58d801faf2b95e0
BLAKE2b-256 45df1bb1ae1345be5daca069a77d4e48037253082033e3afc85090b1f151529b

See more details on using hashes here.

Provenance

The following attestation bundles were made for plum-2.10.0-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.0-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for plum-2.10.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 6b5c0c5ae45719705a21d0d7300023a6fa4c673fb46f901066ee2913d47b9d05
MD5 7d9b81300a5ed6426ec3eb8853c828b3
BLAKE2b-256 71fac6526c54c35aef3ea574fa48026e3a39472c614ec48e90e4161da273efc7

See more details on using hashes here.

Provenance

The following attestation bundles were made for plum-2.10.0-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.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: plum-2.10.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 242.7 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.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 f37e4438c925f938fd0c74d8d4cca1869c9e3552a0e0e7f474479a94269b94ab
MD5 6994b74b3b6498cf3b5f5f3e29b861ca
BLAKE2b-256 4f2096d1b2a073e14162e3eef6afa1cbd070a8248ee3e301179dd88eb1610469

See more details on using hashes here.

Provenance

The following attestation bundles were made for plum-2.10.0-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.0-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.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8a29385cb611792143894fac71f547f27c8629481f526f35ed240d70af1afcfc
MD5 e864c967928f903a29444de4624b09d6
BLAKE2b-256 e08dd7c6be96d64752fd58ce2c92311d67d0b50a5ae0e3c5028327f93d879c81

See more details on using hashes here.

Provenance

The following attestation bundles were made for plum-2.10.0-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.0-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for plum-2.10.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 273ddfef5d19dd950fc7078b3d26ca40a6b4e0615459d7fb8aea1bbd6e5fb353
MD5 aa1cfbe6b93be68b0285666735dc8e1e
BLAKE2b-256 d8ee9a65218841608ac736793408dd70a297169d59a326775df621acb75152af

See more details on using hashes here.

Provenance

The following attestation bundles were made for plum-2.10.0-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

2.10.1

14 files

This release

2.10.0 This release

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