shrug
¯\(ツ)/¯
Sometimes an exception just isn't worth crashing over. shrug lets you shrug
it off — as a decorator or a context manager — and keeps a running tally of
how many times it's had to.
Install
pip install shrug-it
Usage
As a decorator:
from shrug import shrug
@shrug()
def risky_division(a, b):
return a / b
risky_division(1, 0) # logs a warning, returns None instead of raising
As a context manager:
from shrug import shrug
with shrug(default=[]):
data = fetch_from_flaky_api()
Only shrug off specific exceptions:
@shrug(KeyError, ValueError)
def parse(d):
return d["value"]
Give up after N shrugs and let it actually raise:
@shrug(reraise_after=3)
def flaky():
...
Check the damage:
from shrug import stats
stats() # {'count': 7}
Why
Not every failure deserves a stack trace in a demo script, a notebook, or a
best-effort background job. shrug is a small, honest way to say "eh,
whatever" without silently eating errors you actually care about — you
choose exactly which exceptions get the shrug treatment.
License
MIT
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 shrug_it-0.1.0.tar.gz.
File metadata
- Download URL: shrug_it-0.1.0.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c151ba677436a27854a2b3fadb1182a272f163141b43866d9cf29dbc9c588e80
|
|
| MD5 |
bf8859da7450425e0606a5514b001750
|
|
| BLAKE2b-256 |
14cde6c15d47c1d93d3509dfd67b3a71175707716aee4b38abfdca47cc5fe3a9
|
File details
Details for the file shrug_it-0.1.0-py3-none-any.whl.
File metadata
- Download URL: shrug_it-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c18c446b1f14b36c2eadeee824c6c2bd356e5b59b584b232c7261f3a6aa8bd48
|
|
| MD5 |
03d261296276239db63656f9f2e4a93f
|
|
| BLAKE2b-256 |
2a81376e09c0078815dff2a49d48517387485b640a96e8eb75b074536b3d05c7
|