Skip to main content

The boring 90% of every bot, done for you: supervision, heartbeats, alerting, watchdog, dashboard, state.

Project description

bot-chassis

The boring 90% of every bot, done for you.

pip install bot-chassis

Anyone who has run a long-lived automation — a trading bot, an uptime monitor, a scraper, a report generator — ends up rebuilding the same plumbing: a scheduler loop, crash handling, restart logic, a way to know it's hung (not just dead), alerts to your phone, a kill switch, state that survives crashes, and a second process watching the first one. That plumbing is where the failures actually happen, and it has nothing to do with your domain.

chassis is that plumbing as a product. You write the 10% that's yours; it runs it like production infrastructure. Zero dependencies — pure Python stdlib, 3.11+.

A complete bot

from chassis import Bot

bot = Bot("uptime", log_file="uptime.log")

@bot.every(minutes=5)
def check():
    if not site_is_up("https://example.com"):
        bot.alert("DOWN: example.com")

bot.run()

That function now has, for free:

You get Meaning
Crash containment An exception in a job is logged + alerted; the loop survives
Scheduling @bot.every(minutes=5), @bot.daily_at("16:05", tz="America/New_York"), optional when= guards
Heartbeat A file touched every minute so outside processes can detect hangs
Kill switch Drop a STOP file → jobs pause, remove it → they resume
Alerts bot.alert(...) → console, SMS (email-to-SMS gateway), or webhook (Slack/Discord/ntfy)
State bot.state — atomic, crash-safe JSON that survives restarts

A supervised fleet

Declare bots once in bots.toml:

[chassis]
alerts = ["sms", "console"]
digest_at = "16:35"                # daily summary text

[[bot]]
name = "uptime"
command = "python3 uptime_bot.py"
heartbeat_max_minutes = 10
log = "uptime.log"

Then:

chassis run     # spawn everything; restart crashes; give up on crash-loops; alert on hangs
chassis watch   # independent watchdog — still texts you when the supervisor itself dies
chassis dash    # mission control: http://localhost:8899 status page (+ /api/status JSON)
chassis init    # starter bots.toml + hello bot

(python -m chassis works everywhere the chassis script does.)

The supervisor restarts bots that die (with rapid-crash backoff so a broken bot doesn't restart forever) and alerts on stale heartbeats. The watchdog runs as a separate process and re-checks everything from outside — processes, heartbeats, kill switch, error spikes in logs — with per-issue alert cooldowns and an optional daily digest and healthchecks.io ping. Domain checks plug in:

wd = Watchdog(load("bots.toml"))

@wd.add_check
def account_equity():   # anything that returns [(key, message)]
    ...

Troubleshooting

Every HTTPS request fails instantly with CERTIFICATE_VERIFY_FAILED (bot jobs, the sms/webhook channels): your Python has no CA certificate bundle — common with python.org installers on macOS. Either run the installer's Install Certificates.command, or point Python at the system bundle:

export SSL_CERT_FILE=/etc/ssl/cert.pem

Provenance

Extracted from a live multi-bot trading system where every one of these features was added because its absence caused a real incident: a bot that ran dead for a day with no alert (supervision), a hung process that passed the liveness poll (heartbeats), burst SMS silently collapsed by the carrier (delivery slots), a crash mid-write corrupting state (atomic saves), a launcher that couldn't report its own death (external watchdog). That trading fleet runs on bot-chassis today — this package is its production supervisor, not a side project's abstraction of one.

Linux and macOS. Python 3.11+. Zero dependencies, and that's a promise, not a current status.

Layout

chassis/
  runner.py       Bot — the decorator API and job loop
  supervisor.py   fleet spawn/restart/heartbeat supervision
  watchdog.py     independent external health monitor
  dashboard.py    one-file status page + JSON API (localhost only)
  notify.py       alert fan-out: console / sms / webhook
  state.py        crash-safe JSON state
  config.py       bots.toml loader
examples/
  uptime_bot.py   a complete non-trading bot in ~40 lines

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

bot_chassis-0.1.0.tar.gz (18.1 kB view details)

Uploaded Source

Built Distribution

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

bot_chassis-0.1.0-py3-none-any.whl (21.9 kB view details)

Uploaded Python 3

File details

Details for the file bot_chassis-0.1.0.tar.gz.

File metadata

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

File hashes

Hashes for bot_chassis-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cf785d7b2af905be439fe3cd3aff612a056ed0888038220c0ed48633f11622c3
MD5 22f62f5f8dce9409b5fc020ac6765b9e
BLAKE2b-256 c4f899c733a7be74699abc17d0d5463987c970cb87dc6407a0f85c27170b62ff

See more details on using hashes here.

Provenance

The following attestation bundles were made for bot_chassis-0.1.0.tar.gz:

Publisher: publish.yml on chrismance3-star/bot-chassis

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

File details

Details for the file bot_chassis-0.1.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for bot_chassis-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d5ca2777ac23e072db5fe7e48582aba0af76236cbedcff22c6ee20f01a928869
MD5 2ae46430b881ffc3b3270762cdd57008
BLAKE2b-256 d1c14b6bf782f1461c8656113cc956d850190c3187bff22502fb71f258d29146

See more details on using hashes here.

Provenance

The following attestation bundles were made for bot_chassis-0.1.0-py3-none-any.whl:

Publisher: publish.yml on chrismance3-star/bot-chassis

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