Skip to main content

SilenceWatch for Python

Add the library and an API key. The scheduled jobs of your application show up in SilenceWatch with their real schedule, and send a heartbeat around each run.

Licensed under Apache-2.0 — deliberately, so it can be embedded in any application without licence consequences.

Scheduler Install What it reads
Celery beat pip install "silencewatch[celery]" the beat_schedule (crontab, timedelta, seconds)
django-celery-beat pip install "silencewatch[celery]" the periodic tasks in the database, read by the Celery integration
APScheduler 3 pip install "silencewatch[apscheduler]" the jobs of the scheduler (cron and interval triggers)

More are planned; see Adding an integration.

Set up

Create an API key in your project's Settings page and give it to the process:

export SILENCEWATCH_API_KEY=sw_...
# export SILENCEWATCH_URL=https://watch.example.com   # only when you host SilenceWatch yourself

Celery

from celery import Celery
from celery.schedules import crontab
from silencewatch.integrations.celery import instrument

app = Celery("shop")
app.conf.beat_schedule = {
    "nightly-backup": {"task": "shop.tasks.backup", "schedule": crontab(hour=2, minute=0)},
    "sync-prices": {"task": "shop.tasks.sync_prices", "schedule": 900.0},
}
instrument(app)

Workers declare the schedule when they start, and send a heartbeat from the worker that runs each scheduled task. Nothing else to write.

django-celery-beat

Nothing to add: when django_celery_beat is in INSTALLED_APPS, the same instrument(app) also reads the enabled periodic tasks of the database, crontab (with its own time zone) and interval, next to beat_schedule.

A change made while the workers run (in the Django admin, or in code) is declared again within a minute: each worker process looks at django-celery-beat's own change marker — one row — every minute, and reads and declares the schedule only when it moved. The new task's runs are reported from then on, without a restart.

APScheduler

from apscheduler.schedulers.background import BackgroundScheduler
from silencewatch.integrations.apscheduler import instrument

scheduler = BackgroundScheduler()
scheduler.add_job(backup, "cron", hour=2, id="nightly-backup")
scheduler.add_job(sync_prices, "interval", minutes=15, id="sync-prices")
instrument(scheduler)
scheduler.start()

Give each job an id. APScheduler makes up a random one otherwise, which changes on every start and cannot tie a job to its history. Without an id the job is identified by the function it runs, which is stable.

What it does

At startup, in one HTTP call, every job found is declared to POST /api/v1/checks/sync and the returned ping keys are kept in memory. Around each run:

POST /p/<key>/start                     when the run begins
POST /p/<key>/0?duration_ms=1234        when it returns
POST /p/<key>/fail?duration_ms=1234     when it raises

Each job gets a stable identity, which is what ties it to its history on the server across restarts, redeployments and renames:

Integration Key
Celery, django-celery-beat celery:shop.tasks.backup (the task name)
APScheduler apscheduler:nightly-backup (the job id, else apscheduler:app.jobs:backup, the function)

Jobs that disappear from the code are flagged orphaned on the server, never deleted.

Configuration

Every setting is a keyword argument (instrument(app, api_key="…", environment="staging")) and an environment variable. The keyword wins. Durations in the environment are a number of seconds.

Keyword Environment variable Default
api_key SILENCEWATCH_API_KEY — Without one nothing is sent
base_url SILENCEWATCH_URL https://app.silencewatch.com Your own instance when self-hosting
environment SILENCEWATCH_ENVIRONMENT production Part of a check's identity
enabled SILENCEWATCH_ENABLED true false removes everything, see below
default_grace SILENCEWATCH_DEFAULT_GRACE 5 min For jobs that declare none
auto_register SILENCEWATCH_AUTO_REGISTER true false to manage checks by hand
report_start SILENCEWATCH_REPORT_START true false to send only the outcome
timeout SILENCEWATCH_TIMEOUT 2 (s) Per call, deliberately short
queue_capacity SILENCEWATCH_QUEUE_CAPACITY 1000 Bounded, oldest dropped when full
timezone SILENCEWATCH_TIMEZONE UTC For cron jobs whose own schedule carries none
prune SILENCEWATCH_PRUNE true See below
per_instance_jobs SILENCEWATCH_PER_INSTANCE_JOBS — Jobs watched on each instance, see Several instances
instance_id SILENCEWATCH_INSTANCE_ID — This instance's stable name, for per_instance_jobs

prune flags as orphaned every check of the project and environment that the declaration leaves out. Use one environment per application; if several services share one project and environment, set prune=False, or each would orphan the others' checks.

Several instances

When an application runs as several processes or servers, they all declare the same jobs in the same environment, so each job is one check for all of them: it is up while any of them reports it.

  • Celery (and django-celery-beat): beat hands each run to one worker, whichever it is, and the check hears from it. That is the right rule, and the only one.
  • APScheduler runs inside each process. Started in every Gunicorn worker or every replica, a job runs once per process, and the check stays up while one of them runs it: a process whose scheduler is stuck goes unnoticed while another works. If the job should run once, start the scheduler in one process only; if it has to run in every one, read on.

Jobs that have to run in every instance (clearing a local cache, deleting temporary files) can be monitored on each one:

instrument(scheduler, per_instance_jobs=["apscheduler:evict-cache", "apscheduler:tmp-*"],
           instance_id=os.environ["HOSTNAME"])

or SILENCEWATCH_PER_INSTANCE_JOBS=apscheduler:evict-cache,apscheduler:tmp-* and SILENCEWATCH_INSTANCE_ID. Those jobs are declared in an environment of the instance's own, production.web-1, so each instance has its own check and one going quiet is seen while the others report. A trailing * matches a prefix; every other job stays shared. Celery tasks are never watched per instance, since one worker runs each run: the library says so and keeps them shared.

instance_id has no default, and must stay the same across restarts and deploys (a StatefulSet pod's name, a server's hostname): a name that changes at every deploy would leave checks behind that nothing reports to, and they would go down. Without it, the listed jobs are watched as shared, with a warning. When you remove an instance for good, delete its checks.

Rules it will not break

These are the reason the library is safe to put in a production application:

  • It never fails your job. Every network or HTTP error is swallowed and logged at WARNING. Your task runs exactly once, and its result and its exception are untouched.
  • It never blocks your job. Sending a heartbeat is a queue append handled by a daemon thread. An unreachable SilenceWatch costs your job nothing.
  • It is bounded. The queue holds at most queue_capacity heartbeats; past that the oldest are dropped, because the freshest state is the one worth reporting. Warnings are limited to one a minute so an outage cannot flood your logs.
  • It degrades silently. No API key, no network, no server: the application starts and runs exactly as it would without the library. A process that started while SilenceWatch was unreachable declares itself at its first heartbeat, at most once a minute.
  • It survives a fork. Celery's prefork pool and gunicorn fork after the library started; each child starts its own queue and thread.
  • enabled=False removes the mechanism entirely: no discovery, no hooks, no threads.
  • No dependency. The standard library only. celery, django-celery-beat and apscheduler are extras you already have.

Notes and limits

  • Celery — a task scheduled by several beat entries is declared from the one that fires most often. A manual .delay() of a scheduled task also sends a heartbeat, since a worker cannot tell it from a scheduled one; do not rely on a task being called by hand for the check to stay green. Solar schedules are not read. A crontab that restricts both the day of the month and the day of the week fires when both match in Celery and when either does in cron; the log says so.
  • django-celery-beat — one-off and clocked tasks run once and are not watched; disabled ones are left out (flagged orphaned if they were declared). A task in both beat_schedule and the database is one check, declared from the schedule that fires most often.
  • APScheduler — version 3 only (4 has another API). A job's duration includes any time it waited for an executor. One-off date triggers, combined and/or triggers and the week, year and "third friday" cron fields cannot be expressed and are skipped, with a warning. Jobs added or removed after the scheduler started are declared again two seconds later.
  • Sub-30-second jobs are declared with a 30-second period, the shortest the server accepts, and a warning names them.
  • Cron expressions the server cannot evaluate (Quartz's W) are skipped with a warning rather than failing the whole declaration.

Adding an integration

The package is organised so the next scheduler (Django, RQ, Dramatiq, a cron wrapper…) is one module:

src/silencewatch/
  config.py          settings, from keywords and SILENCEWATCH_* variables
  model.py           DiscoveredJob: what an integration reports
  client.py          the HTTP calls (declaration, heartbeat), standard library only
  heartbeat.py       the bounded queue and the thread, fork-safe
  monitor.py         one per process: declares everything in one request, sends the runs
  cron.py            the cron dialect the server reads, and helpers to write one
  integrations/
    base.py          the contract an integration follows
    celery.py
    django_celery_beat.py   the database schedules the Celery integration also reads
    apscheduler.py   ← a new scheduler goes here, next to these

An integration is a class with a name, a discover() that returns the jobs as DiscoveredJobs, and an install(monitor) that hooks the scheduler: it calls monitor.declare(self, jobs) when the scheduler is ready and monitor.started, succeeded or failed around each run. Add an instrument(...) function that creates it and calls monitor.attach(...), tests next to the others, and the README row above. Nothing else changes.

Development

pip install -e ".[celery,django-celery-beat,apscheduler]" -r requirements.txt   # Python 3.10+ for the lint tools
ruff check . && mypy && pytest

The tests start a small stand-in for SilenceWatch, so the real HTTP code runs.

Metadata

Release files for silencewatch 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for silencewatch 0.2.0
File Size Uploaded Provenance Actions
silencewatch-0.2.0.tar.gz 36.4 kB With provenance Details for silencewatch-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for silencewatch 0.2.0
File Interpreter ABI Platform Actions
silencewatch-0.2.0-py3-none-any.whl Python 3 none any Details for silencewatch-0.2.0-py3-none-any.whl

Total release size: 69.9 kB

Release files / silencewatch-0.2.0.tar.gz

Download URL silencewatch-0.2.0.tar.gz
Size 36.4 kB
Tags Source
SHA-256 checksum
How to use checksums
6592d25f0f6dfb0cfe1a5f80e093c0cffefff42a704146addcaa9554c14a690f
BLAKE2b-256 checksum
How to use checksums
2f416eca8755f989723544961c8eef691ba341e94a37a5723f2954030e3bd7bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.

Transparency log

Release files / silencewatch-0.2.0-py3-none-any.whl

Download URL silencewatch-0.2.0-py3-none-any.whl
Size 33.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
46e67e1c3e7389317cd38ba65206bb475056fe6fe28ba4dc69504a15872c4af2
BLAKE2b-256 checksum
How to use checksums
fe0db19f615e38932762b9d511264b3b6c1e2669c73c02567bdec8c69cf13a25
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.

Transparency log

Security for silencewatch 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for silencewatch-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page