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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4cc69860991744c760e3d12b30a301bc186c242cdab8f7e4bd331fae04de0f19
|
|
| MD5 |
ecec9f7bbd7693cdf78bae865b1da07a
|
|
| BLAKE2b-256 |
20c82e3fc9eb70e591d4ad279a9d5f94de225d1ee73e264786c55d22e8deb431
|
Provenance
The following attestation bundles were made for crashbytes_guard-1.0.0.tar.gz:
Publisher:
publish.yml on CrashBytes/crashbytes-guard
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
crashbytes_guard-1.0.0.tar.gz -
Subject digest:
4cc69860991744c760e3d12b30a301bc186c242cdab8f7e4bd331fae04de0f19 - Sigstore transparency entry: 1022914693
- Sigstore integration time:
-
Permalink:
CrashBytes/crashbytes-guard@29b2097c311acda755d4f189d3b44a86cb075d22 -
Branch / Tag:
refs/tags/1.0.0 - Owner: https://github.com/CrashBytes
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@29b2097c311acda755d4f189d3b44a86cb075d22 -
Trigger Event:
push
-
Statement type:
File details
Details for the file crashbytes_guard-1.0.0-py3-none-any.whl.
File metadata
- Download URL: crashbytes_guard-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ca12bd2eec0ea20ecea145d2db9b62c3fc7484bf89b9e956546d71e0341a39a
|
|
| MD5 |
9f3a25d60e7e5eac0ff2c4feb65fd08c
|
|
| BLAKE2b-256 |
54edb99991ee838d2b2accdf5f4442056ee2f4f0d022bc1df8fe7ee17fe6aa8d
|
Provenance
The following attestation bundles were made for crashbytes_guard-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on CrashBytes/crashbytes-guard
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
crashbytes_guard-1.0.0-py3-none-any.whl -
Subject digest:
2ca12bd2eec0ea20ecea145d2db9b62c3fc7484bf89b9e956546d71e0341a39a - Sigstore transparency entry: 1022914701
- Sigstore integration time:
-
Permalink:
CrashBytes/crashbytes-guard@29b2097c311acda755d4f189d3b44a86cb075d22 -
Branch / Tag:
refs/tags/1.0.0 - Owner: https://github.com/CrashBytes
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@29b2097c311acda755d4f189d3b44a86cb075d22 -
Trigger Event:
push
-
Statement type: