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

Uploaded Source

Built Distributions

koerce-0.0.7-cp312-cp312-win_amd64.whl (342.8 kB view details)

Uploaded CPython 3.12 Windows x86-64

koerce-0.0.7-cp312-cp312-win32.whl (279.7 kB view details)

Uploaded CPython 3.12 Windows x86

koerce-0.0.7-cp312-cp312-musllinux_1_2_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.12 musllinux: musl 1.2+ x86-64

koerce-0.0.7-cp312-cp312-musllinux_1_2_i686.whl (2.5 MB view details)

Uploaded CPython 3.12 musllinux: musl 1.2+ i686

koerce-0.0.7-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

koerce-0.0.7-cp312-cp312-manylinux_2_17_i686.manylinux_2_5_i686.manylinux1_i686.manylinux2014_i686.whl (2.7 MB view details)

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

koerce-0.0.7-cp312-cp312-macosx_14_0_arm64.whl (386.5 kB view details)

Uploaded CPython 3.12 macOS 14.0+ ARM64

koerce-0.0.7-cp312-cp312-macosx_13_0_x86_64.whl (419.1 kB view details)

Uploaded CPython 3.12 macOS 13.0+ x86-64

koerce-0.0.7-cp311-cp311-win_amd64.whl (355.2 kB view details)

Uploaded CPython 3.11 Windows x86-64

koerce-0.0.7-cp311-cp311-win32.whl (289.1 kB view details)

Uploaded CPython 3.11 Windows x86

koerce-0.0.7-cp311-cp311-musllinux_1_2_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.2+ x86-64

koerce-0.0.7-cp311-cp311-musllinux_1_2_i686.whl (2.5 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.2+ i686

koerce-0.0.7-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

koerce-0.0.7-cp311-cp311-manylinux_2_17_i686.manylinux_2_5_i686.manylinux1_i686.manylinux2014_i686.whl (2.7 MB view details)

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

koerce-0.0.7-cp311-cp311-macosx_14_0_arm64.whl (385.4 kB view details)

Uploaded CPython 3.11 macOS 14.0+ ARM64

koerce-0.0.7-cp311-cp311-macosx_13_0_x86_64.whl (430.8 kB view details)

Uploaded CPython 3.11 macOS 13.0+ x86-64

koerce-0.0.7-cp310-cp310-win_amd64.whl (355.0 kB view details)

Uploaded CPython 3.10 Windows x86-64

koerce-0.0.7-cp310-cp310-win32.whl (289.8 kB view details)

Uploaded CPython 3.10 Windows x86

koerce-0.0.7-cp310-cp310-musllinux_1_2_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.2+ x86-64

koerce-0.0.7-cp310-cp310-musllinux_1_2_i686.whl (2.2 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.2+ i686

koerce-0.0.7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

koerce-0.0.7-cp310-cp310-manylinux_2_17_i686.manylinux_2_5_i686.manylinux1_i686.manylinux2014_i686.whl (2.4 MB view details)

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

koerce-0.0.7-cp310-cp310-macosx_14_0_arm64.whl (385.3 kB view details)

Uploaded CPython 3.10 macOS 14.0+ ARM64

koerce-0.0.7-cp310-cp310-macosx_13_0_x86_64.whl (429.8 kB view details)

Uploaded CPython 3.10 macOS 13.0+ x86-64

File details

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

File metadata

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

File hashes

Hashes for koerce-0.0.7.tar.gz
Algorithm Hash digest
SHA256 1d57d807429becfded10bed92f293a51f831d8d189798289ad7a51d12277df83
MD5 644cf23bcc6f38c87e12e43ac4163224
BLAKE2b-256 2db2fe2e7e925b703926b4b418c5f23c85917be6013d0ccbec5ddb07903ab2fe

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for koerce-0.0.7-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 2be1e26de4ab9d24cb7821ca873e831eeb987e1f03b5c37bfb6625b8d4c077f8
MD5 50864a78e51bb29ebb89476360fa6e3f
BLAKE2b-256 b62f021756d633a0bb3e083d1d2906e527bbdc0e204bf0e94afeb04085ceb89e

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for koerce-0.0.7-cp312-cp312-win32.whl
Algorithm Hash digest
SHA256 86a4bcbea7b4fc01959f87356c0608f1ac7f7093ef4f246a5552b4e581fc6258
MD5 015fbe78d623c816898629587c1184d4
BLAKE2b-256 9a580e3807831f27bf215f2a5d51b73fa96b968aac70e2bb5a78507199ef5dfc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for koerce-0.0.7-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 55ec5566dca41352a6e89b15ba616170eb7107df09c0025410b504bdf9da42e2
MD5 d8bb2399a6739ebee840dcaeb138643d
BLAKE2b-256 4eeb70eccbc97629fa5902b15d5400127c0002ba4e5a80bf463ef1ae8dded15b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for koerce-0.0.7-cp312-cp312-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 6019b7f033de3c982131a0b0fe465eb14eae00dc85763e6011381d737caae4ed
MD5 9440095e8b3959ac4ab2d9b89ef4b36d
BLAKE2b-256 522b0572b35fc826829422a457b07c5c7a462d1682b12427873d4708efc74f61

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for koerce-0.0.7-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 21079d9e8288c56c522232e76e84cb4f53c1c07f0c6b95c685a62c0059212206
MD5 625f8aef1394e93bc59490eb02471e05
BLAKE2b-256 48750b6014b1a2ae6ef3ea527f88d38fb0219f2e8f1eccc0977d7a0002d3604d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for koerce-0.0.7-cp312-cp312-manylinux_2_17_i686.manylinux_2_5_i686.manylinux1_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 15e89685eeea3e07ed3559fc46153521b0f6e81fac85882ad0d39522eaa0d13b
MD5 326c6aa9b9e78cb1fb7e8a85d57654c5
BLAKE2b-256 1d00e0611de6a3f7a0a65c49a5375f3e147b78e1c512b92ebc973b9587ea6dfb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for koerce-0.0.7-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 e1bd2a09ccd8cae65f77d32d545590eb8c986959179f23263b64a0bfbdbb0bac
MD5 9b6d1e6be8e543c3d9e637da49540771
BLAKE2b-256 1af969e13dc434e146039d6eba3633828d3095f23a6d38fd14b619853064ab0e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for koerce-0.0.7-cp312-cp312-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 3cc8ba0412e2dc0f0e97488845cca24f9d4b0f20132892026f9e69995eea3160
MD5 599afabc1d52f50d6000cb86ae96fe86
BLAKE2b-256 f92f2f4afde57cc24b66046a6c1da7679ef785e04eaa23557263f1c1bb195d7e

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for koerce-0.0.7-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 84775efda53cdc6bcd60131e3db67dda1ab01afe80ea9163ce88474f70bcd963
MD5 1a5e7a09fc3148dbf34fa4b8090df9b4
BLAKE2b-256 7fc90bbbcc5fe72e3099d9b248f4324ed6436dbc31eb031c8dc9fa06aeb349a2

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for koerce-0.0.7-cp311-cp311-win32.whl
Algorithm Hash digest
SHA256 87b3ee8f89038fb4f35ec9f30d42cd01f830e3c56c0624db648554974f3afa63
MD5 29b90968e8f241aa0170b75b30c2a524
BLAKE2b-256 eafc6708b7a3f5957e7ead4082dca964941746016ef23455aff4d13f256573a0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for koerce-0.0.7-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 c748edc53620d5773736ee1c96205c6b9d7fb78e88a15a042a8005abea307f8b
MD5 c3f96df203c3cc9d1fb20399662571db
BLAKE2b-256 c0c67571e02e49463d6dbc0cccbfe9f61e1b58aa404ba1cb826c0f02d2426eb3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for koerce-0.0.7-cp311-cp311-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 1d8684642a65ef9accdf44fc36a591e3f731c8d6591e684a64f0fe22def8b605
MD5 86e8a07caeccc22eaca62cd92d22fce2
BLAKE2b-256 f5fa530be57d8ad5b7f9a7349ed903010e88bdafa6d3cd232ed43050dac6dc6f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for koerce-0.0.7-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 628e3622e80eb125b0220efb0cba5d03a1b54abbabb5929fe8ec5269f5d7599b
MD5 2e4754e97e5d10267292d662fb86a1b9
BLAKE2b-256 18449020272bb87a52358ac43d412535b16467fed02f686f4c18e28485d7859f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for koerce-0.0.7-cp311-cp311-manylinux_2_17_i686.manylinux_2_5_i686.manylinux1_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 01d05c6c0b6293e913a7155cd6419fc5adeac7c8cd00c8080c221a6e8ea806d1
MD5 fa09aaffba5775b44ee11a6ec0d817f2
BLAKE2b-256 3f549aa1f6a786b83d1ac8a503b7549ed391bd4dbc1160c9dbc21ced3cee3f52

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for koerce-0.0.7-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 510dddef123273342b0ff52ac2af51b29385a172189bfa6751e9f2eb1f9c193b
MD5 0317dbc300fb2eaa4289e981f7bf6763
BLAKE2b-256 312c26b3d1b7ea27587bd1e3c727d4934e317b4997f41bc4b207ab579c692cd1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for koerce-0.0.7-cp311-cp311-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 ed45068461930393d7b444cbe1fa67ce442e5a58088099cb02f4fe26251eb956
MD5 0d5a6946b1c5d79b84fcdaa6d7c62d2c
BLAKE2b-256 783f81f5eb59dfa13d0773e294c3e5e6fe98d68079c35a8dcad6437866283ca3

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for koerce-0.0.7-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 91159c0f82434f014708517af44b97825dc988fc83d9b9def91245c0ea6e26ae
MD5 bce45f935116fafd28a3a0d8a980ca44
BLAKE2b-256 7bea0a8e5a3b3c0d3c3b6d04fcf5102e19d4790d0979da9c5a9f7cd4d785f077

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for koerce-0.0.7-cp310-cp310-win32.whl
Algorithm Hash digest
SHA256 d3f367ce83012530f6dd4d5ca707b40b0e860595fe6a70f15d90e495c0bd457f
MD5 48ea5622a1167f380f24bd96f467f0a7
BLAKE2b-256 96d6b6f14546e9bbd9c9240d3520f3954337e7bc318f9645a1f36501cb705f0a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for koerce-0.0.7-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 586b911ce91cdd4917ae9f601cae9d842c39348989f0a235320bb0853fbc68c8
MD5 e90cc6bdb08c97aa2715cba9cd4cb615
BLAKE2b-256 1af9359f147c89b02b6ca257e910ed0079311446692dc1378618562e61ab5988

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for koerce-0.0.7-cp310-cp310-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 d3eb7137c3b66eadc7086afda3d3b21e47f58227ef09440349601ad10363d6a9
MD5 3e4f3313a3deb6912397d69491c29d26
BLAKE2b-256 c1997c35b4da3c793f423b366de054f4a6d787fb40cb841ce28e3c4959e0291f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for koerce-0.0.7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2f6159f61e2cb45f11898f828741a0b1adcd907a72ff7239b99d582e355c396c
MD5 456a5f78876f39e0152e54c83b96490c
BLAKE2b-256 5fd78cb8c4a7eac9cb7282be46420c475063aff6c6f606d3e17a8f1368e45c7e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for koerce-0.0.7-cp310-cp310-manylinux_2_17_i686.manylinux_2_5_i686.manylinux1_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 04f37dc0e3b6b7b7ae69e3705155ef2b35f01cadfa5f5d6472d192773945ec37
MD5 f2455ca473046634de3de51d9dcb787e
BLAKE2b-256 b9516d0b05d15d2bc157d90da5e64374f282eda9a3f9d74ad4f270b467384e54

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for koerce-0.0.7-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 cc6d53f92c449f040d8f6aeadcfe340393cc7215d6a06e8002953125014b2e65
MD5 01d3f5abd7db4a6e3c306793d79e14dd
BLAKE2b-256 e4ddeead41581b31dfd72adcb072beea2f84806cf0c326e2a3f2b40332dcaaf2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for koerce-0.0.7-cp310-cp310-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 d6e235e6799dc209c5dd681891877b13978df336f589f0c9049b8c77eb39a17c
MD5 17604067ab284832f440da7e4d023449
BLAKE2b-256 f25cd528a3862c32d797d1dca11d5f741761c1f251d675c2c542907b90ac5204

See more details on using hashes here.

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