Skip to main content

grippo

The Python binding for grippo: secrets, credential fields and personal data found in log text and replaced with tokens, grippo's field scanners and literal sets, regex patterns, and CEL filters over raw JSON.

from datetime import UTC, datetime

from grippo import Field, LiteralSet, Scrubber

scrubber = Scrubber()  # gitleaks' rules, every layer, mask redaction
text, report = scrubber.scrub_text("login password=hunter2 from alice@example.com")
record, report = scrubber.scrub_value(
    {"user": {"password": "hunter2"}, "at": datetime.now(UTC)}
)
Field("MAC").fullmatch("00:1a:2b:3c:4d:5e")  # True
LiteralSet(["db-1", "alice"], boundary=True).find_all(
    "alice on db-1"
)  # [(0, 5, 1), (9, 13, 0)]

Scrubbing

Build one Scrubber and share it across threads.

  • scrub_text_or_none(text) gives the scrubbed text, or None when nothing changes, so a caller that only needs to know skips the copy.
  • A value runs on through a lone surrogate in scrub_text and is masked whole. Where the credential pair layer rewrites a text, each surrogate in it comes back as three U+FFFD, as errors="replace" decodes it.
  • scrub_value(value, *, default=None, max_depth=32, max_strings=64) reads any Python value the way a log record's fields are read. A dict's own keys and string values are always read. Inside a container, keys and strings past max_strings read <elided> and the rest is counted. A container max_depth deep reads <depth limit>, and one inside itself <cycle>. NaN and the infinities read by name. Anything else, such as bytes, datetime, Decimal or a set, goes through default, str when None, and one that raises reads <unprintable TYPE>. Keys are scrubbed too, and their order is kept.
  • In scrub_value, a tuple, or a two-item list inside a list, whose first item names a credential keeps the name and masks the value, as a header list holds them. An int past 64 bits reads as its decimal text. None or an empty string under a credential name is kept, as there is nothing in it.
  • Scrubber(only_rules=[...]) builds just those config rules, and refuses an id the config has no rule for. without_rules=[...] leaves rules out by id, a PII check included. skipped() lists each rule the build left out and why.
  • Scrubber(redaction="hash", hash_key=...) writes [<RULE>_<16 hex>], the first 8 bytes of HMAC-SHA256 over the secret. An empty key hashes as HMAC does with b"".
  • is_credential_name(name, parent="", *, extra=()) says whether a field name holds a credential, and mask_text(text, mask, *, extra=()) masks every credential value in a text. extra adds terms to SENSITIVE_FIELDS, a frozenset, for that call.
  • The text layer and mask_text mask a header value an HTTP client's error quotes as refused, whole and past \ escapes: Illegal header value b'Basic dXNlcg==' keeps its head and quotes and loses the value. One that never closes is masked to the end of its line.
  • mask_url_userinfo(text, mask=MASK_VALUE, *, keep_user=True) masks every URL password, and the user too with keep_user=False. MASK_VALUE is ***REDACTED***.
  • url_passwords(text) lists every URL password in a text, as written.
  • rule_token(rule) gives the stem of the token a rule writes: rule_token("credit-card") is CREDIT_CARD, written as [CREDIT_CARD_REDACTED].
  • The PII layer checks card numbers, IBANs, email addresses, phone numbers, and AU ABN, ACN, Medicare and TFN numbers.

Fields and literal sets

  • Field(name) is one of grippo's field parsers, named for the grok pattern it reads: IPV4, IPV6, MAC, UUID, HOSTNAME, EMAILADDRESS, TIMESTAMP_ISO8601, UNIXPATH and the rest in FIELD_NAMES. Each reads exactly as its regex, leftmost first, with no regex run unless a non-ASCII digit needs one.
  • fullmatch(text) says whether the field, read from the start, takes all of the text. scan(text, at=0) gives where it ends from an index, and find_all(text) the (start, end) of each match. Indices are str indices.
  • Field("IPV4", validate=True) also holds each octet to 255 or less, and PORT to 16 bits.
  • LiteralSet(literals, *, boundary=False) finds every literal in one pass. find_all(text) gives (start, end, index): leftmost first, the longest at one start, none overlapping. With boundary, a match has no ASCII letter or digit beside it, and a literal that fails that gives way to a shorter one at the same start, as (?<![A-Za-z0-9])(?:...)(?![A-Za-z0-9]) does with its alternatives longest first.

Patterns and CEL filters

from grippo import Program, Refusal, StrMatcher

StrMatcher("^web-[0-9]+$").is_match("web-12")  # True
program = Program.compile('host.startsWith("prod-") && severity > 3')
program.matches(b'{"host":"prod-1","severity":5}')  # True
program.explain()  # 'and(prefix(host, "prod-"), Gt(severity, Int(3)))'
refused = Program.compile("size(tags) > 0")
isinstance(refused, Refusal)  # True
refused.why, refused.span  # ('a function call outside the subset', (0, 4))
  • StrMatcher(pattern) reads a regex as Rust's regex does: $ matches only at the very end, never before a final newline, and lookaround or a backreference doesn't build. An empty pattern raises ValueError, since it would match everywhere. is_match(text) runs the cheapest check that gives the regex's answer, and tier names it: Byte, Literal, LiteralSet or Regex. hint says what would reach a faster one.
  • Program.compile(text, *, allow_regex=False) lowers a CEL filter to grippo's own checks over raw JSON, with cel's meaning and no interpreter. A form outside what grippo lowers, such as size(), a macro or a comparison of two fields, comes back as a Refusal, not an exception, so the caller runs its interpreter for that filter. why says what the form is and span where it sits, in str indices. matches() lowers only with allow_regex=True.
  • eval(record) takes the record as bytes or str and gives True, False, or the name of the error cel would raise: missing_root, missing_field, type_mismatch, malformed or overflow. matches(record) is True only on True.
  • explain() names each check the filter runs, one line, for a startup log or a UI that shows what the runtime does.
  • has() takes a member, has(a.b), as cel does. has(a) on a bare name is refused.

Metadata

Release files for grippo 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for grippo 0.1.3
File Actions
grippo-0.1.3-cp314-abi3-win_amd64.whl CPython 3.14 abi3 Windows x86-64 Details for grippo-0.1.3-cp314-abi3-win_amd64.whl
grippo-0.1.3-cp314-abi3-musllinux_1_2_x86_64.whl CPython 3.14 abi3 Linux musl 1.2+ x86-64 Details for grippo-0.1.3-cp314-abi3-musllinux_1_2_x86_64.whl
grippo-0.1.3-cp314-abi3-musllinux_1_2_aarch64.whl CPython 3.14 abi3 Linux musl 1.2+ ARM64 Details for grippo-0.1.3-cp314-abi3-musllinux_1_2_aarch64.whl
grippo-0.1.3-cp314-abi3-manylinux_2_28_x86_64.whl CPython 3.14 abi3 Linux glibc 2.28+ x86-64 Details for grippo-0.1.3-cp314-abi3-manylinux_2_28_x86_64.whl
grippo-0.1.3-cp314-abi3-manylinux_2_28_aarch64.whl CPython 3.14 abi3 Linux glibc 2.28+ ARM64 Details for grippo-0.1.3-cp314-abi3-manylinux_2_28_aarch64.whl
grippo-0.1.3-cp314-abi3-macosx_11_0_arm64.whl CPython 3.14 abi3 macOS 11.0+ ARM64 Details for grippo-0.1.3-cp314-abi3-macosx_11_0_arm64.whl

Total release size: 10.3 MB

Release files / grippo-0.1.3-cp314-abi3-win_amd64.whl

Download URL grippo-0.1.3-cp314-abi3-win_amd64.whl
Size 1.6 MB
Tags CPython 3.14 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
56417988421b61374a108c79457369e15a076cc1ff44d670f2ff81359abec3f9
BLAKE2b-256 checksum
How to use checksums
575826c6a592e3166272f631c824c46f0077f9b607f7ce98cd8b9812653a44cd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / grippo-0.1.3-cp314-abi3-musllinux_1_2_x86_64.whl

Download URL grippo-0.1.3-cp314-abi3-musllinux_1_2_x86_64.whl
Size 1.8 MB
Tags CPython 3.14 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
bd423c7f30d2c41ba218842c65ce2e283f4fa9b466e4a952d1fdd1148ea27db1
BLAKE2b-256 checksum
How to use checksums
e280960ad1e906f0169f834027373e52a99aa45ea5a8598bc37bf1eda76fecd6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / grippo-0.1.3-cp314-abi3-musllinux_1_2_aarch64.whl

Download URL grippo-0.1.3-cp314-abi3-musllinux_1_2_aarch64.whl
Size 1.7 MB
Tags CPython 3.14 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
c1efa9527b45d745cf0b6b5a03a16e5dacb80c709e98c1766eaff8e2fb32c3eb
BLAKE2b-256 checksum
How to use checksums
aef5476b210673915a616443e55d2845fa014f8060050e789b2bb2757225f588
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / grippo-0.1.3-cp314-abi3-manylinux_2_28_x86_64.whl

Download URL grippo-0.1.3-cp314-abi3-manylinux_2_28_x86_64.whl
Size 1.8 MB
Tags CPython 3.14 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
65928aca1bac469d900063316ea37d272304dedc3546c5eef876b28fb8189759
BLAKE2b-256 checksum
How to use checksums
86dc1cfa560edd4e49cb36953f9cac81146fd32f5ad6bf5105d4c6278932a67c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / grippo-0.1.3-cp314-abi3-manylinux_2_28_aarch64.whl

Download URL grippo-0.1.3-cp314-abi3-manylinux_2_28_aarch64.whl
Size 1.7 MB
Tags CPython 3.14 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
61e91faafde62c86d4c0bb792190b18af9a3952a9b926a0fba24b74f5cff78f4
BLAKE2b-256 checksum
How to use checksums
a373ecf42708858dbe47db554f69c95e08c325dd43f1f75bfbee6b65c2aa3715
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / grippo-0.1.3-cp314-abi3-macosx_11_0_arm64.whl

Download URL grippo-0.1.3-cp314-abi3-macosx_11_0_arm64.whl
Size 1.7 MB
Tags CPython 3.14 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
f6a806d721fea0ef6364f99ad83033c65c4daebc3578ffd06c91b9ff55053758
BLAKE2b-256 checksum
How to use checksums
131a219958c3526bd66fa9b85094547794cee319aeb259a7b308ca08a7cba07a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for grippo 0.1.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page