core-sentry
A thin Python wrapper around the Sentry SDK providing a decorator for automatic initialization and standalone functions for the full event lifecycle: initialization, exception capture, message capture, and flush.
Installation
pip install core-sentry
uv pip install core-sentry
Features
Decorator-based initialization: wrap any function with @with_sentry to initialize the SDK before it runs
Duplicate initialization guard: skips sentry_sdk.init if the client is already configured
Tag management: set global tags via SentryConfig and per-event tags via SentryRuntimeConfig
Exception capture: capture_exception sends errors with optional per-event tags and extra context using an isolated scope
Message capture: capture_message sends informational/warning events with configurable severity
Event flush: flush_sentry blocks until the event queue drains; essential for short-lived scripts and ETLs
Flexible decorator syntax: usable with or without parentheses
Fully typed: complete type annotations including Literal for severity levels
Quick Start
pip install core-sentry
pip install -e ".[dev]" # For development
Decorator usage
The with_sentry decorator initializes Sentry before the wrapped function runs. For long-running services the defaults are sufficient:
from core_sentry.base import SentryConfig
from core_sentry.decorators.base import with_sentry
@with_sentry(config=SentryConfig(
dsn="https://...",
env="production",
tags={"service": "my-api"},
))
def my_function():
return "Hello World"
For ETLs and short-lived scripts running in containers, enable capture_exceptions and flush to guarantee delivery even when atexit handlers are skipped (e.g. SIGKILL or OOM):
from core_sentry.base import SentryConfig
from core_sentry.decorators.base import SentryRuntimeConfig, with_sentry
@with_sentry(
config=SentryConfig(
dsn="https://...",
env="production",
tags={"service": "etl-pipeline", "version": "1.0.0"},
traces_sample_rate=0.5,
),
runtime_config=SentryRuntimeConfig(
capture_exceptions=True,
flush=True,
flush_timeout=5.0,
tags={"job": "daily-sync"},
extra={"rows_processed": 9999},
),
)
def run_etl():
pass
Standalone functions
Use the standalone API when you need explicit control over initialization, capture, and flush within a single process:
from core_sentry.base import (
SentryConfig,
init_sentry,
capture_exception,
capture_message,
flush_sentry,
)
init_sentry(SentryConfig(
dsn="https://...",
env="production",
tags={"service": "etl-pipeline"},
))
# Informational breadcrumb
capture_message("ETL job started", level="info", tags={"job": "daily-sync"})
# Recoverable error mid-job
try:
raise ValueError("Unexpected null value in column 'amount'")
except ValueError as exc:
capture_exception(
exc,
tags={"job": "daily-sync", "stage": "transform"},
extra={"row_index": 1042, "column": "amount"},
)
# Guarantee delivery before process exit
flushed = flush_sentry(timeout=5.0)
if not flushed:
print("WARNING: some Sentry events may not have been delivered.")
Development
# Create and activate virtual environment
virtualenv --python=python3.12 .venv
source .venv/bin/activate
# Install with dev dependencies
pip install -e ".[dev]"
# Run tests
python -m unittest discover -s tests -p "tests_*.py"
python manager.py run-tests
python manager.py run-coverage
# Lint and security scan
pylint core_sentry
bandit -r core_sentry
# Run across all supported Python versions
tox
Contributing
Contributions are welcome! Please:
Fork the repository
Create a feature branch
Write tests for new functionality
Ensure all tests pass: python -m unittest discover -s tests -p "tests_*.py"
Run linting: pylint core_sentry
Run security checks: bandit -r core_sentry
Submit a pull request
License
This project is licensed under the MIT License. See the LICENSE file for details.
Links
Support
For questions or support, please open an issue on GitLab or contact the maintainers.
Metadata
Release files for core-sentry 2.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| core_sentry-2.1.1.tar.gz | 11.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| core_sentry-2.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 21.7 kB
Release files / core_sentry-2.1.1.tar.gz
| Download URL | core_sentry-2.1.1.tar.gz |
|---|---|
| Size | 11.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3bf369eefe9d276bee4d8d30343e07d886855dec67bb6dadab8555364db71096
|
|
BLAKE2b-256 checksum How to use checksums |
c287c106d82d8416ffd95501f45d863bc6b1ab5a1e085137ff0e58875bfb2cbb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Release files / core_sentry-2.1.1-py3-none-any.whl
| Download URL | core_sentry-2.1.1-py3-none-any.whl |
|---|---|
| Size | 10.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f1cfcb7c417689fcbff15448f518f4255be9bd8c4bcb8a6f921b48ec5fdd636a
|
|
BLAKE2b-256 checksum How to use checksums |
f2623910a9535c64c309af8a4e6543637c2c9335c6a8934bfad3942baef2f585
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Security for core-sentry 2.1.1
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.