Skip to main content

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:

  1. Automatically captures the entity name from the route parameters
  2. Extracts user information from the request state
  3. Generates a unique event ID for each event
  4. Handles errors gracefully with logging
  5. Works seamlessly with FastAPI dependency injection

Dependencies

  • Python 3.x
  • azure-servicebus
  • fastapi
  • logging
  • dependency-injector

Contributing

When adding new utilities to this package:

  1. Place new modules in the appropriate subdirectory under abs_utils/
  2. Add proper documentation and type hints
  3. Update this README with usage examples
  4. 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)

Source distribution for abs-utils 0.5.4
File Size Uploaded
abs_utils-0.5.4.tar.gz 8.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for abs-utils 0.5.4
File Interpreter ABI Platform
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

Release history Release notifications | RSS feed

This release

0.5.4 This release

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.24

2 release files

0.1.23

2 release files

0.1.22

2 release files

0.1.21

2 release files

0.1.20

2 release files

0.1.18

2 release files

0.1.17

2 release files

0.1.16

2 release files

0.1.15

2 release files

0.1.14

2 release files

0.1.13

2 release files

0.1.12

2 release files

0.1.11

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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