Skip to main content

Last-stop alerts for Python automations.

Project description

logo

Shuuten — last-stop alerts for Python automations

PyPI version PyPI license PyPI Python versions GitHub Actions Documentation Status

Stop writing boilerplate alert code. Shuuten gives your Python automations structured JSON logging and instant Slack, Microsoft Teams, or email alerts when things go wrong — with zero dependencies and minimal setup.

Built for AWS Lambda and ECS, works anywhere Python runs.

終点 (Shūten) — "final stop" in Japanese. The last line of defense before a silent failure.

📖 Documentation · ⭐ Star on GitHub

Why Shuuten?

  • Zero dependencies — no SDKs, agents, or background workers
  • 3 lines to set up — decorator + one env var and you're done
  • Structured JSON logs — CloudWatch-friendly out of the box
  • Built for failure paths — only ERROR+ alerts are sent by default, no noise
  • Designed for AWS — Lambda, ECS tasks, and containers work out of the box
  • Logging-native — uses familiar logging semantics, no new concepts

Quick start (AWS Lambda)

import shuuten

@shuuten.capture
def lambda_handler(event, context):
    shuuten.error('domain error')    # → sends alert
    1 / 0                            # → alert with full stack trace

Configure one destination:

# Slack
export SHUUTEN_SLACK_WEBHOOK_URL="https://hooks.slack.com/services/..."
# OR Microsoft Teams
export SHUUTEN_TEAMS_WEBHOOK_URL="https://xxxxx.webhook.office.com/..."
# OR Email (Amazon SES)
export SHUUTEN_SES_FROM="..."
export SHUUTEN_SES_TO="..."

That's it.

Installation

pip install shuuten             # core package (logging, Slack, Teams)
pip install "shuuten[email]"    # + SES email support (boto3)

Usage patterns

Structured logging (logging-style)

Note: By default, only ERROR and above are sent to configured destinations. Lower-severity logs (DEBUG, INFO, WARNING) are emitted locally but are not sent as notifications unless min_level is changed.

import shuuten

def handler(event, context):
    shuuten.info('hello')        # not sent
    shuuten.error('bad input')   # sent to configured destinations

Explicit logger + notifications

Requires SES env vars (SHUUTEN_SES_FROM, SHUUTEN_SES_TO). Email is sent via AWS SES if configured.

import shuuten

shuuten.init(shuuten.Config(app='my-app', env='dev'))
log = shuuten.get_logger(__name__)


@shuuten.capture(workflow='my-workflow')
def handler(event, context):
    log.critical('Something went wrong')  # sent to configured destinations

Manual context control (advanced)

import shuuten

def handler(event, context):
    token = shuuten.detect_and_set_context(context)
    try:
        ...
    finally:
        shuuten.reset_runtime_context(token)

The capture() decorator works for ECS tasks as well (via ECS metadata v4).

Structured logging with extra

Works with both shuuten.info() and log = shuuten.get_logger(__name__) — any logger using ShuutenJSONFormatter.

Attach structured context with data

Pass a dict under the data key in extra to merge fields top-level into the JSON log output:

shuuten.info('Incoming event', extra={
    'data': {
        'method': 'POST',
        'path': '/slack/events',
        'status': 200,
    }
})
# → {"ts": ..., "level": "info", "msg": "Incoming event", "method": "POST", "path": "/slack/events", "status": 200, ...}

Note: Keys in data must not conflict with shuuten's built-in output fields (ts, fn, file, lineno, level, msg, logger, stack, kind, shuuten, exc). A ValueError is raised if they do:

ValueError: shuuten: extra 'data' keys ['msg'] conflict with built-in log output fields.

Attach internal shuuten context

Use the shuuten key to attach structured metadata that is nested under a shuuten field in the output:

shuuten.info('Processing request', extra={'shuuten': {'caller': 'my_fn', 'request_id': '123'}})
# → {"ts": ..., "msg": "Processing request", "shuuten": {"caller": "my_fn", "request_id": "123"}, ...}

Log a dict or list directly as msg

Pass a Python dict or list directly as the message — it will be embedded as a native JSON object rather than a stringified representation:

shuuten.info({'event': 'app_requested', 'app_id': 'A123', 'scopes': ['incoming-webhook']})
# → {"ts": ..., "msg": {"event": "app_requested", "app_id": "A123", "scopes": [...]}, ...}

This also works with shuuten.get_logger():

log = shuuten.get_logger(__name__)
log.info({'event': 'app_requested', 'app_id': 'A123'})

Configuration

You can configure Shuuten via Config in code or environment variables.

Variable Description Default
SHUUTEN_APP Application name (used for grouping/metadata) auto
SHUUTEN_ENV Environment name (prod, dev, staging, etc.) auto
SHUUTEN_MIN_LEVEL Minimum level sent to destinations ERROR
SHUUTEN_EMIT_LOCAL_LOG Emit local structured log when notifying true
SHUUTEN_QUIET_LEVEL Silence noisy third-party logs (e.g. boto) WARNING
SHUUTEN_DEDUPE_WINDOW_S Notification dedupe window (seconds); 0 disables 30

Slack

Variable Description
SHUUTEN_SLACK_WEBHOOK_URL Slack Incoming Webhook URL
SHUUTEN_SLACK_FORMAT blocks or plain

See Slack webhook setup

Microsoft Teams

Variable Description
SHUUTEN_TEAMS_WEBHOOK_URL Microsoft Teams Incoming Webhook URL

See Microsoft Teams Webhook Setup

Email (SES)

Variable Description
SHUUTEN_SES_FROM Verified SES sender
SHUUTEN_SES_TO Comma-separated recipient list
SHUUTEN_SES_REPLY_TO Optional reply-to address
SHUUTEN_SES_REGION Optional SES region

Supported destinations

Roadmap

  • Structlog processor integration
  • PagerDuty / JSM Alerting destination
  • Context manager for exception capture
  • Optional "exceptions-only" alerting mode
  • Expanded ECS and EKS support

Credits

Created with Cookiecutter using https://github.com/audreyfeldroy/cookiecutter-pypackage

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

shuuten-0.4.0.tar.gz (32.9 kB view details)

Uploaded Source

Built Distribution

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

shuuten-0.4.0-py3-none-any.whl (29.4 kB view details)

Uploaded Python 3

File details

Details for the file shuuten-0.4.0.tar.gz.

File metadata

  • Download URL: shuuten-0.4.0.tar.gz
  • Upload date:
  • Size: 32.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for shuuten-0.4.0.tar.gz
Algorithm Hash digest
SHA256 eab62231d6a6c03b079e7d05b3a0b8e7f7e4b5afa5a0a50dcf36fdb4468a35b5
MD5 bd7cad6717ac47beef3333197d756d0f
BLAKE2b-256 b62c50dec6c1a650b414f8e6cf14af671387a5855acfb83353d59f1f8617208d

See more details on using hashes here.

Provenance

The following attestation bundles were made for shuuten-0.4.0.tar.gz:

Publisher: release.yml on rnag/shuuten

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

File details

Details for the file shuuten-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: shuuten-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 29.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for shuuten-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 30369f697b826211e0457bc5b9b7a74eff054e85f1d37a3c933654d10097286f
MD5 ec11c845681c2d8227f702d312a55e8d
BLAKE2b-256 8605828c1cc6c71fa44ee4997d682f8a9f29f55fa21c9efd427b7e19e243cf78

See more details on using hashes here.

Provenance

The following attestation bundles were made for shuuten-0.4.0-py3-none-any.whl:

Publisher: release.yml on rnag/shuuten

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