Utils Package
This package provides utility functions and classes for common operations in the application, including logging and Azure Service Bus integration.
Installation
The package is managed using Poetry. To install dependencies:
poetry install
Features
Logger
A simple logging utility that provides a standardized way to set up logging across the application.
Usage
from abs_utils.logger import setup_logger
# Create a logger instance
logger = setup_logger("my_module")
# Use the logger
logger.info("This is an info message")
logger.error("This is an error message")
Azure Service Bus Integration
Provides functionality to interact with Azure Service Bus for message queuing and event handling.
AzureServiceBus Class
A wrapper class for Azure Service Bus operations.
from abs_utils.azure_service_bus import AzureServiceBus
# Initialize the service bus client
service_bus = AzureServiceBus(
connection_string="your_connection_string",
queue_name="your_queue_name"
)
# Send a message
await service_bus.send({"key": "value"})
Event Decorator
A decorator that automatically sends events to Azure Service Bus after function execution. This is particularly useful for tracking entity operations in your application.
from fastapi import APIRouter, Depends, Request
from dependency_injector.wiring import inject, Provide
from abs_utils.azure_service_bus import azure_event_decorator, AzureServiceBus
router = APIRouter()
@router.post("/{entity_name}/records")
@inject
@azure_event_decorator(event_type="record_created")
async def create_record(
entity_name: str,
data: dict,
request: Request,
azure_service_bus: AzureServiceBus = Depends(Provide[Container.azure_service_bus]),
service: YourService = Depends(Provide[Container.yourService])
):
# Your function logic here
return await service.create(data, entity_name)
The decorator automatically creates and sends an event payload with the following structure:
{
"event_id": "uuid",
"event_type": "record_created",
"entity_name": "your_entity_name",
"entity_id": "record_id",
"payload": {
// Your data payload
},
"user": {
"id": "user_id",
"uuid": "user_uuid",
"email": "user_email",
"name": "user_name"
}
}
Key features of the decorator:
- Automatically captures the entity name from the route parameters
- Extracts user information from the request state
- Generates a unique event ID for each event
- Handles errors gracefully with logging
- Works seamlessly with FastAPI dependency injection
Dependencies
- Python 3.x
- azure-servicebus
- fastapi
- logging
- dependency-injector
Contributing
When adding new utilities to this package:
- Place new modules in the appropriate subdirectory under
abs_utils/ - Add proper documentation and type hints
- Update this README with usage examples
- Add tests for new functionality
Metadata
Release files for abs-utils 0.5.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 | |
|---|---|---|---|
| abs_utils-0.5.4.tar.gz | 8.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| abs_utils-0.5.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 20.6 kB
Release files / abs_utils-0.5.4.tar.gz
| Download URL | abs_utils-0.5.4.tar.gz |
|---|---|
| Size | 8.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6ff44de242e50ddc5d700bdcfc2f130ca8eabc82f7dd01708df09e6118881212
|
|
BLAKE2b-256 checksum How to use checksums |
46a8be57e9dcaf4d77d2a28146b2fbbbd619834aaba4afb91b60a440a8974d35
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.4 CPython/3.13.5 Darwin/25.5.0
|
Release files / abs_utils-0.5.4-py3-none-any.whl
| Download URL | abs_utils-0.5.4-py3-none-any.whl |
|---|---|
| Size | 12.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b6437cb3325b8fc5fd55cf6ebe6fee2ce1000c5b344d5adf23fefb8c40aac1b2
|
|
BLAKE2b-256 checksum How to use checksums |
945113674281fb7ad7da7d2879ba84a43024f76b540c97cc3cab96a694bd8edc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.4 CPython/3.13.5 Darwin/25.5.0
|