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

Uploaded Source

Built Distributions

koerce-0.0.6-cp312-cp312-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.12 Windows x86-64

koerce-0.0.6-cp312-cp312-win32.whl (1.4 MB view details)

Uploaded CPython 3.12 Windows x86

koerce-0.0.6-cp312-cp312-musllinux_1_2_x86_64.whl (7.6 MB view details)

Uploaded CPython 3.12 musllinux: musl 1.2+ x86-64

koerce-0.0.6-cp312-cp312-musllinux_1_2_i686.whl (7.1 MB view details)

Uploaded CPython 3.12 musllinux: musl 1.2+ i686

koerce-0.0.6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.3 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

koerce-0.0.6-cp312-cp312-manylinux_2_17_i686.manylinux_2_5_i686.manylinux1_i686.manylinux2014_i686.whl (7.8 MB view details)

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

koerce-0.0.6-cp312-cp312-macosx_14_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.12 macOS 14.0+ ARM64

koerce-0.0.6-cp312-cp312-macosx_13_0_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.12 macOS 13.0+ x86-64

koerce-0.0.6-cp311-cp311-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.11 Windows x86-64

koerce-0.0.6-cp311-cp311-win32.whl (857.8 kB view details)

Uploaded CPython 3.11 Windows x86

koerce-0.0.6-cp311-cp311-musllinux_1_2_x86_64.whl (4.9 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.2+ x86-64

koerce-0.0.6-cp311-cp311-musllinux_1_2_i686.whl (4.7 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.2+ i686

koerce-0.0.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.5 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

koerce-0.0.6-cp311-cp311-manylinux_2_17_i686.manylinux_2_5_i686.manylinux1_i686.manylinux2014_i686.whl (5.1 MB view details)

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

koerce-0.0.6-cp311-cp311-macosx_14_0_arm64.whl (732.7 kB view details)

Uploaded CPython 3.11 macOS 14.0+ ARM64

koerce-0.0.6-cp311-cp311-macosx_13_0_x86_64.whl (822.5 kB view details)

Uploaded CPython 3.11 macOS 13.0+ x86-64

koerce-0.0.6-cp310-cp310-win_amd64.whl (606.7 kB view details)

Uploaded CPython 3.10 Windows x86-64

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

Uploaded CPython 3.10 Windows x86

koerce-0.0.6-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.6-cp310-cp310-musllinux_1_2_i686.whl (2.2 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.2+ i686

koerce-0.0.6-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.6-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.6-cp310-cp310-macosx_14_0_arm64.whl (385.3 kB view details)

Uploaded CPython 3.10 macOS 14.0+ ARM64

koerce-0.0.6-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.6.tar.gz.

File metadata

  • Download URL: koerce-0.0.6.tar.gz
  • Upload date:
  • Size: 36.7 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.6.tar.gz
Algorithm Hash digest
SHA256 ffa90387b87ade9bd642fb83216298951e5f49a80709fd6405a62ea0ad021301
MD5 f8526ab917b16aab55191fce5f196cc6
BLAKE2b-256 a1d3c224a667b0c4344e6ece23ec494014c1308d6dc5ba6fe5b55d712ab48678

See more details on using hashes here.

File details

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

File metadata

  • Download URL: koerce-0.0.6-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 1.7 MB
  • 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.6-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 af68b967f90653b8b38dd105063b81c75a946823db729e9e0b934ed88edbffec
MD5 77a0d686193f32ffc115b68bfe1808fc
BLAKE2b-256 d967288b27ebfea2c8cdd017833425b75e58b43c2a0e95023e11d9a985c03b54

See more details on using hashes here.

File details

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

File metadata

  • Download URL: koerce-0.0.6-cp312-cp312-win32.whl
  • Upload date:
  • Size: 1.4 MB
  • 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.6-cp312-cp312-win32.whl
Algorithm Hash digest
SHA256 fcfba6c2f7932a4f65eebbf170bb556c4dbd19384aa597b9449ae9d5c218997d
MD5 6e94218cea70a3275d58a16d651b8858
BLAKE2b-256 fa3abf9c953096dc71be13b52faf508731fe69c64613efdc676eecaf8f3f1457

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for koerce-0.0.6-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 1e2108a081317233d258c5f7abd44bae838ff0264c94bb6694584db4ecb619f4
MD5 f877412a9249f49e509484dee6e333d8
BLAKE2b-256 c26b08dbd97e97826a32e624e5ae148408dd2b309e23196778d299f01b81aba2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for koerce-0.0.6-cp312-cp312-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 7e6e7dc331af048680c262071140a88cb72ba420477cc5b635d262ca6dcdb370
MD5 db2d18a9a80b176695af2b8bc994a37c
BLAKE2b-256 2f4e010459a2300e714d6d005ea6cd21b4d90c286c89fed15b9ada2c698aa329

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for koerce-0.0.6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2989a2bf59f16f031aa59f50a764b60bf7c1eb6c9c822a7782f7272f51458a4e
MD5 0980482c263be601de130cc9e7015089
BLAKE2b-256 224a77038736696bc112a3bd4b067603f6e6925c55968a4c37a5372795b7d518

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for koerce-0.0.6-cp312-cp312-manylinux_2_17_i686.manylinux_2_5_i686.manylinux1_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 e92303e0825a5190e4a4df02936ab088ee610267c2bbc2cf85e7037445ae58b1
MD5 f14de6dea3e8951da07f55513b7ef6d4
BLAKE2b-256 ca2961ea95880399fe75f64217178b2cf23a28e55b56fba3c0aea31989130b05

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for koerce-0.0.6-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 5197e2fbb4391496a5c200abcbd33a5bfb23acc02cd59dd74aeaa3053796cb2f
MD5 6875c4b6febb7fe66ceaae00a29d6dd8
BLAKE2b-256 5444bb4fab9fcdc86bb0ed00d8a2b1133190a3e96d9bad1d04ca279ac3881dd1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for koerce-0.0.6-cp312-cp312-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 1066b03b42d00ecd033be59192b1f7fc628bfd57a2616175c569f867ec99552c
MD5 840da7f69b75864e1b48b8024fc570b4
BLAKE2b-256 98fc8e2b78ae4ffee53038faae6eeef6da6dc23d5bd3cddc3c85827650e61d95

See more details on using hashes here.

File details

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

File metadata

  • Download URL: koerce-0.0.6-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 1.2 MB
  • 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.6-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 b952de80c187db7375192a3f9be0bf93be1a868aaff8c6990ce089e4d7d933b2
MD5 a0064f5e314713cd63e33be05d2873af
BLAKE2b-256 ef8438e66155ce362ca5c385bb78c316cee73795dd3cd7915514bc8579c6258d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: koerce-0.0.6-cp311-cp311-win32.whl
  • Upload date:
  • Size: 857.8 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.6-cp311-cp311-win32.whl
Algorithm Hash digest
SHA256 bf4b1c5a2ab6fd9162f3b5a68cc51abdf42dff8a3b7b62a048f5dcbff6b40d9f
MD5 af3230353d7c13693268321e27353e4c
BLAKE2b-256 dd5c9958e32b128ff31a8fde007e3a2ee13abd32d886ae53c8d0d5817d369410

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for koerce-0.0.6-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 1d3e996be17a1770c2ccdafd30a84c1630ece8d1f5aa3a113d8143a1c6702f8f
MD5 71502445534c8560ccc563cfdb1354cd
BLAKE2b-256 9fe3aaec57af2fe1cbeb44ef8f690616d6a837ed30412bce453f6ad218a85230

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for koerce-0.0.6-cp311-cp311-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 0adbda2bc4494783cf971e246fb40a8f23309d9d78fb236d8b5b55782e4763b0
MD5 10c949c5b3a0e0fac055fb2fd2995c36
BLAKE2b-256 f4919dc9579761c25e303aa6aa733c679d63f2a486e72af373712eaae61cba15

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for koerce-0.0.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8ae428c31d9b2fd43882179e4ae7cae3afa79bf0d65b44aadbe98776c984a83b
MD5 90add7024d441060e68d5365ee07841f
BLAKE2b-256 81b780438657849c86e2741e979b1696b8c12a5032a199548c6a8cb8f8695694

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for koerce-0.0.6-cp311-cp311-manylinux_2_17_i686.manylinux_2_5_i686.manylinux1_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 fecbc356187016805fb082f5b46f308de79ed945021866903c0c09799a041655
MD5 ee895ea830c84ded9716530aac57d508
BLAKE2b-256 a5ccb2b6f99751da12235da94237a533665b3df97e0e7e02a92bb87eb13f71fc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for koerce-0.0.6-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 0ea3a06d20d1f29d6f02595a1b159c50e81b293888b1092c9cede762b16203c2
MD5 123e0576467495a82cffa73dc84463b8
BLAKE2b-256 13c1c80378f77724e8bd5216be1b620e7ec4a4993620bf1799e1266c86bd8db2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for koerce-0.0.6-cp311-cp311-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 2c7b1a0c95d77e96f25d4dad2c32996d3e461fffe29a87c2bf63bb52fa269cde
MD5 4dc1973a840d3f5f03f1ffcf2f812838
BLAKE2b-256 40d322c582f3c91eb947f6f14573237e00716e01023151446d00fc27552ec75a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: koerce-0.0.6-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 606.7 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.6-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 b14b22eda27ed97874c1d1e5ea3a689799c1cbaad511093b643b3685b379fefc
MD5 4ef10b482f9b7587039651977711dc95
BLAKE2b-256 19062ea1892ececd72d9e41a5d3e4d0a2f4514258a86a40b0fa52d4729600687

See more details on using hashes here.

File details

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

File metadata

  • Download URL: koerce-0.0.6-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.6-cp310-cp310-win32.whl
Algorithm Hash digest
SHA256 dda09ecca71c8fa105d56b7f446a7433b2fe17797e13589aec8929a711e489d0
MD5 15b2f6d6136089eda2be865636487cf4
BLAKE2b-256 ebac943a068af91eea44c56f2902dbf62b9942467a2df02e09d47ad7ed637b51

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for koerce-0.0.6-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 355f24dc600836aef2fbcd9ef61b5bfc88f62365b33f1d5c3fcbc5bdb99e5ab5
MD5 98108086e7337d4920eaddb91be83f76
BLAKE2b-256 adbecd1e7907a9db3a349e330ebbf19980bc26d0d4cc8fa7ba08fb6b41919176

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for koerce-0.0.6-cp310-cp310-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 97d21226a303cc73725d246819b1c160224c71e6037a73524b27abd48cca8b34
MD5 3aa304d9df9bef014344cff32aa3d836
BLAKE2b-256 8e79931e15015707ec3464da479b72d0aef92bb59544033b19ecaa9c6c0d5485

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for koerce-0.0.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 dc05b58bf5f58f16fb5ed21455af7c3b4cb5974d906b74266085c9a08423410f
MD5 664c59f846f15d2ca237ffdd38922a5d
BLAKE2b-256 192b5e0f3c5e0a44c1767dfd61715c50348a04f1d1cabf263ac31ac62e361de7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for koerce-0.0.6-cp310-cp310-manylinux_2_17_i686.manylinux_2_5_i686.manylinux1_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 1eaf07c3301b49dff42c864b51a4c179c13280dc1c11512ee00c67f871ac394e
MD5 aec9a11a99da5e28df4c268c2b330156
BLAKE2b-256 9d560e1a8731bad50dda8d607e82c64d0be349046a8e6ddc0c052b77a5b6df73

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for koerce-0.0.6-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 eef7955a76223f670a97609aa26671b9d0dc0fada0e4b66acad72b4c2a52c881
MD5 e400113f5f01cdeb64b72fa8b615ceed
BLAKE2b-256 ed1441a62eae0692ec64a95e6778fe46a1335671a40d0359467f75ea647a5509

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for koerce-0.0.6-cp310-cp310-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 7ea9b1862f42d4c2263c315d934585a05cf2ae03a3b6bcf7598990ee6737afe3
MD5 b23155ff22aff5ad8c721083886afa38
BLAKE2b-256 2e23272f5390cd964637bc4d9a515b4a95d0f96437b60323b5f8dc4b452d0aed

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