Python bindings for SentryStr - a decentralized error tracking system using Nostr
Project description
SentryStr Python Bindings
Python bindings for SentryStr - a decentralized error tracking and alerting system using Nostr.
Installation
pip install sentrystr
Quick Start
import sentrystr
# Basic setup
config = sentrystr.Config("your_private_key", ["wss://relay.damus.io"])
client = sentrystr.NostrSentryClient(config)
# Send events
event = sentrystr.Event().with_message("Something went wrong").with_level(sentrystr.Level("error"))
client.capture_event_sync(event)
# Or use convenience methods
client.capture_error_sync("Database connection failed")
client.capture_message_sync("System started")
Async Support
import asyncio
import sentrystr
async def main():
config = sentrystr.Config("your_private_key", ["wss://relay.damus.io"])
client = await sentrystr.NostrSentryClient.create(config)
await client.capture_error("Async error occurred")
asyncio.run(main())
Advanced Usage
Creating Custom Events
import sentrystr
# Create a detailed event
event = (sentrystr.Event()
.with_message("User authentication failed")
.with_level(sentrystr.Level("error"))
.with_logger("auth.login")
.with_tag("user_id", "12345")
.with_tag("ip_address", "192.168.1.1"))
# Add user information
user = (sentrystr.User()
.with_id("user123")
.with_email("user@example.com")
.with_username("john_doe"))
event = event.with_user(user)
# Add request information
request = (sentrystr.Request()
.with_url("https://example.com/login")
.with_method("POST")
.with_query_string("redirect=/dashboard"))
event = event.with_request(request)
client.capture_event_sync(event)
Exception Handling
import sentrystr
try:
# Some code that might raise an exception
raise ValueError("Something went wrong")
except Exception as e:
# Create exception object
exception = sentrystr.Exception(type(e).__name__, str(e))
# Create event with exception
event = sentrystr.Event().with_exception(exception)
client.capture_event_sync(event)
Configuration Options
import sentrystr
config = sentrystr.Config("your_private_key", ["wss://relay.damus.io"])
# Set optional configuration
config.set_platform("python")
config.set_server_name("web-server-01")
config.set_release("1.0.0")
config.set_environment("production")
# Add encryption (optional)
config.with_encryption_keys("public_key", "private_key")
config.with_encryption_version("nip44")
client = sentrystr.NostrSentryClient(config)
Configuration from Environment
You can also configure SentryStr using environment variables:
export SENTRYSTR_PRIVATE_KEY="your_private_key"
export SENTRYSTR_RELAYS="wss://relay.damus.io,wss://relay.nostr.band"
export SENTRYSTR_PLATFORM="python"
export SENTRYSTR_SERVER_NAME="web-server-01"
export SENTRYSTR_RELEASE="1.0.0"
export SENTRYSTR_ENVIRONMENT="production"
import sentrystr
# Load configuration from environment
config = sentrystr.Config.from_env()
client = sentrystr.NostrSentryClient(config)
API Reference
NostrSentryClient
NostrSentryClient(config)- Create a new clientNostrSentryClient.create(config)- Async factory methodcapture_event(event)- Async method to capture an eventcapture_message(message)- Async method to capture a messagecapture_error(error)- Async method to capture an errorcapture_exception(exception, message=None)- Async method to capture an exceptioncapture_event_sync(event)- Sync method to capture an eventcapture_message_sync(message)- Sync method to capture a messagecapture_error_sync(error)- Sync method to capture an errorcapture_exception_sync(exception, message=None)- Sync method to capture an exception
Config
Config(private_key, relays)- Create a new configurationConfig.from_env()- Load configuration from environment variables- Various setters for platform, server_name, release, environment
with_encryption_keys(public_key, private_key)- Add encryptionwith_encryption_version(version)- Set encryption version ("nip04" or "nip44")
Event
Event()- Create a new eventwith_message(message)- Set the messagewith_level(level)- Set the levelwith_logger(logger)- Set the loggerwith_user(user)- Set user informationwith_request(request)- Set request informationwith_exception(exception)- Set exception informationwith_tag(key, value)- Add a tagwith_extra(key, value)- Add extra data
Level
Level(level_string)- Create a level ("debug", "info", "warning", "error", "fatal")
Exception, User, Request, Frame, Stacktrace
Various data structures for capturing detailed error information.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sentrystr-0.1.2.tar.gz.
File metadata
- Download URL: sentrystr-0.1.2.tar.gz
- Upload date:
- Size: 42.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c99093b8ffde68db692e964041513ec327b5f51f2f71b93be01547aadff1008
|
|
| MD5 |
b0ce51ac062eef2be58b35acf4592168
|
|
| BLAKE2b-256 |
3e103369faff36dc6e452d16d48acbe4fddb9d9f08c07a3e96de37a5c95c8029
|
File details
Details for the file sentrystr-0.1.2-cp39-cp39-macosx_11_0_arm64.whl.
File metadata
- Download URL: sentrystr-0.1.2-cp39-cp39-macosx_11_0_arm64.whl
- Upload date:
- Size: 3.6 MB
- Tags: CPython 3.9, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7fa267c3a784d7ce1f54083082c4aca5aba35071fcad6f8e576db782e47ee735
|
|
| MD5 |
61ca3baef8a8b263d8b9435a7b31a8aa
|
|
| BLAKE2b-256 |
61e95709ed5b626f7efb38fa54e45b1e6310f6ef05aeebf771a21a5d5a9e1518
|