Skip to main content

cyberrakshak-monitor

Cyber Rakshak error monitoring for Python 3.9+: what goes wrong in your program lands on your site's Errors page in the Cyber Rakshak console, scrubbed of secrets before it leaves. One module, standard library only, no dependencies.

What it catches

  • An exception that ends the program (sys.excepthook) and one that ends a thread (threading.excepthook). The hooks that were there before still run, so tracebacks print as they did.
  • ERROR log records, with LoggingHandler (with their traceback, if any).
  • Anything you report yourself: capture_exception() and capture_message(). Django and Flask need two lines each (below).

Sending happens on a background thread; at exit, what is still waiting gets at most 2 s.

Install

pip install cyberrakshak-monitor

Use

import logging, os
import cyberrakshak_monitor as monitor
monitor.init(key=os.environ["CR_MONITOR_KEY"], release="2026.11.21", environment="production")
logging.getLogger().addHandler(monitor.LoggingHandler())     # every ERROR record
monitor.capture_exception(exc, route="nightly-import", context={"batch": 42})

The key is your site's app key (crk_…), made on the site's Security scan tab: under Apps, servers and scripts, press Make an app key.

Django (settings.py, or an AppConfig.ready()):

from django.core.signals import got_request_exception
got_request_exception.connect(lambda sender, request=None, **kw: monitor.capture_exception(
    route=request.resolver_match.route if request is not None and request.resolver_match else None), weak=False)

Flask:

from flask import got_request_exception, request
got_request_exception.connect(lambda sender, exception, **kw: monitor.capture_exception(
    exception, route=request.url_rule.rule if request.url_rule else None), weak=False)

Options (init(...))

Option Meaning
key Your site's app key, crk_ and 32 letters or digits. Required; with no valid key the library does nothing.
endpoint Where reports go. Default https://app.cyberrakshak.ai/api/v1/app-reports.
release Your version or build (A-Z a-z 0-9 . _ + -, at most 60), so a problem shows the release it started in.
environment production, staging… (a-z 0-9 _ -, at most 30).
enabled False sends nothing (default True).
sample_rate 0 to 1: the share of problems sent (default 1, all).
before_send Gets each problem (a dict), already scrubbed; return it (changed if you like) or None to drop it.
debug Says on standard error what the library does and why something was not sent. The key is never printed.
context Values sent with every problem: at most 20, strings (300 characters), numbers, True/False.
scrub_names Names of your own whose values are removed, like password=: whole words, A-Z a-z 0-9 _ . -, at most 50. Only adds to the built-in rules.
scrub_patterns Regular expressions of your own (compiled, or strings): what they match becomes [removed]. At most 20; one that does not compile, or matches an empty text, is left out. Only adds to the built-in rules.
platform server (the default), script, desktop, mobile or other.
capture_uncaught Report exceptions that end the program or a thread (default True).

Functions: init(...), capture_exception(exc=None, route=None, context=None, level="error") (no argument: the exception being handled now), capture_message(text, level="warning", route=None, context=None), flush(timeout=2) (True when nothing is left waiting), scrub(text) (shows what a text would become), close(), and LoggingHandler(level=logging.ERROR).

What is sent, and what never is

Sent, per problem: its kind (exception, crash, log message), its message, its traceback (file, line and function; never local variables or argument values), the route or command (never its query string), the level, how many times it happened and when last; with each request: the library's name and version, python and its version, your release and environment.

Never sent: request or response bodies, headers, cookies, sessions, form fields, environment variables, local variables.

Scrubbed before anything leaves: query strings; Bearer/Basic values; the value after password, secret, token, api_key and the like; JSON Web Tokens; keys that say what they are (crk_, sk_live_, ghp_, AKIA…); email addresses; IBANs (mod-97 checked); card numbers (Luhn-checked); the value after pin, otp, cvv, iban, sort_code, card_number, account_number, cookie, signature, authorization and the like, as whole words only (company: and spinning: stay); long hex and random-looking runs. They become [removed], [token], [email], [iban] or [card], and a context entry whose name is one of these names is sent as [removed]. scrub_names and scrub_patterns add names and patterns of your own; nothing switches the built-in rules off. The console scrubs everything again when it arrives.

At most 10 problems go per request, each request under 64 KB; repeats of one problem are counted, not resent; a request takes at most 5 s; 429 and 5xx answers are retried later (never before Retry-After). Nothing in the library raises into your code. After os.fork() the child starts its own sending thread.

Full documentation, the same library for other platforms, and every file's SHA-256: https://app.cyberrakshak.ai/sdk/README.md

Development

python -m unittest discover -s tests -v          # the module in src/, against tests/fake-server.mjs (needs Node.js 18+)
python -m build                                  # dist/: the wheel and the sdist
CR_TEST_INSTALLED=1 python -m unittest discover -s tests -v   # the same tests on the installed wheel

The fake server listens on 127.0.0.1 only: no test talks to a real Cyber Rakshak host. src/cyberrakshak_monitor.py, LICENSE and the two test fixtures are byte for byte the ones served at https://app.cyberrakshak.ai/sdk/ and are not edited here: they are changed in the Cyber Rakshak console's repository and copied by its scripts/sdk-packages.mjs (whose --check also checks that version in pyproject.toml is the library's).

For maintainers

Publishing is by tag, through PyPI's trusted publishing (.github/workflows/publish.yml, pypa/gh-action-pypi-publish with id-token: write in the environment pypi): no PyPI token is stored anywhere. A release: copy the new module in, set version in pyproject.toml, add the CHANGELOG entry, commit, tag vX.Y.Z, push the tag.

Before the first tag, the PyPI account that will own the project adds a pending publisher (pypi.org → Your account → Publishing → Add a new pending publisher → GitHub): PyPI project name cyberrakshak-monitor, owner LaabamOne-Business-Solutions-Pvt-Ltd, repository name cyberrakshak-monitor-python, workflow name publish.yml, environment name pypi. The first publish then creates the project. In this repository's GitHub settings, the environment pypi can require a reviewer's approval before each publish.

Licence

MIT. Copyright (c) 2026 Laabam One Business Solutions (OPC) Private Limited. See LICENSE.

Metadata

Release files for cyberrakshak-monitor 1.1.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 cyberrakshak-monitor 1.1.0
File Size Uploaded Provenance Actions
cyberrakshak_monitor-1.1.0.tar.gz 26.9 kB With provenance Details for cyberrakshak_monitor-1.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cyberrakshak-monitor 1.1.0
File Interpreter ABI Platform Actions
cyberrakshak_monitor-1.1.0-py3-none-any.whl Python 3 none any Details for cyberrakshak_monitor-1.1.0-py3-none-any.whl

Total release size: 43.6 kB

Release files / cyberrakshak_monitor-1.1.0.tar.gz

Download URL cyberrakshak_monitor-1.1.0.tar.gz
Size 26.9 kB
Tags Source
SHA-256 checksum
How to use checksums
14546e72f8461bb1b000387e3a4c944d2ac6c100c7abc378ed24e0405d97d7e1
BLAKE2b-256 checksum
How to use checksums
d27c71b27bc527d1209080d38a75b9daaec2e568b27b7812a90f1ab339f207d9
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 Nov 21, 2026.

Transparency log

Release files / cyberrakshak_monitor-1.1.0-py3-none-any.whl

Download URL cyberrakshak_monitor-1.1.0-py3-none-any.whl
Size 16.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bc45148d25a44457a9712e1174ab1771e552576d2e45a504d7263572fb2778c2
BLAKE2b-256 checksum
How to use checksums
5858bc57cb22188850f5df5d4b637e6e8a212473405d3fad028af59dc927a161
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 Nov 21, 2026.

Transparency log

Security for cyberrakshak-monitor 1.1.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 cyberrakshak_monitor-1.1.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 Nov 21, 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.

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files Full provenance

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