Skip to main content

Temporal event-pattern matching over partitioned, timestamped event sequences, with explicit semantics and near-miss explanations.

Project description

epigrep

PyPI Python versions License: MIT

Grep is good at lines. Epigrep is for sequences.

Epigrep finds temporal patterns in partitioned, timestamped event streams — the kind of question that is awkward in grep, SQL, or ad-hoc pandas: "a config reload followed by an OOM within two minutes, with no readiness success in between, per pod." You describe the sequence; Epigrep returns the matches, their spans and captured values, and — for the near-misses — an explanation of why they did not match.

It is a small Rust core with Python bindings and an explicit, tested matching contract.

Install

pip install epigrep

Prebuilt wheels cover Linux (x86_64, aarch64), macOS (Apple Silicon), and Windows (x64); other platforms build from the source distribution, which needs a Rust toolchain.

Quick start

from epigrep import Event, Pattern, explain, match

stream = [
    Event("api-0", 0,  "config_reload",     {"pod": "api-0"}),
    Event("api-0", 30, "readiness_success", {"pod": "api-0"}),
    Event("api-0", 70, "oom_killed",        {"pod": "api-0"}),
    Event("api-1", 0,  "config_reload",     {"pod": "api-1"}),
    Event("api-1", 90, "oom_killed",        {"pod": "api-1"}),
]

pattern = (
    Pattern.event("config_reload")
    .then("oom_killed", within=120, no="readiness_success")
    .build()
)

for m in match(pattern, stream):
    print(m.partition, list(m.indices))   # api-1 [3, 4]

# Why didn't the others match?
for nm in explain(pattern, stream):
    print(nm.partition, nm.reason)        # api-0 absence_blocked

api-1 matches: a reload, then an OOM 90s later, nothing in between. api-0 does not — a readiness_success lands in the gap, so the no= clause rules it out, and explain() tells you that rather than leaving you to work it out.

What you get back

For each start position, Epigrep returns either:

  • a match — participating event indices, the span (start and end timestamps), and any captured attribute values; or
  • a near-miss — for starts that cannot complete, the deepest partial path it reached and the reason the next step failed (predicate_failed, absence_blocked, window_exceeded, or no_successor), with structured detail.

schema(stream) summarises the event types and attributes present. Pandas dataframe helpers are available when pandas is installed; matching and explanation do not require it.

Patterns

Two construction surfaces are stable: the builder (above) for code written by hand, and a JSON pattern format for tools and agents that emit and validate patterns programmatically.

from epigrep import Pattern, pattern_from_json

ast = Pattern.event("A").then("B", within=5).build().to_json()
pattern = pattern_from_json(ast)   # validated; safe to match

A terse text DSL also exists (parse_pattern), but it is experimental and outside the 0.1 stability guarantee — prefer the builder or JSON format.

Semantics

Matching has an explicit, tested contract: ordering and tie-breaking, partitioning, match-consumption modes, inclusive windows, absence-between, capture/register equality, overlapping matches, and near-miss guarantees. A naive reference matcher is the source of truth; a second, independent implementation is checked against it by property tests. See the documentation.

Status

Alpha (0.1.0). The Python API and JSON pattern format are the intended stable surface; the text DSL is experimental. MIT licensed.

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

epigrep-0.1.0.tar.gz (45.6 kB view details)

Uploaded Source

Built Distributions

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

epigrep-0.1.0-cp39-abi3-win_amd64.whl (312.0 kB view details)

Uploaded CPython 3.9+Windows x86-64

epigrep-0.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (471.2 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64

epigrep-0.1.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (465.1 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

epigrep-0.1.0-cp39-abi3-macosx_11_0_arm64.whl (412.8 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

File details

Details for the file epigrep-0.1.0.tar.gz.

File metadata

  • Download URL: epigrep-0.1.0.tar.gz
  • Upload date:
  • Size: 45.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for epigrep-0.1.0.tar.gz
Algorithm Hash digest
SHA256 964a973bde565f25187ab28eba3225811be5457ea3e203e5471dcef76d934bad
MD5 1c52b222030901a8a9f28c797ba3ce79
BLAKE2b-256 03396133a9941a408d5f60105adf85e20aa91d66d1384d77a242bf2a4342a8dd

See more details on using hashes here.

Provenance

The following attestation bundles were made for epigrep-0.1.0.tar.gz:

Publisher: release.yml on rikkhill/epigrep

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file epigrep-0.1.0-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: epigrep-0.1.0-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 312.0 kB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for epigrep-0.1.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 33849c64c16a27af7c91c3696a7a229495c73b26b5706779b4ab77bc99fb4eca
MD5 3cbb154e551e0664bb02fe8c92763f30
BLAKE2b-256 036fcb08fd4e41480af928f561c7523a2db9407478cb092a93f769bc29442f82

See more details on using hashes here.

Provenance

The following attestation bundles were made for epigrep-0.1.0-cp39-abi3-win_amd64.whl:

Publisher: release.yml on rikkhill/epigrep

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file epigrep-0.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for epigrep-0.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 699fb8b2d70e605ab84dfdd77a42183829ea2df30e64c974813c56cc2cbd1e8a
MD5 b35457721cfcfd4341d6e58f69dda2e3
BLAKE2b-256 2151b475ad12dfde06a8ac3f302d6c49cde90d014cf62225759a373a46192db7

See more details on using hashes here.

Provenance

The following attestation bundles were made for epigrep-0.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on rikkhill/epigrep

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file epigrep-0.1.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for epigrep-0.1.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 52e0d245907eb8c120c0e836efa80a6a545d561d6887f0d86676104334067b78
MD5 4b7f5cc6e5bd6bb3d3d4c308405b82c7
BLAKE2b-256 c96adb6b7de76b2ebe40d2ea560d291b48cb79f36ec259e9959a389f1bad62f2

See more details on using hashes here.

Provenance

The following attestation bundles were made for epigrep-0.1.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on rikkhill/epigrep

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file epigrep-0.1.0-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for epigrep-0.1.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5939dd483168bc30041f2ebbb01b35600fe19bbba613ac62c23b4b8a5cb77775
MD5 4dcbcdf452c8bf69a0d9c561b393fc55
BLAKE2b-256 ef0cfeb0010dd00fc56c229e0e5a4a9229ee3cbbe1a1af0ac463e6af5a233431

See more details on using hashes here.

Provenance

The following attestation bundles were made for epigrep-0.1.0-cp39-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on rikkhill/epigrep

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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