Skip to main content

Expressive guard clauses for Python — fail fast with readable validation.

Project description

crashbytes-guard

Expressive guard clauses for Python — fail fast with readable validation.

Install

pip install crashbytes-guard

Usage

from crashbytes_guard import Guard

def create_user(name: str, age: int, email: str) -> None:
    Guard.against_none_or_whitespace(name, "name")
    Guard.against_out_of_range(age, 0, 150, "age")
    Guard.against_invalid_email(email, "email")
    # ...proceed safely

Available Guards

Method Description
against_none(value, name) Rejects None
against_none_or_empty(value, name) Rejects None or ""
against_none_or_whitespace(value, name) Rejects None, "", or whitespace-only
against_empty(value, name) Rejects empty collections/strings
against_negative(value, name) Rejects negative numbers
against_negative_or_zero(value, name) Rejects non-positive numbers
against_zero(value, name) Rejects zero
against_out_of_range(value, min, max, name) Rejects values outside [min, max]
against_invalid_email(value, name) Rejects invalid email format
against_invalid_url(value, name) Rejects non-HTTP(S) URLs
against_predicate(value, pred, name, msg) Rejects when predicate returns True
against_length_out_of_range(value, min, max, name) Rejects strings outside length range
against_type(value, expected, name) Rejects wrong types
against_not_in(value, allowed, name) Rejects values not in allowed set
against_pattern(value, pattern, name) Rejects strings not matching regex

All methods return the validated value for fluent chaining.

License

MIT

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

crashbytes_guard-1.0.0.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

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

crashbytes_guard-1.0.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file crashbytes_guard-1.0.0.tar.gz.

File metadata

  • Download URL: crashbytes_guard-1.0.0.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for crashbytes_guard-1.0.0.tar.gz
Algorithm Hash digest
SHA256 4cc69860991744c760e3d12b30a301bc186c242cdab8f7e4bd331fae04de0f19
MD5 ecec9f7bbd7693cdf78bae865b1da07a
BLAKE2b-256 20c82e3fc9eb70e591d4ad279a9d5f94de225d1ee73e264786c55d22e8deb431

See more details on using hashes here.

Provenance

The following attestation bundles were made for crashbytes_guard-1.0.0.tar.gz:

Publisher: publish.yml on CrashBytes/crashbytes-guard

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

File details

Details for the file crashbytes_guard-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for crashbytes_guard-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2ca12bd2eec0ea20ecea145d2db9b62c3fc7484bf89b9e956546d71e0341a39a
MD5 9f3a25d60e7e5eac0ff2c4feb65fd08c
BLAKE2b-256 54edb99991ee838d2b2accdf5f4442056ee2f4f0d022bc1df8fe7ee17fe6aa8d

See more details on using hashes here.

Provenance

The following attestation bundles were made for crashbytes_guard-1.0.0-py3-none-any.whl:

Publisher: publish.yml on CrashBytes/crashbytes-guard

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