Skip to main content

Backend.AI commons library

Project description

Backend.AI Common Package

Back to Backend.AI Architecture

PyPI release version Supported Python versions Gitter

Overview

The Backend.AI Common package provides utilities, infrastructure, and shared components used across all Backend.AI components (Manager, Agent, Storage Proxy, Webserver, App Proxy, etc.).

Package Structure

Entry Point System

Core event-based communication and asynchronous task processing framework for Backend.AI.

  • events/ - Event Dispatcher System

    • Asynchronous event-based communication between components
    • Broadcast and Anycast event type support
    • Message queue-based event delivery
    • Event handler registration and routing
  • bgtask/ - Background Task Handler System

    • Process long-running tasks asynchronously
    • Issue Task IDs and track tasks
    • Progress monitoring and Heartbeat
    • Notify via event publishing upon completion

Infrastructure Components

Client and abstraction layer for integration with external services and systems.

  • clients/ - External service client wrappers

    • Agent client (ZeroMQ RPC)
    • Storage Proxy client (HTTP)
    • Valkey/Redis client
    • etcd client
  • message_queue/ - Message queue interface and implementation

    • Provide message publish/subscribe interface
    • Currently implemented based on Redis Streams
    • Consumer Group management
    • Future support for other message queue systems planned
  • service_discovery/ - Service registration and integration

    • etcd-based service registration and discovery
    • Provide service information for Prometheus metrics collection
    • Automatic health check and update
    • Future expansion of additional service discovery features planned
  • resilience/ - Inter-layer communication resilience patterns

    • Generalize request processing between layers
    • Retry, Timeout, Circuit Breaker
    • Automatic metric collection
    • Fallback support

Data and Types

Common structures for data exchange and type definitions between components.

  • dto/ - Data Transfer Objects (for inter-component communication)

    • Data structures used for inter-component communication
    • Request/Response models
    • Event payloads
    • Recommended to use Pydantic-based
  • types.py - Common type definitions (for internal logic)

    • Domain types used within components (SessionId, AgentId, AccessKey, etc.)
    • Shared Enum types
    • Common constants
    • Mainly used in internal business logic

Utilities

Utility modules for development convenience and common functionality.

  • metrics/ - Metrics collection and Prometheus integration

    • Metric observer pattern
    • Prometheus metric types (Counter, Gauge, Histogram)
    • HTTP metrics middleware
  • auth/ - Authentication utilities

    • Authentication between Webserver (Gateway) and Manager
    • JWT token generation/verification
    • Signature generation/verification
    • API Key management
  • web/ - Web utilities

    • HTTP helper functions
    • CORS configuration
    • Request/response processing
  • middlewares/ - Common middlewares

    • Commonly used across all components
    • Authentication middleware
    • Logging middleware
    • Error handling middleware
  • configs/ - Configuration management utilities

    • Configuration processing commonly used internally
    • Configuration file parsing (TOML, YAML)
    • Environment variable processing
    • Configuration validation

Other Components

  • contexts/ - Context management utilities

    • ContextVar-based request and user tracking
    • Current request ID tracking
    • Current user information management
    • Context propagation
  • data/ - Common data utilities

    • Data-based value processing used in internal logic
    • Data transformation and validation
    • Common data type handling
  • exception.py - Common exception classes

    • Base exceptions for all Backend.AI services
    • Exception definitions must inherit from BackendAIError
    • Domain-specific exception classes
    • Communicate error situations externally
  • utils.py - Other utility functions

    • String processing
    • Time conversion
    • Other helper functions

Installation

$ pip install backend.ai-common

For development

$ pip install -U pip setuptools
$ pip install -U -r requirements/dev.txt

Running test suite

$ python -m pytest

With the default halfstack setup, you may need to set the environment variable BACKEND_ETCD_ADDR to specify the non-standard etcd service port (e.g., localhost:8110).

The tests for common.redis module requires availability of local TCP ports 16379, 16380, 16381, 26379, 26380, and 26381 to launch a temporary Redis sentinel cluster via docker compose.

In macOS, they require a local redis-server executable to be installed, preferably via brew, because docker compose in macOS does not support host-mode networking and Redis cannot be configured to use different self IP addresses to announce to the cluster nodes and clients.

Related Documentation

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

backend_ai_common-26.4.4rc6.tar.gz (526.8 kB view details)

Uploaded Source

Built Distribution

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

backend_ai_common-26.4.4rc6-py3-none-any.whl (817.9 kB view details)

Uploaded Python 3

File details

Details for the file backend_ai_common-26.4.4rc6.tar.gz.

File metadata

  • Download URL: backend_ai_common-26.4.4rc6.tar.gz
  • Upload date:
  • Size: 526.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for backend_ai_common-26.4.4rc6.tar.gz
Algorithm Hash digest
SHA256 d13f26a3a8657fcd5235aedb411649a58f02471cec5d11e0f331e8f3e67f3ee9
MD5 c84357a348548a69a9342845fb2d0c6c
BLAKE2b-256 ab6b073953dce846ac0b43f0be6e236dc077477a1f4b249ff920b93d0dfd54f3

See more details on using hashes here.

File details

Details for the file backend_ai_common-26.4.4rc6-py3-none-any.whl.

File metadata

File hashes

Hashes for backend_ai_common-26.4.4rc6-py3-none-any.whl
Algorithm Hash digest
SHA256 548a7e2b116bfa70780cbbfb33d01dea75631995837818c7258ee95a1d56b094
MD5 15260f9376ca75facdd580c27b7884a9
BLAKE2b-256 c624a1c1ecdabcada4bfeb813ee677cbd4ab10fe7f7d1ed7f8093810722ebfa2

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