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.2

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.2
File Actions
grippo-0.1.2-cp314-abi3-win_amd64.whl CPython 3.14 abi3 Windows x86-64 Details for grippo-0.1.2-cp314-abi3-win_amd64.whl
grippo-0.1.2-cp314-abi3-musllinux_1_2_x86_64.whl CPython 3.14 abi3 Linux musl 1.2+ x86-64 Details for grippo-0.1.2-cp314-abi3-musllinux_1_2_x86_64.whl
grippo-0.1.2-cp314-abi3-musllinux_1_2_aarch64.whl CPython 3.14 abi3 Linux musl 1.2+ ARM64 Details for grippo-0.1.2-cp314-abi3-musllinux_1_2_aarch64.whl
grippo-0.1.2-cp314-abi3-manylinux_2_28_x86_64.whl CPython 3.14 abi3 Linux glibc 2.28+ x86-64 Details for grippo-0.1.2-cp314-abi3-manylinux_2_28_x86_64.whl
grippo-0.1.2-cp314-abi3-manylinux_2_28_aarch64.whl CPython 3.14 abi3 Linux glibc 2.28+ ARM64 Details for grippo-0.1.2-cp314-abi3-manylinux_2_28_aarch64.whl
grippo-0.1.2-cp314-abi3-macosx_11_0_arm64.whl CPython 3.14 abi3 macOS 11.0+ ARM64 Details for grippo-0.1.2-cp314-abi3-macosx_11_0_arm64.whl

Total release size: 10.1 MB

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

Download URL grippo-0.1.2-cp314-abi3-win_amd64.whl
Size 1.6 MB
Tags CPython 3.14 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
03de568a8e4fc9f245c7e47db7c60fb633b600dbe39e0b20ec0f633386c6fc29
BLAKE2b-256 checksum
How to use checksums
4474a9e48dff954545728ceb1c98904248180e54e787d602a9ed333bae57ab1e
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.2-cp314-abi3-musllinux_1_2_x86_64.whl

Download URL grippo-0.1.2-cp314-abi3-musllinux_1_2_x86_64.whl
Size 1.7 MB
Tags CPython 3.14 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
dc5e275a6c607f91b709243cd5b48b01250f0cfd16ca6cc27e3ce8943742d7c3
BLAKE2b-256 checksum
How to use checksums
7d486b6fa333657c653081bc6526616f08c7cf585bfc25c31de062022d73f245
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.2-cp314-abi3-musllinux_1_2_aarch64.whl

Download URL grippo-0.1.2-cp314-abi3-musllinux_1_2_aarch64.whl
Size 1.6 MB
Tags CPython 3.14 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
d3dd65f4225f0abd29f93451cee87d87e41f47cba5fffda2bf490272a36c6162
BLAKE2b-256 checksum
How to use checksums
76650ca74e7c406471ea44a6fd9a79b80cddf6d1f2081ece9664d63fa0540334
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.2-cp314-abi3-manylinux_2_28_x86_64.whl

Download URL grippo-0.1.2-cp314-abi3-manylinux_2_28_x86_64.whl
Size 1.7 MB
Tags CPython 3.14 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
8e6c0f5573771648463b44fdb4895b2a42c04826cbfa3e0177d97eaf5392f643
BLAKE2b-256 checksum
How to use checksums
cb7286fa32049c83a1c6658b652170cc697338c5295c03dd192a9788e43c1361
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.2-cp314-abi3-manylinux_2_28_aarch64.whl

Download URL grippo-0.1.2-cp314-abi3-manylinux_2_28_aarch64.whl
Size 1.6 MB
Tags CPython 3.14 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
531a69574b83665f42eb58482131c9029a05c930a17fad8198f8f4e46090fb64
BLAKE2b-256 checksum
How to use checksums
aa5a70b2c9467df9c491a0ed2a0bfa4ee17ec62831c959d5986475c45904ad4f
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.2-cp314-abi3-macosx_11_0_arm64.whl

Download URL grippo-0.1.2-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
92e738fc13c71015b724f49854ac8986524245e1c915506d4f304b9870484621
BLAKE2b-256 checksum
How to use checksums
649ecf61829be92caa887e6e8383cb6b6d2480213aeda745fe76462c5ed74532
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.2

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