Skip to main content

Python Pattern Matching

Project description

Python Pattern Matching

Reusable pattern matching for Python, implemented in Cython. I originally developed this system for the Ibis Project in pure python, but it can be useful in many other contexts as well.

Examples

from koerce import match, NoMatch
from koerce.sugar import Namespace
from koerce.patterns import SomeOf, ListOf

assert match([1, 2, 3, SomeOf(int, at_least=1)], four) == four
assert match([1, 2, 3, SomeOf(int, at_least=1)], three) is NoMatch

assert match(int, 1) == 1
assert match(ListOf(int), [1, 2, 3]) == [1, 2, 3]
from dataclasses import dataclass
from koerce.sugar import match, Namespace, var
from koerce.patterns import pattern
from koerce.builder import builder

@dataclass
class A:
    x: int
    y: int

@dataclass
class B:
    x: int
    y: int
    z: float


p = Namespace(pattern, __name__)
d = Namespace(builder, __name__)

x = var("x")
y = var("y")

assert match(p.A(~x, ~y) >> d.B(x=x, y=1, z=y), A(1, 2)) == B(x=1, y=1, z=2)

More examples and a comprehensive readme are on the way.

Packages are not published to PyPI yet.

Python support follows https://numpy.org/neps/nep-0029-deprecation_policy.html

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

koerce-0.0.8.tar.gz (41.8 kB view details)

Uploaded Source

Built Distributions

koerce-0.0.8-cp312-cp312-win_amd64.whl (402.0 kB view details)

Uploaded CPython 3.12 Windows x86-64

koerce-0.0.8-cp312-cp312-win32.whl (334.5 kB view details)

Uploaded CPython 3.12 Windows x86

koerce-0.0.8-cp312-cp312-musllinux_1_2_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.12 musllinux: musl 1.2+ x86-64

koerce-0.0.8-cp312-cp312-musllinux_1_2_i686.whl (2.9 MB view details)

Uploaded CPython 3.12 musllinux: musl 1.2+ i686

koerce-0.0.8-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

koerce-0.0.8-cp312-cp312-manylinux_2_17_i686.manylinux_2_5_i686.manylinux1_i686.manylinux2014_i686.whl (3.1 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

koerce-0.0.8-cp312-cp312-macosx_14_0_arm64.whl (454.2 kB view details)

Uploaded CPython 3.12 macOS 14.0+ ARM64

koerce-0.0.8-cp312-cp312-macosx_13_0_x86_64.whl (490.6 kB view details)

Uploaded CPython 3.12 macOS 13.0+ x86-64

koerce-0.0.8-cp311-cp311-win_amd64.whl (417.7 kB view details)

Uploaded CPython 3.11 Windows x86-64

koerce-0.0.8-cp311-cp311-win32.whl (346.1 kB view details)

Uploaded CPython 3.11 Windows x86

koerce-0.0.8-cp311-cp311-musllinux_1_2_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.2+ x86-64

koerce-0.0.8-cp311-cp311-musllinux_1_2_i686.whl (2.9 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.2+ i686

koerce-0.0.8-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

koerce-0.0.8-cp311-cp311-manylinux_2_17_i686.manylinux_2_5_i686.manylinux1_i686.manylinux2014_i686.whl (3.1 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

koerce-0.0.8-cp311-cp311-macosx_14_0_arm64.whl (452.6 kB view details)

Uploaded CPython 3.11 macOS 14.0+ ARM64

koerce-0.0.8-cp311-cp311-macosx_13_0_x86_64.whl (503.3 kB view details)

Uploaded CPython 3.11 macOS 13.0+ x86-64

koerce-0.0.8-cp310-cp310-win_amd64.whl (417.1 kB view details)

Uploaded CPython 3.10 Windows x86-64

koerce-0.0.8-cp310-cp310-win32.whl (347.8 kB view details)

Uploaded CPython 3.10 Windows x86

koerce-0.0.8-cp310-cp310-musllinux_1_2_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.2+ x86-64

koerce-0.0.8-cp310-cp310-musllinux_1_2_i686.whl (2.6 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.2+ i686

koerce-0.0.8-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.0 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

koerce-0.0.8-cp310-cp310-manylinux_2_17_i686.manylinux_2_5_i686.manylinux1_i686.manylinux2014_i686.whl (2.8 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

koerce-0.0.8-cp310-cp310-macosx_14_0_arm64.whl (452.7 kB view details)

Uploaded CPython 3.10 macOS 14.0+ ARM64

koerce-0.0.8-cp310-cp310-macosx_13_0_x86_64.whl (502.5 kB view details)

Uploaded CPython 3.10 macOS 13.0+ x86-64

File details

Details for the file koerce-0.0.8.tar.gz.

File metadata

  • Download URL: koerce-0.0.8.tar.gz
  • Upload date:
  • Size: 41.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for koerce-0.0.8.tar.gz
Algorithm Hash digest
SHA256 69c34fad90c04a4ac136a93ccb47931dac8e37f27e649a94dbb05d3efef46851
MD5 547fbc92cbc1e7c5a4a5ebd4e3ef9d69
BLAKE2b-256 ab5803aa0e9e1cf3bd4c521c98e06728d2264c4df7df0f1a33cc95206be3f861

See more details on using hashes here.

Provenance

File details

Details for the file koerce-0.0.8-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: koerce-0.0.8-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 402.0 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for koerce-0.0.8-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 0dd61a52d06834d4b6db9ee53430bf6c3b806d6b372ce213e97248cfcb4845dd
MD5 91e8b2b1a06be1ceec5db05d8cf59bff
BLAKE2b-256 8b3d495094c653fd3b3e651800ff7ef0f27db23d6da6139244806bab7ba1794b

See more details on using hashes here.

Provenance

File details

Details for the file koerce-0.0.8-cp312-cp312-win32.whl.

File metadata

  • Download URL: koerce-0.0.8-cp312-cp312-win32.whl
  • Upload date:
  • Size: 334.5 kB
  • Tags: CPython 3.12, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for koerce-0.0.8-cp312-cp312-win32.whl
Algorithm Hash digest
SHA256 284f67d740e1124e1110c2011379f38da7030e5ac638719ae23493077b2d2a92
MD5 896a70036dd8d526f2f0976231a51af0
BLAKE2b-256 ff32555a6a55f4e8c3e8360055eeb51559754eec1225e42912eb88999edd6444

See more details on using hashes here.

Provenance

File details

Details for the file koerce-0.0.8-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for koerce-0.0.8-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 365bfedd8a4dbc5f4197271e0f8974ee8cf07cc421717f8f094cc14f9bcc4588
MD5 7487dbeeb89228313216eeff59fc8ff2
BLAKE2b-256 96b5410cd2f1f792c4678151b1f7a85a66e675bc5b929a21c22d24de6a2c8142

See more details on using hashes here.

Provenance

File details

Details for the file koerce-0.0.8-cp312-cp312-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for koerce-0.0.8-cp312-cp312-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 c91a917ad32f3c024ebb0ee7e0b4bb1ba20b10e11a0437f24781e258e9bf5bde
MD5 90657325eb4b2ad3e926e7ee813606ef
BLAKE2b-256 9247d0656ed793fbc5e19e5e6be8c631f13dce5fdb23d6a8266bf5ce46e23e80

See more details on using hashes here.

Provenance

File details

Details for the file koerce-0.0.8-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for koerce-0.0.8-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ab74641de333ba27d486f0fdc7da8c202059c0a6ec5e6dbe69835c688dd2b1dd
MD5 0ba54e149f1df2d74a1f14b5919613ac
BLAKE2b-256 d54d7ed4702d286088b4d45503567cccf4a6725eda6f2d6c77f7c62482d3b21b

See more details on using hashes here.

Provenance

File details

Details for the file koerce-0.0.8-cp312-cp312-manylinux_2_17_i686.manylinux_2_5_i686.manylinux1_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for koerce-0.0.8-cp312-cp312-manylinux_2_17_i686.manylinux_2_5_i686.manylinux1_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 09b754e51762c2fd67395fe30556b6e7819feb8676dce3d056668b005cf57ece
MD5 d4f26d23ec1071e76de8e767b8af9159
BLAKE2b-256 dd9e4bd4f0defc06ab684f6bf3236ec6ca2f0bb4dffa5d9f07d5c5e599f2016a

See more details on using hashes here.

Provenance

File details

Details for the file koerce-0.0.8-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for koerce-0.0.8-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 6ec33b285fec109e09192fc2178af4c3d2c78d24bc9350695a348b65590b791b
MD5 eb138b65b9a96c5c6090a4b47d59211f
BLAKE2b-256 3f15719d7ea708e96af45e22268c7bdb447599395998ef77cd1f637797218f06

See more details on using hashes here.

Provenance

File details

Details for the file koerce-0.0.8-cp312-cp312-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for koerce-0.0.8-cp312-cp312-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 cf032a4a79744f6f0a807981cce29345163b7fe8dbb23c60526e0aae341a19eb
MD5 810a9bd86baae0a17369ec10e699712f
BLAKE2b-256 b4db06e539c8c091f783d8fa937a7eb0e6519bbf906da2ecf9df076e34ec55c3

See more details on using hashes here.

Provenance

File details

Details for the file koerce-0.0.8-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: koerce-0.0.8-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 417.7 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for koerce-0.0.8-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 2bb0c08fcc32fdeac17fa8532817611b464f95ca4a3ff3ddf71929c5eebeb9ab
MD5 36d48afda907ecaae7a207308d64394e
BLAKE2b-256 61ddfd13cb6aaa27561aec6f4a9833b37c460aa4815d64916dc29fe2e1bf1f2e

See more details on using hashes here.

Provenance

File details

Details for the file koerce-0.0.8-cp311-cp311-win32.whl.

File metadata

  • Download URL: koerce-0.0.8-cp311-cp311-win32.whl
  • Upload date:
  • Size: 346.1 kB
  • Tags: CPython 3.11, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for koerce-0.0.8-cp311-cp311-win32.whl
Algorithm Hash digest
SHA256 db0937b9a3f0f157d63c5aaeab432a03322dff9e34cc7b68756964a34bc4c3f6
MD5 45a244da1d3600ab03c4876b2a34a3cb
BLAKE2b-256 29bdc9a1cb5435ad7cd0f1e1b8e4ce4df21f00d18f038d4d17143b309891404d

See more details on using hashes here.

Provenance

File details

Details for the file koerce-0.0.8-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for koerce-0.0.8-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 69ac5ed3f4d45ca02c5e797de19b473402e655e0361b833d7abac1a6c0bccff6
MD5 4b8b697f0d0ce4f2249633235e95d2cc
BLAKE2b-256 5dc6e18610201a17b9db7121c70fe5b4fcb0f2295edff9bc56556edbd5ea692e

See more details on using hashes here.

Provenance

File details

Details for the file koerce-0.0.8-cp311-cp311-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for koerce-0.0.8-cp311-cp311-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 5cc44ca71201d06ff94746794818f62a6756e987ca3d39ab0799a7a267e904a4
MD5 9d5c6adfcefdbf3e197c7ec111c06589
BLAKE2b-256 6ee15dd4f3ab70b255a884da976325dc7fa98f7db866cd843c2c62ea8c7a71ba

See more details on using hashes here.

Provenance

File details

Details for the file koerce-0.0.8-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for koerce-0.0.8-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 96b16df10bcce9509c5c356f850f6bae20f398e2cebbd007da5386f3537fbf03
MD5 d4d14bf6449bbed75d266a3796d3d987
BLAKE2b-256 ddad3cbe8827baaa259aed2c6e332a3b54cd08861e0c3a7f33e520cdcedced2b

See more details on using hashes here.

Provenance

File details

Details for the file koerce-0.0.8-cp311-cp311-manylinux_2_17_i686.manylinux_2_5_i686.manylinux1_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for koerce-0.0.8-cp311-cp311-manylinux_2_17_i686.manylinux_2_5_i686.manylinux1_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 b1a35b0a58ad6bcb0c3eea02a9cf7790575794548183f6eb6dc9d1e973291ebb
MD5 3e931bdc3a066d82cccfcdba78fe3ded
BLAKE2b-256 3733a1de43fb0c5618a706891e4a1da038580dbc0f54ed73b3c71d343cca1712

See more details on using hashes here.

Provenance

File details

Details for the file koerce-0.0.8-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for koerce-0.0.8-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 977353160bc71e250a51d62f6e56069419efc195d89e44c619d5cf859c0f928d
MD5 1df8064657e1ff15006aaeeeefc2eb83
BLAKE2b-256 360763d7fa762fa8209d1bf84982d7d432fdae1a5dc14c26cf5f9506c75bc99c

See more details on using hashes here.

Provenance

File details

Details for the file koerce-0.0.8-cp311-cp311-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for koerce-0.0.8-cp311-cp311-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 13f81d79b961aec7b490a6e83036a4ca6551b7625a4f52756b21eb3fdf331c48
MD5 d659b4828c725a6366f9c7fb742c0113
BLAKE2b-256 a49f9e125c6367b4b9b48d845f03e1d5c71c724c858f771fb35ce32f04b5d36f

See more details on using hashes here.

Provenance

File details

Details for the file koerce-0.0.8-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: koerce-0.0.8-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 417.1 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for koerce-0.0.8-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 987744e67c51e3cecc6dbc461e3f4d50da40e10f4bb2e218a11776164ca2cfcc
MD5 a6df5e3ec8d96132b2563d60c5627ea7
BLAKE2b-256 82ececb3f3af06343f1b16092b68d5728c752f3efb3c5a03b70542152b944534

See more details on using hashes here.

Provenance

File details

Details for the file koerce-0.0.8-cp310-cp310-win32.whl.

File metadata

  • Download URL: koerce-0.0.8-cp310-cp310-win32.whl
  • Upload date:
  • Size: 347.8 kB
  • Tags: CPython 3.10, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for koerce-0.0.8-cp310-cp310-win32.whl
Algorithm Hash digest
SHA256 e09e97320038b2c20b8fce7c7994d06d51fe6da081226f1546790ad3425d6b1d
MD5 560f602c6be081e0e0d5d1090ab4dbef
BLAKE2b-256 c4cc17f6361c98ce7fed227787c24eec51bcaff16a77170bae70110341132e65

See more details on using hashes here.

Provenance

File details

Details for the file koerce-0.0.8-cp310-cp310-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for koerce-0.0.8-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 acc2d5d9fe2b558ab3eb7aa781a44dd1c19d4c48ac56cb53c056dbb9ffcea175
MD5 bf0664b1357e5de86d8a1adfab15b2c7
BLAKE2b-256 e8f833c04cc79f9e6a07a50b7b1c1d6a59d966c39c1c837c2b3f92a9e5e405e9

See more details on using hashes here.

Provenance

File details

Details for the file koerce-0.0.8-cp310-cp310-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for koerce-0.0.8-cp310-cp310-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 68e077452d8f3f89377bf7ade7164a933d2392ad4997ecaf9f17cae9715b014a
MD5 fdaf3739754201172beda59a03c0c851
BLAKE2b-256 24d8a78f990410b9b15375ed4e96234d1cd1361e7f7b028416c987303764fd99

See more details on using hashes here.

Provenance

File details

Details for the file koerce-0.0.8-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for koerce-0.0.8-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 02496fee56d04aa4f4be6f7205c576277e083da32b16d50626dea845313078d0
MD5 5a67b4a1a91708ff1524165cbc0e0293
BLAKE2b-256 578fb1727bf1d6ca1990d884e59c54c26d4f2d01e43a3aca4b3bcbc13fd0b402

See more details on using hashes here.

Provenance

File details

Details for the file koerce-0.0.8-cp310-cp310-manylinux_2_17_i686.manylinux_2_5_i686.manylinux1_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for koerce-0.0.8-cp310-cp310-manylinux_2_17_i686.manylinux_2_5_i686.manylinux1_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 bc582a9be506b3d476e13d908d129fb50347cbfeb5942ba953019d1268c4d019
MD5 f8eb916a83ce3394cd4669d249850173
BLAKE2b-256 e1a579da5f1ad23121f8a2cffb9a0fc3347500616b52c79af70a3f005300c735

See more details on using hashes here.

Provenance

File details

Details for the file koerce-0.0.8-cp310-cp310-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for koerce-0.0.8-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 955f69f309332081a5748fac6581a99340e30396fd18b7c627b02ed5fcab009a
MD5 9817d0d4f6565fdcd9d77bafb968a3eb
BLAKE2b-256 2486d06fd4d45d58c00af0c392defcdfb5ab1256be948776aa416f3ef3f2799f

See more details on using hashes here.

Provenance

File details

Details for the file koerce-0.0.8-cp310-cp310-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for koerce-0.0.8-cp310-cp310-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 438baf4f633f3304ae0dc05ed050b7e858d458d980bb79b3caee3e6aa7e3e6de
MD5 c6961ca2b0e60f2d523e8a216f131f63
BLAKE2b-256 2f93cef13278f29e6395ab2714eb488f98fdb0ef69246493c404570cbd3d3360

See more details on using hashes here.

Provenance

Supported by

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