Skip to main content

No project description provided

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

abs_utils-0.1.6.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

abs_utils-0.1.6-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file abs_utils-0.1.6.tar.gz.

File metadata

  • Download URL: abs_utils-0.1.6.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.13.3 Darwin/23.6.0

File hashes

Hashes for abs_utils-0.1.6.tar.gz
Algorithm Hash digest
SHA256 3fa5d8345019680f65e836988c043f3398b4b299a853c0d5dca804bb5fd0c6a8
MD5 28f7d5ffb66d73c7b69e77c2709ed961
BLAKE2b-256 aaecaef197a714641a06017d9cecee8e76c8cbe14a75904655416d515e44311f

See more details on using hashes here.

File details

Details for the file abs_utils-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: abs_utils-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.13.3 Darwin/23.6.0

File hashes

Hashes for abs_utils-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 ca1dc488623e3788b29fa118ed1c260807b210d2216d3f85b28cb861f2e8a6e1
MD5 51f6ca496d8bf059ed2b70216fbe1aaa
BLAKE2b-256 190b59950e16ae59a1ef4c38f4b37be6b9f5b745bb7fc912d8a4eeedd7eb8db9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page