Evolvishub Notification Adapter
A flexible notification system adapter for Evolvishub applications. This library provides a simple interface for managing notifications with SQLite backend storage.
About
This project is part of the Evolvis AI ecosystem, providing intelligent notification management capabilities for Evolvishub applications.
Author
Alban Maxhuni, PhD
Email: a.maxhuni@evolvis.ai
Features
- Async SQLite-based notification storage
- Support for different notification types (info, warning, error, success)
- Category-based notification organization
- Bulk notification operations
- Configurable through YAML or INI files
- Built-in logging system
- Easy to use async API
- Type hints for better IDE support
- Comprehensive test suite with pytest and pytest-asyncio
Installation
pip install evolvishub-notification-adapter
Quick Start
import asyncio
from evolvishub_notification_adapter import Notification, NotificationDB, Config, Category
async def main():
# Initialize with your application's configuration file
config = Config("/path/to/your/config.yaml") # or .ini file
# Use async context manager for proper resource management
async with NotificationDB(config) as db:
# Add a simple notification
notification_id = await db.add_notification("Hello, World!", "info")
# Add a notification with category and metadata
category_id = await db.add_category("updates", "System updates")
notification_id = await db.add_notification(
"New version available",
"info",
category_id=category_id,
metadata={"version": "1.2.0", "changes": ["Bug fixes", "New features"]}
)
# Get unread notifications
unread = await db.get_unread_notifications()
for notif in unread:
print(f"Unread: {notif.message}")
# Mark notifications as read
await db.mark_as_read(notification_id) # Single notification
await db.mark_many_as_read([1, 2, 3]) # Multiple notifications
# Get all notifications with filters
all_notifs = await db.get_all_notifications(
category_id=category_id,
notif_type="info",
limit=10,
offset=0
)
# Run the async main function
asyncio.run(main())
Advanced Usage
Working with Categories
async def manage_categories():
async with NotificationDB(config) as db:
# Add a new category
category_id = await db.add_category("alerts", "Important system alerts")
# Get all categories
categories = await db.get_categories()
for category in categories:
print(f"Category: {category.name} - {category.description}")
# Get notifications by category
category_notifs = await db.get_all_notifications(category_id=category_id)
# Run the async function
asyncio.run(manage_categories())
Bulk Operations
async def bulk_operations():
async with NotificationDB(config) as db:
# Add multiple notifications at once
notifications = [
{
"message": "System update available",
"type": "info",
"category_id": category_id,
"metadata": {"version": "1.2.0"}
},
{
"message": "Disk space low",
"type": "warning",
"category_id": category_id,
"metadata": {"space_left": "500MB"}
}
]
notif_ids = await db.add_notifications(notifications)
# Mark multiple notifications as read
await db.mark_many_as_read(notif_ids)
# Run the async function
asyncio.run(bulk_operations())
Working with Metadata
async def metadata_example():
async with NotificationDB(config) as db:
# Add notification with metadata
notification_id = await db.add_notification(
"User action required",
"warning",
metadata={
"user_id": 123,
"action": "verify_email",
"expires_at": "2024-03-20T00:00:00Z"
}
)
# Get notification and access metadata
notifications = await db.get_all_notifications()
notification = notifications[0]
user_id = notification.metadata.get("user_id")
# Run the async function
asyncio.run(metadata_example())
Configuration
The library requires a configuration file to be provided by your application. You can use either YAML or INI format.
YAML Configuration Example
Create a config.yaml file in your application:
database:
path: notifications.db
directory: ./data
logging:
enabled: true
level: INFO
INI Configuration Example
Create a config.ini file in your application:
[database]
path = notifications.db
directory = ./data
[logging]
enabled = true
level = INFO
Configuration Options
database.path: Name of the SQLite database filedatabase.directory: Directory where the database file will be storedlogging.enabled: Enable/disable logginglogging.level: Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
Testing
The library includes a comprehensive test suite using pytest and pytest-asyncio. The tests cover:
- Basic notification operations (create, read, update)
- Category management
- Bulk operations
- Error handling
- Database state management
- Async context manager functionality
To run the tests:
# Install test dependencies
pip install -e ".[test]"
# Run all tests
pytest
# Run tests with coverage
pytest --cov=evolvishub_notification_adapter
# Run specific test file
pytest tests/test_notification.py
# Run tests with verbose output
pytest -v
Requirements
- Python 3.7 or higher
- aiosqlite 0.19.0 or higher
- PyYAML 6.0.1 or higher
- pytest 7.0.0 or higher (for testing)
- pytest-asyncio 0.21.0 or higher (for testing)
Development
To set up the development environment:
# Clone the repository
git clone https://github.com/yourusername/evolvishub-notification-adapter.git
cd evolvishub-notification-adapter
# Create and activate virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install development dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Run linting
flake8
black .
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests and ensure they pass
- Submit a pull request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for evolvishub-notification-adapter 0.1.4
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 | Actions |
|---|---|---|---|---|
| evolvishub_notification_adapter-0.1.4.tar.gz | 17.0 kB | Without provenance | Details for evolvishub_notification_adapter-0.1.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| evolvishub_notification_adapter-0.1.4-py3-none-any.whl | Python 3 | none | any | Details for evolvishub_notification_adapter-0.1.4-py3-none-any.whl |
Total release size: 30.9 kB
Release files / evolvishub_notification_adapter-0.1.4.tar.gz
| Download URL | evolvishub_notification_adapter-0.1.4.tar.gz |
|---|---|
| Size | 17.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
79fdce06f74b87957462545d6705fd67125f97ab5cc3f7c66490f9fd2b9ff794
|
|
BLAKE2b-256 checksum How to use checksums |
e23c76a7d80b576e60d2b5e4e8bd06983b01b6e5734e9d40d179099331920d7b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.2
|
Release files / evolvishub_notification_adapter-0.1.4-py3-none-any.whl
| Download URL | evolvishub_notification_adapter-0.1.4-py3-none-any.whl |
|---|---|
| Size | 13.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6effa03798e506c47c270ef2b2009de33670ebac2f2d645794ce439da1166fb6
|
|
BLAKE2b-256 checksum How to use checksums |
991207d5b71744a6a36269cc38032914697210667eb1242636d5cbdf18107744
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.2
|
Security for evolvishub-notification-adapter 0.1.4
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.