spakky¶
spakky는 DI 컨테이너, AOP, 애플리케이션 부트스트랩, Pod 스캔을 제공하는 핵심 패키지입니다.
DI 컨테이너, 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. |
startup_phase_recorder
property
¶
Get the startup phase recorder.
Returns:
| Type | Description |
|---|---|
IStartupPhaseRecorder
|
Active or no-op startup phase recorder. |
startup_report
property
¶
Get the startup diagnostics report.
Returns:
| Type | Description |
|---|---|
StartupReport
|
Startup report backing the current phase recorder. |
discovery_manifest_path
property
¶
Get the configured DiscoveryManifest path.
Returns:
| Type | Description |
|---|---|
Path | None
|
Manifest path when reuse is enabled, otherwise None. |
enable_startup_diagnostics()
¶
Enable startup diagnostics with an active phase recorder.
Returns:
| Type | Description |
|---|---|
Self
|
Self for method chaining. |
Source code in core/spakky/src/spakky/core/application/application.py
enable_discovery_manifest(path=None)
¶
Enable reusable scan discovery manifests.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str | None
|
Explicit manifest path. None uses a deterministic project cache path. |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
Self for method chaining. |
Source code in core/spakky/src/spakky/core/application/application.py
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
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 | |
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
535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 | |
start()
¶
Start the application by initializing all Pods and running post-processors.
Returns:
| Type | Description |
|---|---|
Self
|
Self for method chaining. |
Source code in core/spakky/src/spakky/core/application/application.py
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
¶
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.
__bindings = {}
instance-attribute
¶
Explicit interface-to-implementation binding policies.
__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.
__startup_metrics = None
instance-attribute
¶
Startup lifecycle metrics for the active start attempt.
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. |
__type_name(type_)
¶
Return a stable diagnostic name for a dependency type.
__dependency_path_node(pod, dependency_parameter_name=None, requested_type=None)
¶
Create one dependency path node from registered Pod metadata.
Source code in core/spakky/src/spakky/core/application/application_context.py
__dependency_diagnostic(pod, dependency_parameter_name, requested_type, dependency_path, candidates=(), resolution_hints=())
¶
Build structured diagnostics from the active Pod dependency path.
Source code in core/spakky/src/spakky/core/application/application_context.py
__startup_diagnostic_details(exception)
¶
Convert dependency resolution diagnostics into startup report details.
Source code in core/spakky/src/spakky/core/application/application_context.py
__candidate_diagnostics(pods)
¶
Return stable ambiguity diagnostics for candidate Pods.
Source code in core/spakky/src/spakky/core/application/application_context.py
__ambiguity_hints(dependency_parameter_name)
¶
Return resolution hints for a single dependency ambiguity.
Source code in core/spakky/src/spakky/core/application/application_context.py
__ambiguity_diagnostic(requester_pod, dependency_parameter_name, requested_type, dependency_path, candidates, resolution_hints)
¶
Build dependency diagnostics when ambiguity occurs during injection.
Source code in core/spakky/src/spakky/core/application/application_context.py
__binding_target_count(binding)
¶
Return how many target selectors a binding specifies.
Source code in core/spakky/src/spakky/core/application/application_context.py
__validate_binding(binding)
¶
Validate binding shape without requiring Pods to be registered yet.
Source code in core/spakky/src/spakky/core/application/application_context.py
__resolve_binding_candidate(type_, pods)
¶
Resolve an explicit binding for this requested type, when configured.
Source code in core/spakky/src/spakky/core/application/application_context.py
__candidate_pods_for_type(type_)
¶
Return exact candidates, falling back to generic origin candidates.
Source code in core/spakky/src/spakky/core/application/application_context.py
__resolve_binding_candidate_for_type(type_, pods)
¶
Resolve exact binding first, then generic-origin binding.
Source code in core/spakky/src/spakky/core/application/application_context.py
__resolve_collection_candidates(type_, qualifiers)
¶
Resolve all collection dependency candidates in stable Pod name order.
Source code in core/spakky/src/spakky/core/application/application_context.py
__index_type_cache(type_, pod)
¶
Index one Pod under a runtime-resolvable type key.
Source code in core/spakky/src/spakky/core/application/application_context.py
__resolve_candidate(type_, name, qualifiers, name_is_dependency_parameter, requester_pod, dependency_path)
¶
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
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 | |
__instantiate_pod(pod, dependency_hierarchy, dependency_path)
¶
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
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 | |
__get_pod_instance(pod, dependency_hierarchy, dependency_path)
¶
Get or create an instance for an already resolved Pod candidate.
Source code in core/spakky/src/spakky/core/application/application_context.py
__resolve_collection_dependency(dependency, dependency_hierarchy, dependency_path)
¶
Resolve list/tuple/dict dependency injection without single ambiguity.
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, dependency_path=None, qualifiers=None, name_is_dependency_parameter=False, requester_pod=None)
¶
Internal method to get or create a Pod instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type_
|
type[T]
|
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 |
|---|---|
T | None
|
The resolved Pod instance or None if not found. |
Source code in core/spakky/src/spakky/core/application/application_context.py
__start_services(started_services, started_async_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
bind(binding)
¶
Register an explicit interface-to-implementation binding policy.
Source code in core/spakky/src/spakky/core/application/application_context.py
bind_to_type(interface, implementation)
¶
Bind an interface to a concrete implementation type.
Source code in core/spakky/src/spakky/core/application/application_context.py
bind_to_name(interface, name)
¶
Bind an interface to a registered Pod name.
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(startup_phase_recorder=None)
¶
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
1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 | |
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[T]
|
The type to retrieve. |
required |
name
|
str | None
|
Optional name qualifier. |
None
|
Returns:
| Type | Description |
|---|---|
T | 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
get_or_none(type_, name=None)
¶
Get a Pod instance by type and optional name, or None if not found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type_
|
type[T]
|
The type to retrieve. |
required |
name
|
str | None
|
Optional name qualifier. |
None
|
Returns:
| Type | Description |
|---|---|
T | None
|
The Pod instance, or None 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. |
Source code in core/spakky/src/spakky/core/application/application_context.py
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.discovery_manifest
¶
Discovery manifest storage for reusable scan discovery results.
DiscoveryManifestDecision
¶
Bases: StrEnum
Decision made while loading a discovery manifest.
DiscoveryManifestSourceFingerprint
¶
Fingerprint for one Python source file involved in scan discovery.
DiscoveryManifestFingerprint
¶
Input fingerprint used to decide whether a manifest is fresh.
schema_version
instance-attribute
¶
Manifest schema version used by the current runtime.
python_version
instance-attribute
¶
Major/minor Python version.
module_name
instance-attribute
¶
Scan target module name.
is_package
instance-attribute
¶
Whether the target is a package scan.
exclude
instance-attribute
¶
Normalized exclude module patterns.
sources
instance-attribute
¶
Source files that affect scan discovery.
from_scan_input(path, exclude)
classmethod
¶
Build a fingerprint from scan inputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Module
|
Scan target module or module name. |
required |
exclude
|
set[Module]
|
Exclude module patterns. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
Fingerprint for the current scan input. |
Source code in core/spakky/src/spakky/core/application/discovery_manifest.py
to_json()
¶
Serialize the fingerprint.
Returns:
| Type | Description |
|---|---|
JsonObject
|
JSON-compatible object. |
Source code in core/spakky/src/spakky/core/application/discovery_manifest.py
DiscoveryManifestCandidate
¶
Pod or Tag candidate discovered during scan.
module_name
instance-attribute
¶
Module containing the candidate object.
qualname
instance-attribute
¶
Qualified object name inside the module.
from_object(obj)
classmethod
¶
Build a candidate identity from a discovered object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
type | FunctionType
|
Discovered class or function. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
Candidate identity. |
Source code in core/spakky/src/spakky/core/application/discovery_manifest.py
matches(obj)
¶
Check whether an object matches this candidate identity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
object
|
Candidate object loaded from a module. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True when the object has the same module and qualified name. |
Source code in core/spakky/src/spakky/core/application/discovery_manifest.py
to_json()
¶
Serialize the candidate.
Returns:
| Type | Description |
|---|---|
JsonObject
|
JSON-compatible object. |
DiscoveryManifest
¶
Reusable scan discovery manifest.
fingerprint
instance-attribute
¶
Input fingerprint that produced this manifest.
module_names
instance-attribute
¶
Modules scanned during fresh discovery.
candidates
instance-attribute
¶
Pod and Tag candidates discovered during fresh discovery.
to_json()
¶
Serialize the manifest.
Returns:
| Type | Description |
|---|---|
JsonObject
|
JSON-compatible object. |
Source code in core/spakky/src/spakky/core/application/discovery_manifest.py
DiscoveryManifestLoadResult
¶
DiscoveryManifestStore(path)
¶
File-backed DiscoveryManifest store.
Initialize the store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Manifest JSON file path. |
required |
Source code in core/spakky/src/spakky/core/application/discovery_manifest.py
load(fingerprint)
¶
Load a manifest and compare it to the current fingerprint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fingerprint
|
DiscoveryManifestFingerprint
|
Current scan input fingerprint. |
required |
Returns:
| Type | Description |
|---|---|
DiscoveryManifestLoadResult
|
Manifest load decision and loaded manifest on hit. |
Source code in core/spakky/src/spakky/core/application/discovery_manifest.py
save(manifest)
¶
Persist a manifest.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
manifest
|
DiscoveryManifest
|
Manifest generated from fresh discovery. |
required |
Source code in core/spakky/src/spakky/core/application/discovery_manifest.py
default_discovery_manifest_path()
¶
Return the deterministic project-local manifest path.
Returns:
| Type | Description |
|---|---|
Path
|
Default DiscoveryManifest path under the project cache directory. |
Source code in core/spakky/src/spakky/core/application/discovery_manifest.py
options: show_root_heading: false
spakky.core.application.startup_diagnostics
¶
Startup diagnostics report and phase recorder contracts.
StartupElapsedTimeCannotBeNegativeError
¶
StartupProcessedCountCannotBeNegativeError
¶
StartupFailureSummaryRequiredError
¶
StartupFailureSummaryNotAllowedError
¶
StartupPhaseStatus
¶
Bases: StrEnum
Result status for a startup phase record.
StartupDiagnosticDetail
¶
StartupFailureSummary
¶
Structured startup failure summary without the raw exception object.
exception_type_name
instance-attribute
¶
Concrete exception type name.
message
instance-attribute
¶
Exception message captured at failure time.
diagnostic_details = ()
class-attribute
instance-attribute
¶
Optional structured diagnostic details.
from_exception(exception, diagnostic_details=())
classmethod
¶
Create a failure summary from an exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exception
|
BaseException
|
Exception raised by a startup phase. |
required |
diagnostic_details
|
StartupDiagnosticDetails
|
Optional structured diagnostic details. |
()
|
Returns:
| Type | Description |
|---|---|
Self
|
Failure summary containing exception type and message only. |
Source code in core/spakky/src/spakky/core/application/startup_diagnostics.py
StartupPhaseRecord
¶
Single startup phase timing, count, status, and failure record.
phase_name
instance-attribute
¶
Name of the startup phase.
elapsed_seconds
instance-attribute
¶
Elapsed wall-clock seconds for the phase.
processed_count
instance-attribute
¶
Number of domain objects processed by the phase.
status
instance-attribute
¶
Success or failure status for the phase.
failure_summary = None
class-attribute
instance-attribute
¶
Failure summary when status is failure; absent for success records.
diagnostic_details = ()
class-attribute
instance-attribute
¶
Structured diagnostic details attached to the phase record.
__post_init__()
¶
Validate phase record numeric invariants.
Source code in core/spakky/src/spakky/core/application/startup_diagnostics.py
StartupReport()
¶
Record collection for one application startup attempt.
Initialize an empty startup report.
Source code in core/spakky/src/spakky/core/application/startup_diagnostics.py
records
property
¶
Get startup phase records in insertion order.
Returns:
| Type | Description |
|---|---|
tuple[StartupPhaseRecord, ...]
|
Immutable snapshot of recorded startup phases. |
add_record(record)
¶
Append a phase record.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
record
|
StartupPhaseRecord
|
Phase record to append. |
required |
IStartupPhaseRecorder
¶
Bases: ABC
Interface for startup phase recorders.
report
abstractmethod
property
¶
Get the startup report backing this recorder.
record_success(phase_name, elapsed_seconds, processed_count=0, diagnostic_details=())
abstractmethod
¶
Record a successful startup phase.
Source code in core/spakky/src/spakky/core/application/startup_diagnostics.py
record_failure(phase_name, elapsed_seconds, exception, processed_count=0, diagnostic_details=())
abstractmethod
¶
Record a failed startup phase.
Source code in core/spakky/src/spakky/core/application/startup_diagnostics.py
record_phase(phase_name, processed_count=0, diagnostic_details=())
¶
Measure a startup phase and record success or failure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
phase_name
|
StartupPhaseName
|
Name of the startup phase. |
required |
processed_count
|
StartupProcessedCount
|
Number of domain objects processed by the phase. |
0
|
diagnostic_details
|
StartupDiagnosticDetails
|
Optional structured diagnostic details. |
()
|
Returns:
| Type | Description |
|---|---|
StartupPhaseRecording
|
Context manager that records the phase and re-raises failures. |
Source code in core/spakky/src/spakky/core/application/startup_diagnostics.py
IStartupDiagnosticDetailProvider
¶
Bases: ABC
Interface for startup exceptions that expose structured diagnostics.
startup_diagnostic_details
abstractmethod
property
¶
Structured diagnostic details to attach to startup failure summaries.
StartupPhaseRecording(recorder, phase_name, processed_count, diagnostic_details)
¶
Context manager for measuring and recording one startup phase.
Initialize a startup phase recording context.
Source code in core/spakky/src/spakky/core/application/startup_diagnostics.py
__enter__()
¶
__exit__(_exception_type, exception, _traceback)
¶
Record the phase outcome and preserve exception propagation.
Source code in core/spakky/src/spakky/core/application/startup_diagnostics.py
set_processed_count(processed_count)
¶
Set the processed count before the phase exits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
processed_count
|
StartupProcessedCount
|
Final processed count for the measured phase. |
required |
Source code in core/spakky/src/spakky/core/application/startup_diagnostics.py
set_diagnostic_details(diagnostic_details)
¶
Set structured diagnostic details before the phase exits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
diagnostic_details
|
StartupDiagnosticDetails
|
Structured diagnostic details to attach. |
required |
Source code in core/spakky/src/spakky/core/application/startup_diagnostics.py
ActiveStartupPhaseRecorder(report=None)
¶
Bases: IStartupPhaseRecorder
Recorder that appends phase records to a startup report.
Initialize an active phase recorder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
report
|
StartupReport | None
|
Existing report to append to. None means create a new report. |
None
|
Source code in core/spakky/src/spakky/core/application/startup_diagnostics.py
report
property
¶
Get the startup report backing this recorder.
record_success(phase_name, elapsed_seconds, processed_count=0, diagnostic_details=())
¶
Record a successful startup phase.
Source code in core/spakky/src/spakky/core/application/startup_diagnostics.py
record_failure(phase_name, elapsed_seconds, exception, processed_count=0, diagnostic_details=())
¶
Record a failed startup phase.
Source code in core/spakky/src/spakky/core/application/startup_diagnostics.py
NoOpStartupPhaseRecorder()
¶
Bases: IStartupPhaseRecorder
Recorder that preserves startup behavior without report side effects.
Initialize a no-op recorder with an empty report.
Source code in core/spakky/src/spakky/core/application/startup_diagnostics.py
report
property
¶
Get the empty report backing this recorder.
record_success(phase_name, elapsed_seconds, processed_count=0, diagnostic_details=())
¶
Create a success record without mutating the report.
Source code in core/spakky/src/spakky/core/application/startup_diagnostics.py
record_failure(phase_name, elapsed_seconds, exception, processed_count=0, diagnostic_details=())
¶
Create a failure record without mutating the report.
Source code in core/spakky/src/spakky/core/application/startup_diagnostics.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
¶
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)
¶
Delegate attribute access to the next function in the chain.
__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)
¶
Delegate attribute access to the next async function in the chain.
__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.interfaces.aspect
¶
Interface definitions for aspect implementations.
This module defines the protocols that aspect classes must implement to intercept method calls in the AOP system.
IAspect
¶
Bases: ABC
Interface for synchronous aspect implementations.
before(*args, **kwargs)
¶
Execute before the target method is called.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Positional arguments for the target method. |
()
|
**kwargs
|
Any
|
Keyword arguments for the target method. |
{}
|
Source code in core/spakky/src/spakky/core/aop/interfaces/aspect.py
after_raising(error)
¶
Execute after the target method raises an exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
error
|
Exception
|
The exception that was raised. |
required |
after_returning(result)
¶
Execute after the target method returns successfully.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
Any
|
The return value from the target method. |
required |
after()
¶
around(joinpoint, *args, **kwargs)
¶
Wrap around the target method execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
joinpoint
|
Func
|
The target method to be executed. |
required |
*args
|
Any
|
Positional arguments for the target method. |
()
|
**kwargs
|
Any
|
Keyword arguments for the target method. |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
The result of the joinpoint execution. |
Source code in core/spakky/src/spakky/core/aop/interfaces/aspect.py
IAsyncAspect
¶
Bases: ABC
Interface for asynchronous aspect implementations.
before_async(*args, **kwargs)
async
¶
Execute before the target async method is called.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Positional arguments for the target method. |
()
|
**kwargs
|
Any
|
Keyword arguments for the target method. |
{}
|
Source code in core/spakky/src/spakky/core/aop/interfaces/aspect.py
after_raising_async(error)
async
¶
Execute after the target async method raises an exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
error
|
Exception
|
The exception that was raised. |
required |
after_returning_async(result)
async
¶
Execute after the target async method returns successfully.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
Any
|
The return value from the target method. |
required |
after_async()
async
¶
around_async(joinpoint, *args, **kwargs)
async
¶
Wrap around the target async method execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
joinpoint
|
AsyncFunc
|
The target async method to be executed. |
required |
*args
|
Any
|
Positional arguments for the target method. |
()
|
**kwargs
|
Any
|
Keyword arguments for the target method. |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
The result of the joinpoint execution. |
Source code in core/spakky/src/spakky/core/aop/interfaces/aspect.py
options: show_root_heading: false
spakky.core.aop.error
¶
Error classes for AOP-related exceptions.
AbstractSpakkyAOPError
¶
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.annotations.pod
¶
Pod annotation for dependency injection container registration.
This module provides the core @Pod decorator that marks classes and functions as managed beans in the IoC container, along with dependency resolution logic.
DependencyInfo(name, type_, has_default=False, is_optional=False, qualifiers=list[Qualifier](), collection_kind=None, collection_key_type=None)
dataclass
¶
Information about a Pod's dependency for injection.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The parameter name of the dependency. |
type_ |
Class
|
The type of the dependency. |
has_default |
bool
|
Whether the dependency has a default value. |
is_optional |
bool
|
Whether the dependency is optional (can be None). |
qualifiers |
list[Qualifier]
|
List of qualifiers for disambiguation. |
DependencyCollectionKind
¶
Bases: Enum
Supported collection dependency injection shapes.
CannotDeterminePodTypeError
¶
CannotUseVarArgsInPodError
¶
CannotUsePositionalOnlyArgsInPodError
¶
CannotUseOptionalReturnTypeInPodError
¶
UnsupportedCollectionDependencyTypeError
¶
UnexpectedDependencyNameInjectedError
¶
UnexpectedDependencyTypeInjectedError(*args, dependency_diagnostic=None)
¶
Bases: PodInstantiationFailedError
Raised when an injected dependency has wrong type.
Initialize with optional dependency graph diagnostics.
Source code in core/spakky/src/spakky/core/pod/annotations/pod.py
Pod(*, name='', scope=Scope.SINGLETON)
dataclass
¶
Bases: Annotation, IEquatable
Annotation for marking classes and functions as managed Pods in the IoC container.
Pods are automatically instantiated by the container with their dependencies injected.
id = field(init=False, default_factory=uuid4)
class-attribute
instance-attribute
¶
Unique identifier for this Pod instance.
name = field(kw_only=True, default='')
class-attribute
instance-attribute
¶
Optional name for qualifying this Pod.
scope = field(kw_only=True, default=(Scope.SINGLETON))
class-attribute
instance-attribute
¶
The lifecycle scope of this Pod.
type_ = field(init=False)
class-attribute
instance-attribute
¶
The resolved type of this Pod.
base_types = field(init=False, default_factory=(set[type]))
class-attribute
instance-attribute
¶
Set of base types and interfaces this Pod implements.
target = field(init=False)
class-attribute
instance-attribute
¶
The target class or function being registered as a Pod.
dependencies = field(init=False, default_factory=dict)
class-attribute
instance-attribute
¶
Map of dependency names to their injection information.
is_primary
property
¶
Check if this Pod is marked as primary.
Returns:
| Type | Description |
|---|---|
bool
|
True if the target has @Primary annotation. |
dependency_qualifiers
property
¶
Get qualifiers for all dependencies.
Returns:
| Type | Description |
|---|---|
dict[str, list[Qualifier]]
|
Map of dependency names to their qualifier annotations. |
Scope
¶
Bases: Enum
Lifecycle scope for Pod instances.
SINGLETON = auto()
class-attribute
instance-attribute
¶
One instance shared across the entire application.
PROTOTYPE = auto()
class-attribute
instance-attribute
¶
New instance created on each request.
CONTEXT = auto()
class-attribute
instance-attribute
¶
Instance scoped to request/context lifecycle.
__runtime_base_types(type_)
¶
__get_dependencies(obj)
¶
Extract dependency information from constructor or function parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
PodType
|
The class or function to analyze for dependencies. |
required |
Returns:
| Type | Description |
|---|---|
DependencyMap
|
Map of parameter names to their dependency information. |
Raises:
| Type | Description |
|---|---|
CannotUsePositionalOnlyArgsInPodError
|
If positional-only parameters are found. |
CannotUseVarArgsInPodError
|
If args or *kwargs are found. |
CannotDeterminePodTypeError
|
If parameter has no type annotation. |
Source code in core/spakky/src/spakky/core/pod/annotations/pod.py
__call__(obj)
¶
Apply Pod annotation to target class or function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
T
|
The class or function to decorate. |
required |
Returns:
| Type | Description |
|---|---|
T
|
The original object unchanged. |
Source code in core/spakky/src/spakky/core/pod/annotations/pod.py
__hash__()
¶
Compute hash based on Pod name.
Returns:
| Type | Description |
|---|---|
int
|
Hash value for this Pod. |
__eq__(value)
¶
Check equality based on Pod name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
object
|
The object to compare with. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if both Pods have the same name. |
Source code in core/spakky/src/spakky/core/pod/annotations/pod.py
is_family_with(type_)
¶
Check if this Pod is compatible with a given type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type_
|
type
|
The type to check compatibility with. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if type matches Pod type or is in its base types. |
Source code in core/spakky/src/spakky/core/pod/annotations/pod.py
instantiate(dependencies)
¶
Create an instance of this Pod with injected dependencies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dependencies
|
dict[str, object | None]
|
Map of dependency names to their resolved instances. |
required |
Returns:
| Type | Description |
|---|---|
object
|
The instantiated Pod object. |
Raises:
| Type | Description |
|---|---|
UnexpectedDependencyNameInjectedError
|
If unknown dependency name provided. |
UnexpectedDependencyTypeInjectedError
|
If required non-optional dependency is None. |
Source code in core/spakky/src/spakky/core/pod/annotations/pod.py
is_class_pod(pod)
¶
Check if a Pod target is a class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pod
|
PodType
|
The Pod target to check. |
required |
Returns:
| Type | Description |
|---|---|
TypeGuard[Class]
|
True if pod is a class type. |
is_function_pod(pod)
¶
Check if a Pod target is a function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pod
|
PodType
|
The Pod target to check. |
required |
Returns:
| Type | Description |
|---|---|
TypeGuard[Func]
|
True if pod is a function. |
options: show_root_heading: false
spakky.core.pod.annotations.lazy
¶
Annotation for lazy Pod initialization.
This module provides the @Lazy annotation to defer Pod initialization until first use.
Lazy()
dataclass
¶
Bases: ClassAnnotation
Mark a Pod for lazy initialization.
Pods marked with @Lazy are not instantiated during application startup but only when first requested from the container.
Warning
When using @Lazy with singleton-scoped Pods in multi-threaded environments, the first concurrent access may result in multiple instantiations. To ensure thread-safety for lazy singletons, consider using a factory pattern or initializing the Pod during application startup by removing @Lazy.
Example
@Lazy() @Pod() class ExpensiveService: def init(self): # Heavy initialization deferred until first use pass
options: show_root_heading: false
spakky.core.pod.annotations.order
¶
Annotation for controlling execution order.
This module provides the @Order annotation to control the order of post-processor execution and aspect application.
Order(order=sys.maxsize)
dataclass
¶
Bases: ClassAnnotation
Control execution order of Pods.
Lower order values execute first. Default is sys.maxsize (last). Commonly used for post-processors and aspects.
options: show_root_heading: false
spakky.core.pod.annotations.primary
¶
Annotation for marking preferred Pod implementation.
This module provides the @Primary annotation to indicate the preferred implementation when multiple Pods of the same type exist.
Primary()
dataclass
¶
Bases: ClassAnnotation
Mark a Pod as the primary implementation.
When multiple Pods match a dependency type, the one marked with @Primary is selected by default without requiring explicit qualification.
options: show_root_heading: false
spakky.core.pod.annotations.qualifier
¶
Metadata for qualifying dependency injection.
This module provides the Qualifier class for creating custom dependency qualifiers in Annotated type hints.
Qualifier(selector)
dataclass
¶
Bases: AbstractMetadata
Metadata for qualifying which Pod to inject.
Used in Annotated type hints to select specific Pods when multiple candidates exist.
Example
@Pod() class Service: def init( self, repo: Annotated[IRepo, Qualifier(lambda p: p.name == "primary")], ) -> None: self.repo = repo
options: show_root_heading: false
spakky.core.pod.annotations.tag
¶
Tag()
dataclass
¶
Bases: Annotation, IEquatable
Base class for custom metadata tags attached to Pods.
__eq__(value)
¶
Compare tags by their dataclass field values.
options: show_root_heading: false
spakky.core.pod.binding
¶
Binding policy values for dependency injection candidate selection.
PodBinding
¶
Explicit interface-to-implementation binding policy.
Application or feature configuration can register this value with ApplicationContext to select one implementation when multiple Pods provide the same interface.
options: show_root_heading: false
spakky.core.pod.diagnostics
¶
Structured diagnostics for Pod dependency resolution.
PodCandidateDiagnostic
¶
PodDependencyPathNode
¶
One Pod dependency graph edge observed during resolution.
pod_name
instance-attribute
¶
Registered Pod name for the node being instantiated.
pod_type_name
instance-attribute
¶
Registered Pod type name for the node being instantiated.
dependency_parameter_name = None
class-attribute
instance-attribute
¶
Constructor or factory parameter that requested the next dependency.
requested_type_name = None
class-attribute
instance-attribute
¶
Requested dependency type name for this graph edge.
PodDependencyResolutionDiagnostic
¶
Structured dependency resolution failure details.
failed_pod_name
instance-attribute
¶
Registered Pod name where resolution failed.
failed_pod_type_name
instance-attribute
¶
Registered Pod type name where resolution failed.
dependency_parameter_name
instance-attribute
¶
Dependency parameter that could not be resolved, when applicable.
requested_type_name
instance-attribute
¶
Requested dependency type name that failed, when applicable.
path
instance-attribute
¶
Dependency path from the root Pod to the failure point.
candidates = ()
class-attribute
instance-attribute
¶
Candidate Pods involved in an ambiguity, when applicable.
resolution_hints = ()
class-attribute
instance-attribute
¶
Stable human-readable actions that can resolve the failure.
as_detail_pairs()
¶
Return stable key/value details for report adapters.
Source code in core/spakky/src/spakky/core/pod/diagnostics.py
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[T]
|
The type of Pod to retrieve. |
required |
name
|
str | None
|
Optional name qualifier. |
None
|
Returns:
| Type | Description |
|---|---|
object | T
|
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
¶
Interface and errors for Pod container interface.
This module defines the IContainer protocol for managing Pod lifecycle and dependency injection.
CircularDependencyGraphDetectedError(dependency_chain, dependency_diagnostic=None)
¶
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 |
dependency_diagnostic
|
PodDependencyResolutionDiagnostic | None
|
Optional structured dependency path details. |
None
|
Source code in core/spakky/src/spakky/core/pod/interfaces/container.py
NoSuchPodError
¶
NoUniquePodError(requested_type, candidates, dependency_diagnostic=None, resolution_hints=())
¶
Bases: AbstractSpakkyPodError
Raised when multiple Pods match criteria without clear qualification.
Initialize ambiguity details.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
requested_type
|
type
|
Dependency type requested by the caller. |
required |
candidates
|
tuple[PodCandidateDiagnostic, ...]
|
Candidate Pods that matched the requested type. |
required |
dependency_diagnostic
|
PodDependencyResolutionDiagnostic | None
|
Optional structured dependency path. |
None
|
resolution_hints
|
tuple[str, ...]
|
Actions that can make the selection explicit. |
()
|
Source code in core/spakky/src/spakky/core/pod/interfaces/container.py
InvalidPodBindingError
¶
Bases: AbstractSpakkyPodError
Raised when a binding policy does not identify exactly one target kind.
NoSuchPodBindingTargetError(binding)
¶
Bases: AbstractSpakkyPodError
Raised when an explicit binding does not match any candidate Pod.
Initialize binding target details.
Source code in core/spakky/src/spakky/core/pod/interfaces/container.py
PodBindingNotSupportedError
¶
CannotRegisterNonPodObjectError
¶
PodNameAlreadyExistsError
¶
IContainer
¶
Bases: ABC
Interface 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 |
bind(binding)
¶
Register an explicit interface-to-implementation binding policy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
binding
|
PodBinding
|
Binding value supplied by application or feature config. |
required |
Source code in core/spakky/src/spakky/core/pod/interfaces/container.py
bind_to_type(interface, implementation)
¶
bind_to_name(interface, name)
¶
get(type_, name=None)
abstractmethod
¶
Get a Pod instance by type and optional name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type_
|
type[T]
|
The type to retrieve. |
required |
name
|
str | None
|
Optional name qualifier. |
None
|
Returns:
| Type | Description |
|---|---|
T | object
|
The Pod instance. |
Source code in core/spakky/src/spakky/core/pod/interfaces/container.py
get_or_none(type_, name=None)
abstractmethod
¶
Get a Pod instance by type and optional name, or None if not found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type_
|
type[T]
|
The type to retrieve. |
required |
name
|
str | None
|
Optional name qualifier. |
None
|
Returns:
| Type | Description |
|---|---|
T | None
|
The Pod instance, or None if no matching Pod found. |
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
¶
Interface 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
Interface 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(startup_phase_recorder=None)
abstractmethod
¶
Start the application context and all services.
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
¶
Interface for Pod post-processors.
This module defines the IPostProcessor protocol for transforming Pod instances after creation but before use.
IPostProcessor
¶
Bases: ABC
Interface 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.interfaces.aware.aware
¶
Base protocol for aware interfaces.
This module defines the base IAware marker protocol for dependency injection of framework services into Pods.
IAware
¶
Bases: ABC
Marker protocol for Pods that require framework service injection.
Implementing this protocol allows Pods to receive framework services like logger, container, or application context through setter injection.
options: show_root_heading: false
spakky.core.pod.interfaces.aware.application_context_aware
¶
Interface for application context injection.
This module defines IApplicationContextAware for Pods that need access to the application context.
IApplicationContextAware
¶
Bases: IAware, ABC
Interface for Pods requiring application context injection.
Pods implementing this protocol will have set_application_context() called during post-processing with the current application context.
set_application_context(application_context)
abstractmethod
¶
Inject application context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
application_context
|
IApplicationContext
|
The application context instance. |
required |
Source code in core/spakky/src/spakky/core/pod/interfaces/aware/application_context_aware.py
options: show_root_heading: false
spakky.core.pod.interfaces.aware.container_aware
¶
Interface for container injection.
This module defines IContainerAware for Pods that need access to the IoC container.
IContainerAware
¶
Bases: IAware, ABC
Interface for Pods requiring container injection.
Pods implementing this protocol will have set_container() called during post-processing with the IoC container instance.
set_container(container)
abstractmethod
¶
Inject container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
container
|
IContainer
|
The IoC container instance. |
required |
options: show_root_heading: false
spakky.core.pod.interfaces.aware.tag_registry_aware
¶
Interface for container injection.
This module defines IContainerAware for Pods that need access to the IoC container.
ITagRegistryAware
¶
Bases: IAware, ABC
Interface for Pods requiring tag registry injection.
Pods implementing this protocol will have set_tag_registry() called during post-processing with the tag registry instance.
set_tag_registry(tag_registry)
abstractmethod
¶
Inject tag registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tag_registry
|
ITagRegistry
|
The tag registry instance. |
required |
options: show_root_heading: false
spakky.core.pod.post_processors.aware_post_processor
¶
Post-processor for injecting framework services into aware Pods.
This module provides ApplicationContextAwareProcessor which injects container and application context into Pods implementing aware interfaces.
ApplicationContextAwareProcessor(application_context)
¶
Bases: IPostProcessor
Post-processor for injecting framework services into aware Pods.
Checks if Pods implement aware interfaces and injects corresponding services: - IContainerAware: Injects IoC container - IApplicationContextAware: Injects application context
Initialize aware post-processor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
application_context
|
IApplicationContext
|
The application context to inject. |
required |
Source code in core/spakky/src/spakky/core/pod/post_processors/aware_post_processor.py
post_process(pod)
¶
Inject framework services into aware Pods.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pod
|
object
|
The Pod instance to process. |
required |
Returns:
| Type | Description |
|---|---|
object
|
The Pod instance with injected services. |
Source code in core/spakky/src/spakky/core/pod/post_processors/aware_post_processor.py
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.interfaces.service
¶
Interfaces for application services with lifecycle management.
This module defines interfaces for services that run during application lifecycle with start and stop capabilities.
IService
¶
IAsyncService
¶
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.
Source code in core/spakky/src/spakky/core/service/background.py
stop()
¶
Stop service and wait for thread to finish.
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.
Source code in core/spakky/src/spakky/core/service/background.py
stop_async()
async
¶
Stop service and wait for task to finish.
Source code in core/spakky/src/spakky/core/service/background.py
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
스테레오타입¶
spakky.core.stereotype.configuration
¶
Configuration stereotype for organizing configuration Pods.
This module provides @Configuration stereotype for grouping related configuration and factory method 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.).
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.
options: show_root_heading: false
공통¶
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[T]
|
The class to annotate. |
required |
Returns:
| Type | Description |
|---|---|
type[T]
|
The annotated class. |
FunctionAnnotation()
dataclass
¶
Bases: Annotation
Annotation for functions.
__call__(obj)
¶
Call method to annotate a function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Callable[..., T]
|
The function to annotate. |
required |
Returns:
| Type | Description |
|---|---|
Callable[..., T]
|
The annotated function. |
Source code in core/spakky/src/spakky/core/common/annotation.py
AnnotationNotFoundError
¶
MultipleAnnotationFoundError
¶
Bases: AbstractSpakkyFrameworkError
Exception raised when multiple annotations are found in an object.
options: show_root_heading: false
spakky.core.common.constants
¶
Core constants for Spakky framework.
options: show_root_heading: false
spakky.core.common.error
¶
AbstractSpakkyFrameworkError
¶
Bases: Exception, ABC
Base class for all Spakky framework errors.
The error message can be defined in two ways:
1. Class-level: Define message as a class attribute for a fixed message.
2. Instance-level: Pass message to the constructor to override the class default.
If neither is provided, the message will be an empty string.
message
class-attribute
¶
A human-readable message describing the error.
GenericMROTypeError
¶
Bases: AbstractSpakkyFrameworkError
Raised when a non-type, non-generic-alias is passed to generic_mro.
options: show_root_heading: false
spakky.core.common.interfaces
¶
options: show_root_heading: false
spakky.core.common.interfaces.cloneable
¶
options: show_root_heading: false
spakky.core.common.interfaces.comparable
¶
IComparable
¶
Bases: ABC
Interface for comparable objects.
__lt__(__value)
abstractmethod
¶
Less than comparison.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
__value
|
Self
|
The value to compare against. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if self is less than __value, False otherwise. |
Source code in core/spakky/src/spakky/core/common/interfaces/comparable.py
__le__(__value)
abstractmethod
¶
Less than or equal comparison.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
__value
|
Self
|
The value to compare against. |
required |
Returns: bool: True if self is less than or equal to __value, False otherwise.
Source code in core/spakky/src/spakky/core/common/interfaces/comparable.py
__gt__(__value)
abstractmethod
¶
Greater than comparison.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
__value
|
Self
|
The value to compare against. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if self is greater than __value, False otherwise. |
Source code in core/spakky/src/spakky/core/common/interfaces/comparable.py
__ge__(__value)
abstractmethod
¶
Greater than or equal comparison.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
__value
|
Self
|
The value to compare against. |
required |
Returns: bool: True if self is greater than or equal to __value, False otherwise.
Source code in core/spakky/src/spakky/core/common/interfaces/comparable.py
options: show_root_heading: false
spakky.core.common.interfaces.disposable
¶
IDisposable
¶
Bases: ABC
Interface for disposable objects.
__enter__()
abstractmethod
¶
Enters the runtime context related to this object.
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
The object itself. |
__exit__(__exc_type, __exc_value, __traceback)
abstractmethod
¶
Exits the runtime context related to this object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
__exc_type
|
type[BaseException] | None
|
The exception type. |
required |
__exc_value
|
BaseException | None
|
The exception value. |
required |
__traceback
|
TracebackType | None
|
The traceback object. |
required |
Returns:
| Type | Description |
|---|---|
bool | None
|
bool | None: True if the exception was handled, False otherwise. |
Source code in core/spakky/src/spakky/core/common/interfaces/disposable.py
IAsyncDisposable
¶
Bases: ABC
Interface for asynchronously disposable objects.
__aenter__()
abstractmethod
async
¶
Asynchronously enters the runtime context related to this object.
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
The object itself. |
__aexit__(__exc_type, __exc_value, __traceback)
abstractmethod
async
¶
Asynchronously exits the runtime context related to this object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
__exc_type
|
type[BaseException] | None
|
The exception type. |
required |
__exc_value
|
BaseException | None
|
The exception value. |
required |
__traceback
|
TracebackType | None
|
The traceback object. |
required |
Returns:
| Type | Description |
|---|---|
bool | None
|
bool | None: True if the exception was handled, False otherwise. |
Source code in core/spakky/src/spakky/core/common/interfaces/disposable.py
options: show_root_heading: false
spakky.core.common.interfaces.equatable
¶
IEquatable
¶
Bases: ABC
Interface for equatable objects.
__eq__(__value)
abstractmethod
¶
Checks equality with another object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
__value
|
object
|
The object to compare with. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if equal, False otherwise. |
Source code in core/spakky/src/spakky/core/common/interfaces/equatable.py
__hash__()
abstractmethod
¶
options: show_root_heading: false
spakky.core.common.interfaces.representable
¶
IRepresentable
¶
Bases: ABC
Interface for representable objects.
__str__()
abstractmethod
¶
Returns the string representation of the object.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The string representation. |
__repr__()
abstractmethod
¶
Returns the official string representation of the object.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The official string representation. |
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
¶
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.mro
¶
Method Resolution Order (MRO) utilities for generic types.
This module provides utilities for computing MRO (Method Resolution Order) for generic types, including parameterized generics like list[int] or dict[str, Any].
generic_mro(tp)
¶
Compute the Method Resolution Order for a generic type.
Supports both regular classes and parameterized generic types (e.g., list[int]).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tp
|
Any
|
The type or generic alias to compute MRO for. |
required |
Returns:
| Type | Description |
|---|---|
list[Any]
|
list[type]: The method resolution order as a list of types. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If tp is not a type or generic alias. |
Source code in core/spakky/src/spakky/core/common/mro.py
is_family_with(tp, target)
¶
Check if a type is related to a target type through its MRO.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tp
|
Any
|
The type to check. |
required |
target
|
type[T]
|
The target type to look for in the MRO. |
required |
Returns:
| Type | Description |
|---|---|
TypeGuard[type[T]]
|
True if target is in tp's MRO, False otherwise. |
Source code in core/spakky/src/spakky/core/common/mro.py
options: show_root_heading: false
spakky.core.common.mutability
¶
Utilities for creating mutable and immutable dataclasses.
This module provides decorators that create dataclasses with predefined mutability settings.
mutable(cls)
¶
Decorator to create a mutable dataclass with keyword-only arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cls
|
type[T]
|
The class to transform into a mutable dataclass. |
required |
Returns:
| Type | Description |
|---|---|
type[T]
|
A mutable dataclass with frozen=False, kw_only=True, eq=False. |
Source code in core/spakky/src/spakky/core/common/mutability.py
immutable(cls)
¶
Decorator to create an immutable dataclass with keyword-only arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cls
|
type[T]
|
The class to transform into an immutable dataclass. |
required |
Returns:
| Type | Description |
|---|---|
type[T]
|
An immutable dataclass with frozen=True, kw_only=True, eq=False. |
Source code in core/spakky/src/spakky/core/common/mutability.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
Interface 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)
¶
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
|
T
|
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:
| Type | Description |
|---|---|
T
|
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
로깅 인터페이스¶
spakky.core.logging.interfaces.log_context_binder
¶
ILogContextBinder — log context binding interface.
ILogContextBinder
¶
Bases: ABC
Interface for binding contextual key-value pairs to log records.
Implementations manage a context store (e.g., contextvars) that
structured logging filters can read from. Plugins that need to
enrich log records (such as spakky-opentelemetry) depend on this
interface instead of importing a concrete LogContext class
directly, keeping plugin-to-plugin dependencies out of the graph.
bind(**kwargs)
abstractmethod
¶
Add key-value pairs to the current log context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
str
|
Key-value pairs to bind. |
{}
|
unbind(*keys)
abstractmethod
¶
Remove keys from the current log context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*keys
|
str
|
Keys to remove. |
()
|
options: show_root_heading: false
유틸리티¶
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