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 sequences — 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.

The matching semantics are explicit and tested against a reference matcher; underneath, it is a small Rust core with a Python API.

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

events = [
    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, events):
    print(m.partition, list(m.indices))   # api-1 [3, 4]

# Why didn't the others match?
for nm in explain(pattern, events):
    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(events) 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.2.0.tar.gz (69.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.2.0-cp39-abi3-win_amd64.whl (323.9 kB view details)

Uploaded CPython 3.9+Windows x86-64

epigrep-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (483.4 kB view details)

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

epigrep-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (477.6 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

epigrep-0.2.0-cp39-abi3-macosx_11_0_arm64.whl (425.8 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: epigrep-0.2.0.tar.gz
  • Upload date:
  • Size: 69.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.2.0.tar.gz
Algorithm Hash digest
SHA256 8a3f53ef4b629d40ce756553c867f4d763a0c3478b8182842b56e533d7c11f10
MD5 25e04826629328c1b40452331a0efd39
BLAKE2b-256 d86ef724a1fdf0fc8e1510a29d818ebbc1acfdc5c47f3051a7e191100891a3d6

See more details on using hashes here.

Provenance

The following attestation bundles were made for epigrep-0.2.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.2.0-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: epigrep-0.2.0-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 323.9 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.2.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 9107929f815eeee9601dc7d12892e96bbe7ddf2571bb41ca68d0f0aeb181fc40
MD5 87b1ffcdf7b0abc0b607e8298a80ddd9
BLAKE2b-256 4bf6f174f626e6c88a08328893a6a978cfdc2f713108055dcc8e78513da9b687

See more details on using hashes here.

Provenance

The following attestation bundles were made for epigrep-0.2.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.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for epigrep-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a9b865b5681f8823f00531e5ad1bee0f6942bc7b729788dca6445bed6dd40999
MD5 0e57a1d22fecf1332e0d4e01685c9a0c
BLAKE2b-256 089a15a2540a2b42726774d8fef2e09a88d369598f3d456b5005e4462d721dab

See more details on using hashes here.

Provenance

The following attestation bundles were made for epigrep-0.2.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.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for epigrep-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 13d5187b4ca21d28cdbb83f72d849bdfbf24973147d6adcabde0c8807f8aa4aa
MD5 d83a7e91b8ff978bbba705c43b87990e
BLAKE2b-256 9d146170a6c07f4025467f07cbdc23b5de3edcc30b62f830b144e6724688342c

See more details on using hashes here.

Provenance

The following attestation bundles were made for epigrep-0.2.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.2.0-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for epigrep-0.2.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 26be86438a69bca3b6ceb190e8a263f338c1dd9cbac264fad5a3a0eb1e07802a
MD5 2a5cebceeb82a325a2c76d8f8a6fe491
BLAKE2b-256 82e23d9c05124534ba90629f4797d10c46f7593fbcd84f21c555b08da9d6f78b

See more details on using hashes here.

Provenance

The following attestation bundles were made for epigrep-0.2.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