spakky¶
DI Container, AOP, 부트스트랩 — Spakky Framework의 핵심 패키지
Application¶
spakky.core.application.application
¶
Main application class for bootstrapping the Spakky framework.
This module provides the SpakkyApplication class which serves as the entry point for configuring and starting a Spakky application with DI/IoC and AOP support.
CannotDetermineScanPathError
¶
SpakkyApplication(application_context)
¶
Main application class for bootstrapping Spakky framework.
Provides a fluent API for configuring dependency injection, aspect-oriented programming, plugin loading, and component scanning.
Initialize the Spakky application.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
application_context
|
IApplicationContext
|
The application context to manage Pods. |
required |
Source code in core/spakky/src/spakky/core/application/application.py
container
property
¶
Get the IoC container.
Returns:
| Type | Description |
|---|---|
IContainer
|
The application's dependency injection container. |
application_context
property
¶
Get the application context.
Returns:
| Type | Description |
|---|---|
IApplicationContext
|
The application's context managing Pods and lifecycle. |
add(obj)
¶
Register a class or function in the application.
- If the object has a @Pod annotation, it is registered in the container.
- If the object has a @Tag annotation, the tag is registered in the tag registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
PodType
|
The class or function to register. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
Self for method chaining. |
Source code in core/spakky/src/spakky/core/application/application.py
scan(path=None, exclude=None)
¶
Scan a module for Pod-annotated classes and functions.
When path is None, automatically detects the caller's package and scans it. If the caller's package is not importable (e.g., in Docker environments where the application root is not in sys.path), the parent directory is automatically added to sys.path to enable package discovery.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Module | None
|
Module or package to scan. If None, scans the caller's package. |
None
|
exclude
|
set[Module] | None
|
Set of modules to exclude from scanning. |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
Self for method chaining. |
Raises:
| Type | Description |
|---|---|
CannotDetermineScanPathError
|
If path is None and cannot determine caller's package. |
Source code in core/spakky/src/spakky/core/application/application.py
load_plugins(include=None)
¶
Load plugins from entry points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
include
|
set[Plugin] | None
|
Optional set of plugins to load. If None, loads all available plugins. |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
Self for method chaining. |
Source code in core/spakky/src/spakky/core/application/application.py
start()
¶
Start the application by initializing all Pods and running post-processors.
Returns:
| Type | Description |
|---|---|
Self
|
Self for method chaining. |
stop()
¶
Stop the application and clean up resources.
Returns:
| Type | Description |
|---|---|
Self
|
Self for method chaining. |
options: show_root_heading: false
spakky.core.application.application_context
¶
CannotAssignSystemContextIDError
¶
Bases: Exception
Raised when attempting to override the CONTEXT_ID value.
ApplicationContext()
¶
Bases: IApplicationContext
Container managing Pod instances, dependencies, and application lifecycle.
ApplicationContext is responsible for: - Registering and instantiating Pods with dependency injection - Managing Pod scopes (SINGLETON, PROTOTYPE, CONTEXT) - Running post-processors on Pod instances - Coordinating service lifecycle (start/stop) - Managing async event loop for async services
Initialize application context.
Source code in core/spakky/src/spakky/core/application/application_context.py
__forward_type_map = {}
instance-attribute
¶
Map for resolving forward reference types.
__pods = {}
instance-attribute
¶
Registry of all Pods by name.
__tags = set()
instance-attribute
¶
Registry of all Tags.
__type_cache = {}
instance-attribute
¶
Cache mapping types to Pods for O(1) lookup.
__singleton_cache = {}
instance-attribute
¶
Cache of singleton-scoped Pod instances.
__context_cache = ContextVar(CONTEXT_SCOPE_CACHE)
instance-attribute
¶
Context-local cache for context-scoped Pods.
__post_processors = []
instance-attribute
¶
List of post-processors applied to Pod instances.
__services = []
instance-attribute
¶
List of synchronous services.
__async_services = []
instance-attribute
¶
List of asynchronous services.
__event_loop = None
instance-attribute
¶
Event loop for running async services.
__event_thread = None
instance-attribute
¶
Thread running the event loop.
__is_started = False
instance-attribute
¶
Whether the context has been started.
pods
property
¶
Get read-only view of all registered Pods.
Returns:
| Type | Description |
|---|---|
dict[str, Pod]
|
Read-only mapping proxy of Pod registry (O(1) operation). |
tags
property
¶
Get read-only view of all registered Tags.
Returns:
| Type | Description |
|---|---|
frozenset[Tag]
|
Read-only frozenset of Tag registry (O(1) operation). |
is_started
property
¶
Check if context has been started.
Returns:
| Type | Description |
|---|---|
bool
|
True if started. |
__resolve_candidate(type_, name, qualifiers)
¶
Resolve a Pod candidate matching type, name, and qualifiers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type_
|
type
|
The type to search for. |
required |
name
|
str | None
|
Optional name qualifier. |
required |
qualifiers
|
list[Qualifier]
|
List of qualifier annotations. |
required |
Returns:
| Type | Description |
|---|---|
Pod | None
|
Matching Pod or None if not found. |
Raises:
| Type | Description |
|---|---|
NoUniquePodError
|
If multiple Pods match without clear qualification. |
Source code in core/spakky/src/spakky/core/application/application_context.py
__instantiate_pod(pod, dependency_hierarchy)
¶
Instantiate a Pod with its dependencies recursively resolved.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pod
|
Pod
|
The Pod to instantiate. |
required |
dependency_hierarchy
|
tuple[type, ...]
|
Immutable tuple tracking dependency chain for cycle detection. |
required |
Returns:
| Type | Description |
|---|---|
object
|
The instantiated and post-processed Pod instance. |
Raises:
| Type | Description |
|---|---|
CircularDependencyGraphDetectedError
|
If circular dependency detected. |
Source code in core/spakky/src/spakky/core/application/application_context.py
__post_process_pod(pod)
¶
Apply all registered post-processors to a Pod instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pod
|
object
|
The Pod instance to process. |
required |
Returns:
| Type | Description |
|---|---|
object
|
The post-processed Pod instance. |
Source code in core/spakky/src/spakky/core/application/application_context.py
__register_post_processors()
¶
Register built-in and user-defined post-processors.
Registers post-processors in order: 1. ApplicationContextAwareProcessor 2. AspectPostProcessor 3. ServicePostProcessor 4. User-defined IPostProcessor Pods (sorted by @Order)
Source code in core/spakky/src/spakky/core/application/application_context.py
__initialize_pods()
¶
Eagerly initialize all non-lazy Pods.
Raises:
| Type | Description |
|---|---|
NoSuchPodError
|
If a Pod cannot be instantiated. |
Source code in core/spakky/src/spakky/core/application/application_context.py
__get_internal(type_, name, dependency_hierarchy=None, qualifiers=None)
¶
Internal method to get or create a Pod instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type_
|
type[ObjectT]
|
The type to resolve. |
required |
name
|
str | None
|
Optional name qualifier. |
required |
dependency_hierarchy
|
tuple[type, ...] | None
|
Immutable tuple for circular dependency detection. |
None
|
qualifiers
|
list[Qualifier] | None
|
List of qualifier annotations. |
None
|
Returns:
| Type | Description |
|---|---|
ObjectT | None
|
The resolved Pod instance or None if not found. |
Source code in core/spakky/src/spakky/core/application/application_context.py
__start_services()
¶
Start all registered sync and async services.
Raises:
| Type | Description |
|---|---|
EventLoopThreadAlreadyStartedInApplicationContextError
|
If already started. |
Source code in core/spakky/src/spakky/core/application/application_context.py
__stop_services()
¶
Stop all services and shutdown event loop.
Raises:
| Type | Description |
|---|---|
EventLoopThreadNotStartedInApplicationContextError
|
If not started. |
Source code in core/spakky/src/spakky/core/application/application_context.py
find(selector)
¶
Find all Pod instances matching selector predicate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
selector
|
Callable[[Pod], bool]
|
Predicate function to filter Pods. |
required |
Returns:
| Type | Description |
|---|---|
set[object]
|
Set of matching Pod instances. |
Source code in core/spakky/src/spakky/core/application/application_context.py
add(obj)
¶
Register a Pod-annotated class or function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
PodType
|
The Pod to register. |
required |
Raises:
| Type | Description |
|---|---|
CannotRegisterNonPodObjectError
|
If obj is not annotated with @Pod. |
PodNameAlreadyExistsError
|
If Pod name already registered with different ID. |
Source code in core/spakky/src/spakky/core/application/application_context.py
add_service(service)
¶
Register a service for lifecycle management.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
service
|
IService | IAsyncService
|
The service to register (sync or async). |
required |
Source code in core/spakky/src/spakky/core/application/application_context.py
start()
¶
Start the application context.
Registers post-processors, initializes Pods, and starts services.
Raises:
| Type | Description |
|---|---|
ApplicationContextAlreadyStartedError
|
If already started. |
Source code in core/spakky/src/spakky/core/application/application_context.py
stop()
¶
Stop the application context and clean up resources.
Thread-safe: Multiple concurrent calls to stop() are serialized.
Raises:
| Type | Description |
|---|---|
ApplicationContextAlreadyStoppedError
|
If already stopped. |
Source code in core/spakky/src/spakky/core/application/application_context.py
get(type_, name=None)
¶
Get a Pod instance by type and optional name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type_
|
type[ObjectT]
|
The type to retrieve. |
required |
name
|
str | None
|
Optional name qualifier. |
None
|
Returns:
| Type | Description |
|---|---|
ObjectT | object
|
The Pod instance. |
Raises:
| Type | Description |
|---|---|
NoSuchPodError
|
If no matching Pod found. |
Source code in core/spakky/src/spakky/core/application/application_context.py
contains(type_, name=None)
¶
Check if a Pod is registered.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type_
|
type
|
The type to check. |
required |
name
|
str | None
|
Optional name qualifier. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if matching Pod exists. |
Source code in core/spakky/src/spakky/core/application/application_context.py
register_tag(tag)
¶
Register a Tag instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tag
|
Tag
|
The Tag to register. |
required |
contains_tag(tag)
¶
Check if a Tag is registered.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tag
|
Tag
|
The Tag to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if Tag is registered. |
list_tags(selector=None)
¶
List registered Tags, optionally filtered by selector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
selector
|
Callable[[Tag], bool] | None
|
Optional predicate to filter Tags. |
None
|
Returns: Set of matching Tags.
Source code in core/spakky/src/spakky/core/application/application_context.py
get_context_id()
¶
Get or create unique ID for current context.
Returns:
| Type | Description |
|---|---|
UUID
|
UUID for this context. |
Source code in core/spakky/src/spakky/core/application/application_context.py
get_context_value(key)
¶
Get a value from the context-scoped cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key to retrieve. |
required |
Returns:
| Type | Description |
|---|---|
object | None
|
The cached value, or None if not found. |
Source code in core/spakky/src/spakky/core/application/application_context.py
set_context_value(key, value)
¶
Set a value in the context-scoped cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key to set. |
required |
value
|
object
|
The value to store. |
required |
Source code in core/spakky/src/spakky/core/application/application_context.py
options: show_root_heading: false
spakky.core.application.plugin
¶
Plugin metadata representation.
This module defines the Plugin class for identifying and managing framework plugins.
Plugin
¶
Bases: IEquatable
Immutable plugin identifier.
Plugins are identified by name and used to selectively load framework extensions.
name
instance-attribute
¶
Unique name of the plugin.
__hash__()
¶
Compute hash based on plugin name.
Returns:
| Type | Description |
|---|---|
int
|
Hash value for this plugin. |
__eq__(__value)
¶
Check equality based on plugin name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
__value
|
object
|
The object to compare with. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if both plugins have the same name. |
Source code in core/spakky/src/spakky/core/application/plugin.py
options: show_root_heading: false
spakky.core.application.error
¶
Error types for application-level exceptions.
This module defines the base error class for all application-related errors.
AbstractSpakkyApplicationError
¶
Bases: AbstractSpakkyFrameworkError, ABC
Base class for all application-level errors.
options: show_root_heading: false
AOP¶
spakky.core.aop.aspect
¶
Aspect annotations for declaring AOP aspects as Pods.
This module provides decorators for marking classes as aspects that can intercept method calls across the application.
Aspect(*, name='', scope=Scope.SINGLETON)
dataclass
¶
Bases: Pod
Pod decorator for synchronous aspects.
Marks a class as an aspect that can intercept synchronous method calls. The class must implement IAspect interface.
matches(pod)
¶
Check if this aspect should be applied to a pod.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pod
|
object
|
The pod object to check for matching pointcuts. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if any pointcut matches the pod, False otherwise. |
Raises:
| Type | Description |
|---|---|
AspectInheritanceError
|
If target is not a class Pod or doesn't implement IAspect. |
Source code in core/spakky/src/spakky/core/aop/aspect.py
AsyncAspect(*, name='', scope=Scope.SINGLETON)
dataclass
¶
Bases: Pod
Pod decorator for asynchronous aspects.
Marks a class as an aspect that can intercept asynchronous method calls. The class must implement IAsyncAspect interface.
matches(pod)
¶
Check if this async aspect should be applied to a pod.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pod
|
object
|
The pod object to check for matching pointcuts. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if any pointcut matches the pod, False otherwise. |
Raises:
| Type | Description |
|---|---|
AspectInheritanceError
|
If target is not a class Pod or doesn't implement IAsyncAspect. |
Source code in core/spakky/src/spakky/core/aop/aspect.py
options: show_root_heading: false
spakky.core.aop.advisor
¶
Advisor classes that coordinate aspect execution around method calls.
Advisors wrap methods with aspect logic, executing before/around/after advice in the correct order and handling exceptions appropriately.
Advisor(instance, next)
¶
Advisor for synchronous methods with aspect interception.
Initialize the advisor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instance
|
IAspect
|
The aspect instance providing advice. |
required |
next
|
Func
|
The next function to call in the chain. |
required |
Source code in core/spakky/src/spakky/core/aop/advisor.py
instance = instance
instance-attribute
¶
The aspect instance that provides advice.
next = next
instance-attribute
¶
The next function in the advice chain.
__getattr__(name)
¶
__call__(*args, **kwargs)
¶
Execute the advised method with aspect logic.
Coordinates the execution of before, around, after_returning, after_raising, and after advice in the correct order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Positional arguments for the method. |
()
|
**kwargs
|
Any
|
Keyword arguments for the method. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The result of the method call. |
Raises:
| Type | Description |
|---|---|
Exception
|
Any exception raised by the advised method or aspect. |
Source code in core/spakky/src/spakky/core/aop/advisor.py
AsyncAdvisor(instance, next)
¶
Advisor for asynchronous methods with aspect interception.
Initialize the async advisor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instance
|
IAsyncAspect
|
The async aspect instance providing advice. |
required |
next
|
AsyncFunc
|
The next async function to call in the chain. |
required |
Source code in core/spakky/src/spakky/core/aop/advisor.py
instance = instance
instance-attribute
¶
The async aspect instance that provides advice.
next = next
instance-attribute
¶
The next async function in the advice chain.
__getattr__(name)
¶
__call__(*args, **kwargs)
async
¶
Execute the advised async method with aspect logic.
Coordinates the execution of before, around, after_returning, after_raising, and after advice in the correct order for async methods.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Positional arguments for the method. |
()
|
**kwargs
|
Any
|
Keyword arguments for the method. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The result of the async method call. |
Raises:
| Type | Description |
|---|---|
Exception
|
Any exception raised by the advised method or aspect. |
Source code in core/spakky/src/spakky/core/aop/advisor.py
options: show_root_heading: false
spakky.core.aop.pointcut
¶
Pointcut annotations for defining when aspects should be applied.
This module provides decorators for specifying when aspect advice should intercept method calls (before, after, around, etc.).
AbstractPointCut(pointcut)
dataclass
¶
Bases: FunctionAnnotation, ABC
Base class for pointcut annotations.
pointcut
instance-attribute
¶
Predicate function that determines if a method matches this pointcut.
matches(method)
¶
Check if a method matches this pointcut.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
Func
|
The method to check. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the method matches the pointcut predicate, False otherwise. |
Source code in core/spakky/src/spakky/core/aop/pointcut.py
Before(pointcut)
dataclass
¶
AfterReturning(pointcut)
dataclass
¶
AfterRaising(pointcut)
dataclass
¶
After(pointcut)
dataclass
¶
Bases: AbstractPointCut
Pointcut for advice that executes after a method call (regardless of outcome).
Around(pointcut)
dataclass
¶
Bases: AbstractPointCut
Pointcut for advice that wraps around a method call, controlling its execution.
options: show_root_heading: false
spakky.core.aop.interfaces
¶
options: show_root_heading: false
spakky.core.aop.error
¶
Error classes for AOP-related exceptions.
AbstractSpakkyAOPError
¶
Bases: AbstractSpakkyFrameworkError, ABC
Base class for all AOP-related errors.
AspectInheritanceError
¶
Bases: AbstractSpakkyAOPError
Raised when an aspect class doesn't implement required interfaces.
Aspect classes must inherit from either IAspect (for sync) or IAsyncAspect (for async).
options: show_root_heading: false
Pod¶
spakky.core.pod.annotations
¶
options: show_root_heading: false
spakky.core.pod.inject
¶
Utility function for manual dependency injection.
This module provides the inject() function for programmatic Pod retrieval from the container when constructor injection is not available.
inject(context, type_, name=None)
¶
Manually inject a Pod from the container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
IContainer
|
The container to retrieve from. |
required |
type_
|
type[ObjectT]
|
The type of Pod to retrieve. |
required |
name
|
str | None
|
Optional name qualifier. |
None
|
Returns:
| Type | Description |
|---|---|
object | ObjectT
|
The requested Pod instance. |
Example
service = inject(app.container, UserService) named_service = inject(app.container, IRepo, "postgres")
Source code in core/spakky/src/spakky/core/pod/inject.py
options: show_root_heading: false
spakky.core.pod.interfaces.container
¶
Protocol and errors for Pod container interface.
This module defines the IContainer protocol for managing Pod lifecycle and dependency injection.
CircularDependencyGraphDetectedError(dependency_chain)
¶
Bases: AbstractSpakkyPodError, IRepresentable
Raised when circular dependency is detected during Pod instantiation.
Attributes:
| Name | Type | Description |
|---|---|---|
dependency_chain |
list[type]
|
List of types showing the circular dependency path. |
Initialize with dependency chain information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dependency_chain
|
list[type]
|
List of types in dependency order, ending with the duplicate type. |
required |
Source code in core/spakky/src/spakky/core/pod/interfaces/container.py
__str__()
¶
Format error message with visual dependency path.
Returns:
| Type | Description |
|---|---|
str
|
Formatted string showing the circular dependency path with tree visualization. |
Source code in core/spakky/src/spakky/core/pod/interfaces/container.py
NoSuchPodError
¶
NoUniquePodError
¶
CannotRegisterNonPodObjectError
¶
PodNameAlreadyExistsError
¶
IContainer
¶
Bases: ABC
Protocol for IoC container managing Pod instances.
pods
abstractmethod
property
¶
Get all registered Pods.
Returns:
| Type | Description |
|---|---|
dict[str, Pod]
|
Dictionary mapping Pod names to Pod metadata. |
add(obj)
abstractmethod
¶
Register a Pod in the container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
PodType
|
The Pod-annotated class or function to register. |
required |
get(type_, name=None)
abstractmethod
¶
Get a Pod instance by type and optional name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type_
|
type[ObjectT]
|
The type to retrieve. |
required |
name
|
str | None
|
Optional name qualifier. |
None
|
Returns:
| Type | Description |
|---|---|
ObjectT | object
|
The Pod instance. |
Source code in core/spakky/src/spakky/core/pod/interfaces/container.py
contains(type_, name=None)
abstractmethod
¶
Check if a Pod is registered.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type_
|
type
|
The type to check. |
required |
name
|
str | None
|
Optional name qualifier. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if matching Pod exists. |
Source code in core/spakky/src/spakky/core/pod/interfaces/container.py
find(selector)
abstractmethod
¶
Find all Pod instances matching selector predicate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
selector
|
Callable[[Pod], bool]
|
Predicate function to filter Pods. |
required |
Returns:
| Type | Description |
|---|---|
set[object]
|
Set of matching Pod instances. |
Source code in core/spakky/src/spakky/core/pod/interfaces/container.py
options: show_root_heading: false
spakky.core.pod.interfaces.application_context
¶
Protocol and errors for application context interface.
This module defines the IApplicationContext protocol for managing application lifecycle and service coordination.
ApplicationContextAlreadyStartedError
¶
ApplicationContextAlreadyStoppedError
¶
EventLoopThreadNotStartedInApplicationContextError
¶
EventLoopThreadAlreadyStartedInApplicationContextError
¶
Bases: AbstractSpakkyApplicationError
Raised when attempting to start already running event loop thread.
IApplicationContext
¶
Bases: IContainer, ITagRegistry, ABC
Protocol for application context managing Pod lifecycle and services.
Extends IContainer with service management and lifecycle control.
thread_stop_event
instance-attribute
¶
Threading event for stopping background threads.
task_stop_event
instance-attribute
¶
Async event for stopping background tasks.
is_started
abstractmethod
property
¶
Check if context is started.
Returns:
| Type | Description |
|---|---|
bool
|
True if context has been started. |
add_service(service)
abstractmethod
¶
Register a service for lifecycle management.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
service
|
IService | IAsyncService
|
The service to register. |
required |
start()
abstractmethod
¶
stop()
abstractmethod
¶
get_context_id()
abstractmethod
¶
Get unique ID for current context.
Returns:
| Type | Description |
|---|---|
UUID
|
UUID for this context. |
get_context_value(key)
abstractmethod
¶
Get a value from the context-scoped cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key to retrieve. |
required |
Returns:
| Type | Description |
|---|---|
object | None
|
The cached value, or None if not found. |
Source code in core/spakky/src/spakky/core/pod/interfaces/application_context.py
set_context_value(key, value)
abstractmethod
¶
Set a value in the context-scoped cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key to set. |
required |
value
|
object
|
The value to store. |
required |
options: show_root_heading: false
spakky.core.pod.interfaces.post_processor
¶
Protocol for Pod post-processors.
This module defines the IPostProcessor protocol for transforming Pod instances after creation but before use.
IPostProcessor
¶
Bases: ABC
Protocol for processing Pods after instantiation.
Post-processors can wrap, modify, or enhance Pod instances. Common uses include AOP proxy creation, dependency injection, and lifecycle management.
post_process(pod)
abstractmethod
¶
Process a Pod instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pod
|
object
|
The Pod instance to process. |
required |
Returns:
| Type | Description |
|---|---|
object
|
The processed Pod instance (may be wrapped or modified). |
Source code in core/spakky/src/spakky/core/pod/interfaces/post_processor.py
options: show_root_heading: false
spakky.core.pod.interfaces.tag_registry
¶
ITagRegistry
¶
options: show_root_heading: false
spakky.core.pod.interfaces.aware
¶
options: show_root_heading: false
spakky.core.pod.error
¶
options: show_root_heading: false
Service¶
spakky.core.service.interfaces
¶
options: show_root_heading: false
spakky.core.service.background
¶
Abstract base classes for background services.
This module provides base implementations for long-running background services with proper lifecycle management.
AbstractBackgroundService
¶
Bases: IService, ABC
Base class for synchronous background services.
Runs in a dedicated thread and can be started/stopped gracefully.
set_stop_event(stop_event)
¶
Set stop event for shutdown signaling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stop_event
|
Event
|
Event to signal service shutdown. |
required |
start()
¶
Start service in background thread.
stop()
¶
initialize()
abstractmethod
¶
Initialize service before starting.
Called once before the service thread starts.
dispose()
abstractmethod
¶
run()
abstractmethod
¶
Main service loop.
Runs in background thread. Should check _stop_event periodically and exit when it's set.
AbstractAsyncBackgroundService
¶
Bases: IAsyncService, ABC
Base class for asynchronous background services.
Runs as an async task and can be started/stopped gracefully.
set_stop_event(stop_event)
¶
Set stop event for shutdown signaling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stop_event
|
Event
|
Async event to signal service shutdown. |
required |
start_async()
async
¶
Start service as background task.
stop_async()
async
¶
Stop service and wait for task to finish.
initialize_async()
abstractmethod
async
¶
Initialize service before starting.
Called once before the service task starts.
dispose_async()
abstractmethod
async
¶
Clean up resources after stopping.
Called once after the service task stops.
run_async()
abstractmethod
async
¶
Main service loop.
Runs as async task. Should check _stop_event periodically and exit when it's set.
options: show_root_heading: false
spakky.core.service.post_processor
¶
Post-processor for registering services with application context.
This module provides ServicePostProcessor which automatically registers service Pods with the application context for lifecycle management.
ServicePostProcessor(application_context)
¶
Bases: IPostProcessor
Post-processor for registering service Pods.
Detects Pods implementing IService or IAsyncService and registers them with the application context for automatic lifecycle management.
Initialize service post-processor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
application_context
|
IApplicationContext
|
Application context for service registration. |
required |
Source code in core/spakky/src/spakky/core/service/post_processor.py
post_process(pod)
¶
Register service Pods with application context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pod
|
object
|
The Pod instance to process. |
required |
Returns:
| Type | Description |
|---|---|
object
|
The Pod instance unchanged. |
Source code in core/spakky/src/spakky/core/service/post_processor.py
options: show_root_heading: false
Stereotype¶
spakky.core.stereotype.configuration
¶
Configuration stereotype for organizing configuration Pods.
This module provides @Configuration stereotype for grouping related configuration and factory method Pods.
Configuration(*, name='', scope=Scope.SINGLETON)
dataclass
¶
Bases: Pod
Stereotype for configuration classes containing factory methods.
Classes decorated with @Configuration typically contain @Pod-annotated factory methods that produce other Pods.
options: show_root_heading: false
spakky.core.stereotype.controller
¶
Controller stereotype for grouping request handlers.
This module provides @Controller stereotype for organizing classes that handle external requests (HTTP, CLI, etc.).
Controller(*, name='', scope=Scope.SINGLETON)
dataclass
¶
Bases: Pod
Stereotype for controller classes handling external requests.
Controllers typically contain route handlers, command handlers, or other request processing methods.
options: show_root_heading: false
spakky.core.stereotype.usecase
¶
UseCase stereotype for encapsulating business logic.
This module provides @UseCase stereotype for organizing classes that implement application-specific business rules.
UseCase(*, name='', scope=Scope.SINGLETON)
dataclass
¶
Bases: Pod
Stereotype for use case classes encapsulating business logic.
UseCases represent application-specific business operations, orchestrating domain entities and services to fulfill requirements.
options: show_root_heading: false
Common¶
spakky.core.common.annotation
¶
Annotation()
dataclass
¶
Base class for type-safely injecting metadata(annotation as said) into objects.
all(obj)
classmethod
¶
Get all list of annotations from the object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
object
|
The object to get the annotations from. |
required |
Returns:
| Type | Description |
|---|---|
list[Self]
|
list[Self]: List of annotations. |
Source code in core/spakky/src/spakky/core/common/annotation.py
get(obj)
classmethod
¶
Get a single annotation from the object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
object
|
The object to get the annotation from. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
The annotation. |
Raises:
| Type | Description |
|---|---|
AnnotationNotFoundError
|
If no annotation is found. |
MultipleAnnotationFoundError
|
If multiple annotations are found. |
Source code in core/spakky/src/spakky/core/common/annotation.py
get_or_none(obj)
classmethod
¶
Get a single annotation from the object or None if not found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
object
|
The object to get the annotation from. |
required |
Raises:
| Type | Description |
|---|---|
MultipleAnnotationFoundError
|
If multiple annotations are found. |
Returns:
| Type | Description |
|---|---|
Self | None
|
Self | None: The annotation or None if not found. |
Source code in core/spakky/src/spakky/core/common/annotation.py
get_or_default(obj, default)
classmethod
¶
Get a single annotation from the object or a default value if not found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
object
|
The object to get the annotation from. |
required |
default
|
Self
|
The default value to return if not found. |
required |
Raises:
| Type | Description |
|---|---|
MultipleAnnotationFoundError
|
If multiple annotations are found. |
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
The annotation or the default value if not found. |
Source code in core/spakky/src/spakky/core/common/annotation.py
exists(obj)
classmethod
¶
Check if the annotation exists in the object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
object
|
The object to check. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the annotation exists, False otherwise. |
Source code in core/spakky/src/spakky/core/common/annotation.py
ClassAnnotation()
dataclass
¶
Bases: Annotation
Annotation for classes.
__call__(obj)
¶
Call method to annotate a class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
type[ObjectT]
|
The class to annotate. |
required |
Returns:
| Type | Description |
|---|---|
type[ObjectT]
|
type[ObjectT]: The annotated class. |
Source code in core/spakky/src/spakky/core/common/annotation.py
FunctionAnnotation()
dataclass
¶
Bases: Annotation
Annotation for functions.
__call__(obj)
¶
Call method to annotate a function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Callable[..., AnyT]
|
The function to annotate. |
required |
Returns:
| Type | Description |
|---|---|
Callable[..., AnyT]
|
Callable[..., AnyT]: The annotated function. |
Source code in core/spakky/src/spakky/core/common/annotation.py
AnnotationNotFoundError
¶
Bases: AbstractSpakkyFrameworkError
Exception raised when no annotation is found in an object.
MultipleAnnotationFoundError
¶
Bases: AbstractSpakkyFrameworkError
Exception raised when multiple annotations are found in an object.
options: show_root_heading: false
spakky.core.common.interfaces
¶
options: show_root_heading: false
spakky.core.common.metadata
¶
Metadata extraction utilities for Annotated types.
This module provides utilities for extracting metadata from Python's Annotated type hints.
MetadataNotFoundError
¶
Bases: AbstractSpakkyFrameworkError
Raised when expected metadata is not found in an Annotated type.
InvalidAnnotatedTypeError
¶
Bases: AbstractSpakkyFrameworkError
Raised when an invalid Annotated type is provided.
AbstractMetadata()
dataclass
¶
Bases: ABC
Abstract base class for type metadata.
get_actual_type(annotated)
classmethod
¶
Get the actual Python type from the Annotated type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
annotated
|
AnnotatedType
|
The Annotated type to extract the actual type from. |
required |
Returns:
| Type | Description |
|---|---|
type[Any]
|
type[Any]: The actual Python type. |
Source code in core/spakky/src/spakky/core/common/metadata.py
all(annotated)
classmethod
¶
Get all metadata of this type from the Annotated type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
annotated
|
AnnotatedType
|
The Annotated type to extract metadata from. |
required |
Returns:
| Type | Description |
|---|---|
list[Self]
|
list[Self]: List of metadata instances of this type. |
Source code in core/spakky/src/spakky/core/common/metadata.py
get(annotated)
classmethod
¶
Get a single metadata of this type from the Annotated type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
annotated
|
AnnotatedType
|
The Annotated type to extract metadata from. |
required |
Returns: Self: The metadata instance of this type.
Source code in core/spakky/src/spakky/core/common/metadata.py
get_or_none(annotated)
classmethod
¶
Get a single metadata of this type from the Annotated type, or None if not found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
annotated
|
AnnotatedType
|
The Annotated type to extract metadata from. |
required |
Returns:
| Type | Description |
|---|---|
Self | None
|
Self | None: The metadata instance of this type, or None if not found. |
Source code in core/spakky/src/spakky/core/common/metadata.py
get_or_default(annotated, default)
classmethod
¶
Get a single metadata of this type from the Annotated type, or a default if not found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
annotated
|
AnnotatedType
|
The Annotated type to extract metadata from. |
required |
default
|
Self
|
The default metadata to return if not found. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
The metadata instance of this type, or the default if not found. |
Source code in core/spakky/src/spakky/core/common/metadata.py
exists(annotated)
classmethod
¶
Check if metadata of this type exists in the Annotated type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
annotated
|
AnnotatedType
|
The Annotated type to check. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if metadata of this type exists, False otherwise. |
Source code in core/spakky/src/spakky/core/common/metadata.py
options: show_root_heading: false
spakky.core.common.proxy
¶
Dynamic proxy implementation for intercepting object method calls and attribute access.
This module provides a proxy pattern implementation that allows intercepting and modifying method calls and attribute access on target objects.
IProxyHandler
¶
Bases: ABC
Protocol for proxy handlers that intercept object operations.
call(target, method, *args, **kwargs)
abstractmethod
¶
Intercept a synchronous method call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
object
|
The target object. |
required |
method
|
Func
|
The method being called. |
required |
*args
|
Any
|
Positional arguments for the method. |
()
|
**kwargs
|
Any
|
Keyword arguments for the method. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The result of the method call. |
Source code in core/spakky/src/spakky/core/common/proxy.py
call_async(target, method, *args, **kwargs)
abstractmethod
async
¶
Intercept an asynchronous method call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
object
|
The target object. |
required |
method
|
AsyncFunc
|
The async method being called. |
required |
*args
|
Any
|
Positional arguments for the method. |
()
|
**kwargs
|
Any
|
Keyword arguments for the method. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The result of the async method call. |
Source code in core/spakky/src/spakky/core/common/proxy.py
get(target, name)
abstractmethod
¶
Intercept attribute access.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
object
|
The target object. |
required |
name
|
str
|
The attribute name being accessed. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The attribute value. |
Source code in core/spakky/src/spakky/core/common/proxy.py
set(target, name, value)
abstractmethod
¶
Intercept attribute assignment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
object
|
The target object. |
required |
name
|
str
|
The attribute name being set. |
required |
value
|
Any
|
The value being assigned. |
required |
Source code in core/spakky/src/spakky/core/common/proxy.py
delete(target, name)
abstractmethod
¶
Intercept attribute deletion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
object
|
The target object. |
required |
name
|
str
|
The attribute name being deleted. |
required |
AbstractProxyHandler
¶
Bases: IProxyHandler, ABC
Abstract base class for proxy handlers with default pass-through implementations.
call(target, method, *args, **kwargs)
¶
Default implementation that directly calls the method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
object
|
The target object. |
required |
method
|
Func
|
The method being called. |
required |
*args
|
Any
|
Positional arguments for the method. |
()
|
**kwargs
|
Any
|
Keyword arguments for the method. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The result of the method call. |
Source code in core/spakky/src/spakky/core/common/proxy.py
ProxyFactory(target, handler)
¶
Bases: Generic[ObjectT]
Factory for creating dynamic proxy objects.
Creates a proxy that intercepts method calls and attribute access on a target object, delegating the interception logic to a handler.
Initialize the proxy factory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
ObjectT
|
The target object to proxy. |
required |
handler
|
IProxyHandler
|
The handler that implements interception logic. |
required |
Source code in core/spakky/src/spakky/core/common/proxy.py
ATTRIBUTES_TO_IGNORE = frozenset(['__dict__', '__class__', '__weakref__', '__base__', '__bases__', '__mro__', '__subclasses__', '__name__', '__qualname__', '__module__', '__annotations__', '__doc__'])
class-attribute
¶
Class-level attributes that should not be proxied.
create()
¶
Create a proxy instance for the target object.
Returns:
| Name | Type | Description |
|---|---|---|
ObjectT |
ObjectT
|
A proxy instance that wraps the target object. |
Source code in core/spakky/src/spakky/core/common/proxy.py
options: show_root_heading: false
spakky.core.common.types
¶
Type aliases and utility functions for the Spakky framework.
This module provides common type aliases and utility functions for working with types, particularly for Optional/Union type handling.
is_optional(type_)
¶
Check if a type is Optional (Union with None).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type_
|
Any
|
The type to check. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the type is Optional[T] or Union[T, None], False otherwise. |
Source code in core/spakky/src/spakky/core/common/types.py
remove_none(type_)
¶
Remove None from a Union type.
If the type is Union[T, None], returns T. If the type is Union[T1, T2, ..., None], returns Union[T1, T2, ...]. If the type is not a Union, returns it unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type_
|
Any
|
The type to process. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The type with None removed from Union types. |
Source code in core/spakky/src/spakky/core/common/types.py
get_callable_methods(obj)
¶
Get callable members excluding properties.
Uses inspect.getmembers_static() to avoid invoking descriptors during introspection, then retrieves bound methods only for non-property callables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
object
|
The object to inspect. |
required |
Returns:
| Type | Description |
|---|---|
list[tuple[str, Callable[..., Any]]]
|
List of (name, bound_method) tuples for callable non-property members. |
Source code in core/spakky/src/spakky/core/common/types.py
options: show_root_heading: false
Utilities¶
spakky.core.utils.casing
¶
String case conversion utilities.
This module provides functions for converting between PascalCase and snake_case.
pascal_to_snake(pascal_case)
¶
Convert PascalCase string to snake_case.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pascal_case
|
str
|
String in PascalCase format. |
required |
Returns:
| Type | Description |
|---|---|
str
|
String converted to snake_case. |
Example
pascal_to_snake("UserService") 'user_service'
Source code in core/spakky/src/spakky/core/utils/casing.py
snake_to_pascal(snake_case)
¶
Convert snake_case string to PascalCase.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
snake_case
|
str
|
String in snake_case format. |
required |
Returns:
| Type | Description |
|---|---|
str
|
String converted to PascalCase. |
Example
snake_to_pascal("user_service") 'UserService'
Source code in core/spakky/src/spakky/core/utils/casing.py
options: show_root_heading: false
spakky.core.utils.inspection
¶
Function and class inspection utilities.
This module provides utilities for introspecting functions and classes to determine their characteristics.
is_instance_method(obj)
¶
Check if a function is an instance method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Func
|
The function to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the function is an instance method (has 'self' as first parameter). |
Source code in core/spakky/src/spakky/core/utils/inspection.py
has_default_constructor(cls)
¶
Check if a class has a default (no-argument) constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cls
|
type[object]
|
The class to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the class uses the default object.init or protocol placeholder. |
Source code in core/spakky/src/spakky/core/utils/inspection.py
get_fully_qualified_name(obj)
¶
Return the fully qualified name (FQN) of an object.
Resolution rules
- If
objis a class, returnobj.__module__ + "." + obj.__qualname__. - If
objis a function or method, return its own FQN. - Otherwise, treat
objas an instance and return the FQN oftype(obj).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
object
|
Class, function, method, or arbitrary instance. |
required |
Returns:
| Type | Description |
|---|---|
str
|
A dotted fully qualified name, for example: |
str
|
|
Example
class Foo: ... def bar(self) -> None: pass get_fully_qualified_name(Foo) 'main.Foo' get_fully_qualified_name(Foo.bar) 'main.Foo.bar' get_fully_qualified_name(Foo()) 'main.Foo'
Source code in core/spakky/src/spakky/core/utils/inspection.py
options: show_root_heading: false
spakky.core.utils.naming
¶
Python naming convention utilities.
This module provides functions for checking Python naming conventions, such as identifying public/private identifiers.
PRIVATE_PREFIX = '_'
module-attribute
¶
Prefix for private identifiers in Python naming convention.
DUNDER_PREFIX = '__'
module-attribute
¶
Prefix and suffix for magic/dunder methods.
is_dunder_name(name)
¶
Check if a name is a magic/dunder method name.
Dunder (double underscore) names like init, str are special methods that are considered public in Python.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The identifier name to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the name is a dunder name (starts and ends with __). |
Example
is_dunder_name("init") True is_dunder_name("str") True is_dunder_name("__private") False
Source code in core/spakky/src/spakky/core/utils/naming.py
is_public_name(name)
¶
Check if a name follows public naming convention.
In Python: - Names starting with underscore are private (e.g., _internal) - Names with double underscore prefix are name-mangled (e.g., private) - Dunder names (__init, str) are public magic methods
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The identifier name to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the name is public. |
Example
is_public_name("username") True is_public_name("init") True is_public_name("_internal") False is_public_name("__private") False
Source code in core/spakky/src/spakky/core/utils/naming.py
is_private_name(name)
¶
Check if a name follows private naming convention.
In Python, names starting with underscore are considered private, except for dunder names which are public magic methods.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The identifier name to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the name is private. |
Example
is_private_name("_internal") True is_private_name("mangled") True is_private_name("__init") False is_private_name("public") False
Source code in core/spakky/src/spakky/core/utils/naming.py
options: show_root_heading: false
spakky.core.utils.uuid
¶
options: show_root_heading: false