Skip to content

Protocols

provide.foundation.hub.protocols

TODO: Add module docstring.

Classes

AsyncContextResource

AsyncContextResource(resource_factory: Any)

Bases: AbstractAsyncContextManager[Any]

Base class for async context-managed resources.

Initialize with a resource factory.

Source code in provide/foundation/hub/protocols.py
def __init__(self, resource_factory: Any) -> None:
    """Initialize with a resource factory."""
    self._resource_factory = resource_factory
    self._resource: Any = None
Functions
__aenter__ async
__aenter__() -> Any

Enter async context and acquire resource.

Source code in provide/foundation/hub/protocols.py
async def __aenter__(self) -> Any:
    """Enter async context and acquire resource."""
    self._resource = await self._resource_factory()
    return self._resource
__aexit__ async
__aexit__(exc_type: Any, exc_val: Any, exc_tb: Any) -> None

Exit async context and cleanup resource.

Source code in provide/foundation/hub/protocols.py
async def __aexit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None:
    """Exit async context and cleanup resource."""
    if self._resource and hasattr(self._resource, "dispose_async"):
        await self._resource.dispose_async()
    elif self._resource and hasattr(self._resource, "dispose"):
        self._resource.dispose()

AsyncDisposable

Bases: Protocol

Protocol for components that require async cleanup.

Functions
dispose_async async
dispose_async() -> None

Dispose of the component and clean up resources asynchronously.

Source code in provide/foundation/hub/protocols.py
async def dispose_async(self) -> None:
    """Dispose of the component and clean up resources asynchronously."""
    ...

AsyncInitializable

Bases: Protocol

Protocol for components that support async lazy initialization.

Functions
initialize_async async
initialize_async() -> Any

Initialize the component asynchronously.

Source code in provide/foundation/hub/protocols.py
async def initialize_async(self) -> Any:
    """Initialize the component asynchronously."""
    ...

AsyncResourceManager

Bases: ABC

Abstract base class for async resource managers.

Functions
acquire_resource_async abstractmethod async
acquire_resource_async(resource_id: str) -> Any

Acquire a resource by ID asynchronously.

Source code in provide/foundation/hub/protocols.py
@abstractmethod
async def acquire_resource_async(self, resource_id: str) -> Any:
    """Acquire a resource by ID asynchronously."""
    pass
cleanup_all_async abstractmethod async
cleanup_all_async() -> None

Clean up all managed resources asynchronously.

Source code in provide/foundation/hub/protocols.py
@abstractmethod
async def cleanup_all_async(self) -> None:
    """Clean up all managed resources asynchronously."""
    pass
release_resource_async abstractmethod async
release_resource_async(resource_id: str) -> None

Release a resource by ID asynchronously.

Source code in provide/foundation/hub/protocols.py
@abstractmethod
async def release_resource_async(self, resource_id: str) -> None:
    """Release a resource by ID asynchronously."""
    pass

Disposable

Bases: Protocol

Protocol for components that require cleanup.

Functions
dispose
dispose() -> None

Dispose of the component and clean up resources.

Source code in provide/foundation/hub/protocols.py
def dispose(self) -> None:
    """Dispose of the component and clean up resources."""
    ...

HealthCheckable

Bases: Protocol

Protocol for components that support health checks.

Functions
health_check
health_check() -> dict[str, Any]

Check component health status.

Source code in provide/foundation/hub/protocols.py
def health_check(self) -> dict[str, Any]:
    """Check component health status."""
    ...

Initializable

Bases: Protocol

Protocol for components that support lazy initialization.

Functions
initialize
initialize() -> Any

Initialize the component.

Source code in provide/foundation/hub/protocols.py
def initialize(self) -> Any:
    """Initialize the component."""
    ...

ResourceManager

Bases: ABC

Abstract base class for resource managers.

Functions
acquire_resource abstractmethod
acquire_resource(resource_id: str) -> Any

Acquire a resource by ID.

Source code in provide/foundation/hub/protocols.py
@abstractmethod
def acquire_resource(self, resource_id: str) -> Any:
    """Acquire a resource by ID."""
    pass
cleanup_all abstractmethod
cleanup_all() -> None

Clean up all managed resources.

Source code in provide/foundation/hub/protocols.py
@abstractmethod
def cleanup_all(self) -> None:
    """Clean up all managed resources."""
    pass
release_resource abstractmethod
release_resource(resource_id: str) -> None

Release a resource by ID.

Source code in provide/foundation/hub/protocols.py
@abstractmethod
def release_resource(self, resource_id: str) -> None:
    """Release a resource by ID."""
    pass