super-solid-system 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,494 @@
1
+ Metadata-Version: 2.4
2
+ Name: super-solid-system
3
+ Version: 1.0.0
4
+ Summary: A lightweight, type-safe microkernel & plug-and-play framework for Python.
5
+ License-Expression: Apache-2.0
6
+ License-File: LICENSE
7
+ Keywords: microkernel,plugin,registry,modular,framework,dependency-injection,type-safe
8
+ Author: Doth-J
9
+ Author-email: theodjoan@gmail.com
10
+ Requires-Python: >=3.10
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
19
+ Classifier: Typing :: Typed
20
+ Requires-Dist: pydantic (>=2.0.0)
21
+ Project-URL: Homepage, https://github.com/Doth-J/super-solid-system
22
+ Project-URL: Issues, https://github.com/Doth-J/super-solid-system/issues
23
+ Project-URL: Repository, https://github.com/Doth-J/super-solid-system
24
+ Description-Content-Type: text/markdown
25
+
26
+ # Super-Solid System (`supersolid`)
27
+
28
+ <p align="center">
29
+ <img src="docs/logo.png" alt="Super-Solid" width="250"/>
30
+ </p>
31
+
32
+ <h1 align="center">Super-Solid System</h1>
33
+
34
+ <p align="center">
35
+ <strong>A robust, generic infrastructure for building modular software systems with plug-and-play engines, dynamic plugin discovery, thread-safe component registries, and fault-tolerant system lifecycle management.</strong><br/>
36
+ </p>
37
+
38
+ <p align="center">
39
+ <img alt="Python" src="https://img.shields.io/badge/python-%3E%3D3.10-blue?logo=python&logoColor=white"/>
40
+ <img alt="License" src="https://img.shields.io/badge/license-Apache%202.0-green"/>
41
+ <img alt="Tests" src="https://img.shields.io/badge/tests-43%2F43%20passing-brightgreen"/>
42
+ <img alt="Coverage" src="https://img.shields.io/badge/coverage-100%25-brightgreen"/>
43
+ <img alt="Status" src="https://img.shields.io/badge/status-v1.0.0-brightgreen"/>
44
+ </p>
45
+
46
+ > A lightweight, type-safe microkernel & plug-and-play framework for Python.
47
+
48
+ ## What is Super-Solid System?
49
+
50
+ Super-Solid System (`S³`) gives you a small set of building blocks for assembling modular applications:
51
+
52
+ - **Registries** hold your components — type-checked, thread-safe, and cached.
53
+ - **Engines** group registries together and handle boot/shutdown logic.
54
+ - **Systems** orchestrate engines in dependency order with automatic rollback.
55
+ - **Events** let everything talk to each other through a reactive signal bus.
56
+ - **Security** controls who can load what and from where.
57
+ - **Health** provides a standard way for components to report their status.
58
+
59
+ No magic, no hidden state, no framework lock-in. Just clean abstractions you subclass and wire up.
60
+
61
+ ## Architecture
62
+
63
+ ```mermaid
64
+ graph TD
65
+ S["SuperSolidSystem"]
66
+ EB["SuperSolidEventBus"]
67
+ E1["SuperSolidEngine A"]
68
+ E2["SuperSolidEngine B"]
69
+ R1["SuperSolidRegistry 1"]
70
+ R2["SuperSolidRegistry 2"]
71
+ R3["SuperSolidRegistry 3"]
72
+ D["DiscoveryStrategy Chain"]
73
+ SP["SecurityPolicy"]
74
+ H["HealthCheckable"]
75
+
76
+ S -->|starts / stops| E1
77
+ S -->|starts / stops| E2
78
+ S -->|publishes signals| EB
79
+ E1 -->|routes loads to| R1
80
+ E1 -->|routes loads to| R2
81
+ E2 -->|routes loads to| R3
82
+ R1 -->|discovers plugins via| D
83
+ R1 -.->|enforced by| SP
84
+ R2 -.->|enforced by| SP
85
+ E1 -.->|implements| H
86
+ E2 -.->|implements| H
87
+ ```
88
+
89
+ The core loop is simple:
90
+
91
+ 1. **Register** component classes into typed registries (or let discovery find them).
92
+ 2. **Load** components on demand — the registry instantiates, caches, and returns them.
93
+ 3. **Wire** registries into engines, engines into a system, and call `start()`.
94
+
95
+ ## Installation
96
+
97
+ ### Pip (editable, for development)
98
+
99
+ ```bash
100
+ pip install -e /path/to/super-solid-system
101
+ ```
102
+
103
+ ### Poetry (as a local dependency)
104
+
105
+ ```bash
106
+ poetry add --editable /path/to/super-solid-system
107
+ ```
108
+
109
+ ### Docker (Multi-stage build)
110
+
111
+ ```bash
112
+ # Build the production Docker image
113
+ docker build -t super-solid-system:latest .
114
+
115
+ # Run container & verify installation
116
+ docker run --rm super-solid-system:latest
117
+ ```
118
+
119
+ ## Quickstart
120
+
121
+ ### 1. Define a base interface and a registry
122
+
123
+ ```python
124
+ from abc import ABC, abstractmethod
125
+ from supersolid.core import super_solid_registry, SuperSolidRegistry
126
+
127
+ class BaseAdapter(ABC):
128
+ @abstractmethod
129
+ def connect(self) -> None: ...
130
+
131
+ # [QUICK] Create a typed component registry using super_solid_registry
132
+ Adapters = super_solid_registry(name="adapters", component_class=BaseAdapter)
133
+
134
+ # [ALTERNATIVE] Create a class component registry by subclassing SuperSolidRegistry
135
+ class AdapterRegistry(SuperSolidRegistry[BaseAdapter]):
136
+ def __init__(self):
137
+ super().__init__(name="adapters", component_class=BaseAdapter)
138
+
139
+ Adapters = AdapterRegistry()
140
+ ```
141
+
142
+ `SuperSolidRegistry` is generic — it enforces that only `BaseAdapter` subclasses can be registered here. Anything else raises a `TypeError` at registration time.
143
+
144
+ ### 2. Register components
145
+
146
+ You can register manually:
147
+
148
+ ```python
149
+ Adapters.register("database", "sqlite", SqliteAdapter)
150
+ ```
151
+
152
+ Or use the `@super_solid_component` decorator for a more declarative style:
153
+
154
+ ```python
155
+ from supersolid.core import super_solid_component
156
+
157
+ @super_solid_component(Adapters, namespace="database", name="postgres", version="1.0.0")
158
+ class PostgresAdapter(BaseAdapter):
159
+ def __init__(self, dsn: str = "postgresql://localhost/db"):
160
+ self.dsn = dsn
161
+
162
+ def connect(self) -> None:
163
+ print(f"Connected to {self.dsn}")
164
+
165
+ def disconnect(self) -> None:
166
+ print("Disconnected.")
167
+ ```
168
+
169
+ The decorator registers the class and attaches a `ComponentMetadata` model you can inspect later:
170
+
171
+ ```python
172
+ PostgresAdapter._metadata.version # "1.0.0"
173
+ PostgresAdapter._metadata.namespace # "database"
174
+ ```
175
+
176
+ ### 3. Load components
177
+
178
+ ```python
179
+ db = Adapters.load("database", "postgres", dsn="postgresql://prod/mydb")
180
+ db.connect() # Connected to postgresql://prod/mydb
181
+ ```
182
+
183
+ What happens under the hood:
184
+
185
+ 1. Checks the cache — if already loaded with the same parameters, returns the cached instance.
186
+ 2. If not registered, runs the **discovery chain** (more on that below).
187
+ 3. Introspects the constructor signature and filters keyword arguments automatically.
188
+ 4. Calls lifecycle hooks (`initialize()` or `boot()`) if the component defines them.
189
+ 5. Caches and returns the instance.
190
+
191
+ When you're done:
192
+
193
+ ```python
194
+ Adapters.unload("database", "postgres")
195
+ # Calls disconnect() or stop() automatically if the component defines them
196
+ ```
197
+
198
+ ### 4. Build an engine
199
+
200
+ A `SuperSolidEngine` groups registries and provides a unified loading interface:
201
+
202
+ ```python
203
+ from supersolid.core import SuperSolidEngine
204
+
205
+ class CoreEngine(SuperSolidEngine):
206
+ def __init__(self):
207
+ super().__init__()
208
+ self.connect(Adapters) # attach registries
209
+
210
+ def boot(self, **kwargs) -> None:
211
+ self._running = True
212
+ db = self.load("adapters", "database", "postgres")
213
+ db.connect()
214
+
215
+ def mount(self, app, **kwargs) -> None:
216
+ pass # hook for attaching to a web framework, etc.
217
+
218
+ def shutdown(self, **kwargs) -> None:
219
+ self._running = False
220
+ ```
221
+
222
+ Need async? Subclass `SuperSolidAsyncEngine` instead — it provides `boot_async()`, `mount_async()`, and `shutdown_async()` that automatically bridge to the sync interface via `asyncio.run()`.
223
+
224
+ ### 5. Orchestrate with a system
225
+
226
+ ```python
227
+ from supersolid.core import SuperSolidSystem
228
+
229
+ class MyApp(SuperSolidSystem):
230
+ pass
231
+
232
+ app = MyApp()
233
+ app.add_engine("core", CoreEngine())
234
+ app.start() # boots engines in dependency order
235
+ # ... your app runs ...
236
+ app.stop() # shuts down in reverse order
237
+ ```
238
+
239
+ If any engine fails during `start()`, all previously booted engines are shut down in reverse (LIFO) order automatically.
240
+
241
+ ## Engine Dependencies (Dependency Resolution)
242
+
243
+ Engines can declare dependencies on other engines:
244
+
245
+ ```python
246
+ class ConsensusEngine(SuperSolidEngine):
247
+ depends_on = ["network"] # boot network engine first
248
+ # ...
249
+
250
+ class NetworkEngine(SuperSolidEngine):
251
+ depends_on = []
252
+ # ...
253
+
254
+ system = MyApp()
255
+ system.add_engine("consensus", ConsensusEngine())
256
+ system.add_engine("network", NetworkEngine())
257
+ system.start()
258
+ # Boot order: network → consensus (resolved via topological sort)
259
+ ```
260
+
261
+ The system uses the internal `graphlibs` `TopologicalSorter` so circular dependencies raise a `CycleError` immediately.
262
+
263
+ ## Events
264
+
265
+ `SuperSolidSystem` comes with a built-in `SuperSolidEventBus` that publishes lifecycle signals automatically:
266
+
267
+ | Event | When it fires |
268
+ | :-------------------- | :--------------------------------- |
269
+ | `EngineBootingEvent` | Right before an engine boots |
270
+ | `EngineBootedEvent` | After an engine boots successfully |
271
+ | `EngineShutdownEvent` | After an engine shuts down |
272
+ | `SystemErrorEvent` | On boot failure or shutdown error |
273
+ | `PluginLoadedEvent` | When a plugin is loaded |
274
+
275
+ ### Subscribing to events
276
+
277
+ ```python
278
+ from supersolid.core import SuperSolidEventBus, EngineBootedEvent, super_solid_subscriber
279
+
280
+ bus = SuperSolidEventBus()
281
+
282
+ @super_solid_subscriber(bus)
283
+ def on_boot(event: EngineBootedEvent):
284
+ print(f"Engine '{event.engine_name}' is up!")
285
+ ```
286
+
287
+ The decorator infers the event type from the parameter annotation. You can also be explicit:
288
+
289
+ ```python
290
+ @super_solid_subscriber(bus, event_type=EngineBootedEvent)
291
+ def on_boot(event):
292
+ print(f"Engine '{event.engine_name}' is up!")
293
+ ```
294
+
295
+ ### Publishing events
296
+
297
+ The `@super_solid_publisher` decorator auto-publishes a function's return value if it's a `SystemEvent`:
298
+
299
+ ```python
300
+ from supersolid.core import super_solid_publisher, EngineBootedEvent
301
+
302
+ @super_solid_publisher(bus)
303
+ def finish_boot(name: str) -> EngineBootedEvent:
304
+ # ... do boot work ...
305
+ return EngineBootedEvent(engine_name=name)
306
+
307
+ finish_boot("consensus") # automatically published to bus
308
+ ```
309
+
310
+ Works with both sync and async functions.
311
+
312
+ ### Custom events
313
+
314
+ All events are Pydantic models with `extra = "allow"`, so you can add any fields:
315
+
316
+ ```python
317
+ from supersolid.core import SystemEvent
318
+
319
+ class NodeSyncEvent(SystemEvent):
320
+ node_id: str
321
+ epoch: int
322
+
323
+ # Extra fields work too — they serialize to JSON just fine
324
+ event = NodeSyncEvent(node_id="node_01", epoch=42, custom_field="whatever")
325
+ event.model_dump_json()
326
+ ```
327
+
328
+ ## Plugin Discovery
329
+
330
+ When you call `registry.load()` for something that isn't registered yet, the registry runs a **discovery chain** to try to find it automatically. The default chain has three strategies:
331
+
332
+ ```mermaid
333
+ graph LR
334
+ A["InternalLib"] -->|not found| B["EntryPoints"]
335
+ B -->|not found| C["PluginDirectory"]
336
+ style A fill:#4a9,stroke:#333,color:#fff
337
+ style B fill:#49a,stroke:#333,color:#fff
338
+ style C fill:#a94,stroke:#333,color:#fff
339
+ ```
340
+
341
+ | Strategy | Where it looks |
342
+ | :---------------- | :------------------------------------------------------------------------ |
343
+ | `InternalLib` | `{root_pkg}.lib.{registry_name}.{namespace}_{name}` (trusted imports) |
344
+ | `EntryPoints` | Setuptools entry points in group `{root_pkg}.{registry_name}.{namespace}` |
345
+ | `PluginDirectory` | `plugins.{registry_name}.{namespace}_{name}` (local files) |
346
+
347
+ ### Writing a custom discovery strategy
348
+
349
+ ```python
350
+ from supersolid.core import DiscoveryStrategy
351
+
352
+ class RemoteDiscovery(DiscoveryStrategy):
353
+ def discover(self, registry, item_namespace, item_name) -> bool:
354
+ # fetch plugin from remote source, register it
355
+ return registry.is_registered(item_namespace, item_name)
356
+
357
+ Adapters.add_discovery(RemoteDiscovery())
358
+ ```
359
+
360
+ ## Security
361
+
362
+ ### SecurityPolicy
363
+
364
+ Attach a `SecurityPolicy` to any registry to control access:
365
+
366
+ ```python
367
+ from supersolid.core import SecurityPolicy
368
+
369
+ policy = SecurityPolicy(
370
+ allowed_namespaces={"database", "cache"}, # only these namespaces can be loaded
371
+ allowed_callers={"core_engine"}, # only these caller IDs are authorized
372
+ allow_internal_lib=True, # trusted internal imports still work
373
+ allow_dynamic_discovery=False, # block external plugins (EntryPoints, PluginDirectory)
374
+ )
375
+
376
+ Adapters.set_policy(policy)
377
+ ```
378
+
379
+ Now `Adapters.load("auth", "oauth")` raises `PermissionError` because `"auth"` isn't in the allowed set. And external discovery strategies are skipped entirely, while `InternalLib` still runs as a trusted fallback.
380
+
381
+ ### Plugin verification
382
+
383
+ Before importing a plugin file, you can verify its checksum:
384
+
385
+ ```python
386
+ from supersolid.core import PluginVerifier
387
+
388
+ if PluginVerifier.verify_sha256("plugins/consensus/my_plugin.py", expected_hash):
389
+ import plugins.consensus.my_plugin
390
+ ```
391
+
392
+ ## Health Checks
393
+
394
+ Any component can implement health reporting by defining a `health_check()` method:
395
+
396
+ ```python
397
+ from supersolid.core import HealthStatus, HealthState, HealthCheckable
398
+
399
+ class DatabaseAdapter:
400
+ def health_check(self) -> HealthStatus:
401
+ return HealthStatus(
402
+ state=HealthState.HEALTHY,
403
+ details={"connections": 42, "pool_size": 100}
404
+ )
405
+
406
+ db = DatabaseAdapter()
407
+ isinstance(db, HealthCheckable) # True — structural typing via Protocol
408
+ db.health_check().model_dump_json()
409
+ # {"state": "healthy", "details": {"connections": 42, "pool_size": 100}, "timestamp": ...}
410
+ ```
411
+
412
+ `HealthCheckable` is a `@runtime_checkable` Protocol — no need to inherit from anything.
413
+
414
+ The three states are `HEALTHY`, `DEGRADED`, and `UNHEALTHY`.
415
+
416
+ ## Project Structure
417
+
418
+ ```
419
+ super-solid-system/
420
+ ├── supersolid/
421
+ │ └── core/
422
+ │ ├── __init__.py # Public API exports
423
+ │ ├── registry.py # SuperSolidRegistry, super_solid_component, ComponentMetadata
424
+ │ ├── engine.py # SuperSolidEngine, AsyncSuperSolidEngine
425
+ │ ├── system.py # SuperSolidSystem (orchestrator)
426
+ │ ├── events.py # SuperSolidEventBus, SystemEvent, super_solid_subscriber, super_solid_publisher
427
+ │ ├── discovery.py # DiscoveryStrategy, InternalLib, EntryPoints, PluginDirectory
428
+ │ ├── security.py # SecurityPolicy, PluginVerifier
429
+ │ └── health.py # HealthStatus, HealthState, HealthCheckable
430
+ ├── tests/
431
+ │ ├── test_registry.py # Registration, loading, type enforcement, thread safety, unload
432
+ │ ├── test_events.py # Event bus pub/sub, @open_subscriber, @open_publisher
433
+ │ ├── test_security.py # Namespace ACL, caller auth, discovery fallbacks, SHA-256
434
+ │ ├── test_health.py # Health models, Protocol duck typing
435
+ │ └── test_system.py # DAG resolution, start/stop, rollback on failure
436
+ ├── pyproject.toml
437
+ ├── LICENSE
438
+ └── README.md
439
+ ```
440
+
441
+ ---
442
+
443
+ ## API Reference
444
+
445
+ | Export | Module | What it does |
446
+ | :----------------------- | :--------------- | :----------------------------------------------------------------------------------------------- |
447
+ | `SuperSolidSystem` | `core.system` | Orchestrator — boots/stops engines in dependency order (`SolidSystem`, `OpenSystem`) |
448
+ | `SuperSolidEngine` | `core.engine` | Domain hub — groups registries, handles boot/mount/shutdown (`SolidEngine`, `OpenEngine`) |
449
+ | `SuperSolidAsyncEngine` | `core.engine` | Async variant supporting `boot_async()`, `mount_async()` (`SolidAsyncEngine`, `AsyncOpenEngine`) |
450
+ | `SuperSolidRegistry` | `core.registry` | Generic registry — type checks, caching, discovery (`SolidRegistry`, `OpenRegistry`) |
451
+ | `super_solid_registry` | `core.registry` | Factory function — instantiates a `SuperSolidRegistry` (`solid_registry`, `open_registry`) |
452
+ | `super_solid_component` | `core.registry` | Decorator — registers a class with metadata (`solid_component`, `open_component`) |
453
+ | `ComponentMetadata` | `core.registry` | Pydantic model — name, namespace, version, and extras |
454
+ | `SuperSolidEventBus` | `core.events` | In-memory pub/sub signal bus (`SolidEventBus`, `OpenEventBus`) |
455
+ | `SystemEvent` | `core.events` | Base event model (Pydantic, extra fields allowed) |
456
+ | `super_solid_subscriber` | `core.events` | Decorator — subscribes handler with type inference (`solid_subscriber`, `open_subscriber`) |
457
+ | `super_solid_publisher` | `core.events` | Decorator — auto-publishes return values (`solid_publisher`, `open_publisher`) |
458
+ | `DiscoveryStrategy` | `core.discovery` | Abstract base — subclass to write custom plugin discovery |
459
+ | `SecurityPolicy` | `core.security` | Pydantic model — namespace/caller ACL, discovery toggles |
460
+ | `PluginVerifier` | `core.security` | SHA-256 file checksum verification |
461
+ | `HealthStatus` | `core.health` | Pydantic model — state, details, timestamp |
462
+ | `HealthState` | `core.health` | Enum — `HEALTHY`, `DEGRADED`, `UNHEALTHY` |
463
+ | `HealthCheckable` | `core.health` | Protocol — any class with `health_check()` satisfies it |
464
+
465
+ ## Running Tests
466
+
467
+ Run the test suite with coverage report:
468
+
469
+ ```bash
470
+ poetry run python -m pytest --cov=supersolid --cov-report=term-missing
471
+ ```
472
+
473
+ ```text
474
+ Name Stmts Miss Cover
475
+ --------------------------------------------------
476
+ supersolid/__init__.py 2 0 100%
477
+ supersolid/core/__init__.py 8 0 100%
478
+ supersolid/core/discovery.py 43 0 100%
479
+ supersolid/core/engine.py 49 0 100%
480
+ supersolid/core/events.py 85 0 100%
481
+ supersolid/core/health.py 14 0 100%
482
+ supersolid/core/registry.py 154 0 100%
483
+ supersolid/core/security.py 24 0 100%
484
+ supersolid/core/system.py 59 0 100%
485
+ --------------------------------------------------
486
+ TOTAL 438 0 100%
487
+
488
+ ============================= 43 passed in 1.12s ==============================
489
+ ```
490
+
491
+ ## License
492
+
493
+ [Apache-2.0](LICENSE)
494
+
@@ -0,0 +1,14 @@
1
+ supersolid/__init__.py,sha256=TAxMvzzecHUbYSemZ7gBbqi-3hYmsODLKrbmxrtbaUQ,66
2
+ supersolid/core/__init__.py,sha256=r_Y23AMaiGR9hMOBVmdjHncFgqL56450IpybRYCIVpo,2215
3
+ supersolid/core/discovery.py,sha256=2DckYCntYygrtwi3JWt3Ng7rwd3DE8ksUGZjqula76U,3121
4
+ supersolid/core/engine.py,sha256=FM4k8HwTIGsWhtAwA4j7EzIZgbKKTqzniTVaQoH57i0,2953
5
+ supersolid/core/events.py,sha256=a0tdo6QxDxeL4Uh8LU8_GxayG5yJlDOdMrHb6l2idDo,5113
6
+ supersolid/core/health.py,sha256=_LHJ7XkJC-XPj7c_-nljI_hbmBo-4K_OAbCwcXWJtys,645
7
+ supersolid/core/registry.py,sha256=-HzZbAgSg0oCbMETTeI-9mMnXoDnS472QT6is42rSxc,12385
8
+ supersolid/core/security.py,sha256=z_gxD6MmK9ezDvr3Z3-vNwp9jtUYVybGda8ZkQdX0h4,1552
9
+ supersolid/core/system.py,sha256=qp8i89De-yvDIPHfS1VdDa2GmryaaM-ePCOQTFd3zCM,3582
10
+ supersolid/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
11
+ super_solid_system-1.0.0.dist-info/licenses/LICENSE,sha256=RDdfqrM-83IWtxhQDdgDcVdy5cZPFNT6UVqii57QPJA,11131
12
+ super_solid_system-1.0.0.dist-info/METADATA,sha256=ZqhQqfBq5hsTr7nM57w-KGiUQvMPZbkXzM6Gc_X7ubE,18574
13
+ super_solid_system-1.0.0.dist-info/WHEEL,sha256=EGEvSphFYqXKs23-kQBeyNoJP1nrT8ZJKQoi5p5DYL8,88
14
+ super_solid_system-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: poetry-core 2.4.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any