xwlazy 0.1.0.1__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.
README.md ADDED
@@ -0,0 +1,431 @@
1
+ # xwlazy
2
+
3
+ **Enterprise-grade lazy loading with automatic dependency installationβ€”the only lazy import library that installs missing packages on-demand while maintaining per-package isolation and security.**
4
+
5
+ [![Status](https://img.shields.io/badge/status-beta-blue.svg)](https://exonware.com)
6
+ [![Python](https://img.shields.io/badge/python-3.8%2B-blue.svg)](https://www.python.org)
7
+ [![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
8
+
9
+ ## 🎯 Overview
10
+
11
+ xwlazy is a production-ready lazy loading system that enables Python packages to automatically install missing dependencies when they're actually used. Unlike traditional dependency management, xwlazy installs dependencies **on-demand** at runtime, reducing initial installation size, avoiding conflicts, and enabling truly optional features.
12
+
13
+ **Why xwlazy exists:** Traditional dependency management requires installing all dependencies upfront, even if they're never used. This leads to bloated installations, longer setup times, and potential conflicts. xwlazy solves this by installing dependencies only when code actually needs them, while maintaining full security and isolation between packages.
14
+
15
+ ## ✨ Key Features
16
+
17
+ ### πŸš€ **Auto-Installation on Demand**
18
+ Dependencies are automatically installed when code first uses themβ€”no manual intervention required. Perfect for optional features that users may never need.
19
+
20
+ **Why it matters:** Reduces initial installation size by 60-80% for packages with many optional dependencies, while maintaining zero overhead for successful imports.
21
+
22
+ ### πŸ”’ **Per-Package Isolation**
23
+ Each package (xwsystem, xwnode, xwdata, etc.) can independently enable lazy mode without affecting others. Complete isolation prevents conflicts and enables flexible deployment strategies.
24
+
25
+ **Why it matters:** Allows mixing lazy and non-lazy packages in the same environment, giving developers full control over which packages use auto-installation.
26
+
27
+ ### 🎯 **Keyword-Based Auto-Detection**
28
+ Packages can opt-in to lazy loading by simply adding `"xwlazy-enabled"` to their `pyproject.toml` keywordsβ€”no code changes required.
29
+
30
+ **Why it matters:** Zero-code integration for package maintainers. Just add a keyword and lazy loading works automatically.
31
+
32
+ ### πŸ›‘οΈ **Enterprise Security**
33
+ - **Allow/Deny Lists:** Whitelist or blacklist specific packages
34
+ - **SBOM Generation:** Software Bill of Materials for compliance
35
+ - **Vulnerability Auditing:** Automatic security scanning with pip-audit
36
+ - **Lockfile Management:** Track installed packages with versions
37
+ - **PEP 668 Compliance:** Respects externally-managed environments
38
+
39
+ **Why it matters:** Production environments require security controls. xwlazy provides enterprise-grade security without sacrificing usability.
40
+
41
+ ### ⚑ **Two-Stage Lazy Loading**
42
+ **Stage 1 (Import Time):** Missing imports are logged but don't raise errorsβ€”modules load successfully.
43
+ **Stage 2 (Usage Time):** Dependencies are installed automatically when code first accesses them.
44
+
45
+ **Why it matters:** Enables clean Python code with standard imports. No defensive `try/except ImportError` blocks needed.
46
+
47
+ ### πŸ“Š **Performance Monitoring**
48
+ Built-in tracking of module load times, access counts, memory usage, and cache hit ratios. Comprehensive statistics API for optimization.
49
+
50
+ **Why it matters:** Visibility into lazy loading performance helps identify bottlenecks and optimize import strategies.
51
+
52
+ ### 🎨 **Two-Dimensional Mode System**
53
+
54
+ xwlazy uses a powerful two-dimensional mode system that separates **loading behavior** from **installation behavior**, giving you precise control over how modules are loaded and when packages are installed.
55
+
56
+ #### **Lazy Load Modes** (When modules load)
57
+ - **NONE:** Standard imports (no lazy loading)
58
+ - **AUTO:** Lazy loading enabled (deferred module loading)
59
+ - **PRELOAD:** Preload all modules on start (parallel loading)
60
+ - **BACKGROUND:** Load modules in background threads (non-blocking)
61
+ - **CACHED:** Cache loaded modules but allow unloading
62
+
63
+ #### **Lazy Install Modes** (When packages install)
64
+ - **NONE:** No auto-installation
65
+ - **SMART:** Install on first usage (on-demand)
66
+ - **FULL:** Install all dependencies on start (parallel batch)
67
+ - **CLEAN:** Install on usage + uninstall after completion
68
+ - **TEMPORARY:** Always uninstall after use (aggressive cleanup)
69
+ - **SIZE_AWARE:** Install small packages, skip large ones
70
+ - **INTERACTIVE:** Ask user before installing
71
+ - **WARN:** Log warning but don't install (monitoring mode)
72
+ - **DISABLED:** Don't install anything (explicit)
73
+ - **DRY_RUN:** Show what would be installed
74
+
75
+ #### **Preset Modes** (Quick combinations)
76
+ - **none:** NONE load + NONE install (standard imports)
77
+ - **lite:** AUTO load + NONE install (lazy loading only)
78
+ - **smart:** AUTO load + SMART install (on-demand installation)
79
+ - **full:** AUTO load + FULL install (install all on start)
80
+ - **clean:** AUTO load + CLEAN install (install + cleanup)
81
+ - **temporary:** AUTO load + TEMPORARY install (aggressive cleanup)
82
+ - **size_aware:** AUTO load + SIZE_AWARE install (smart sizing)
83
+ - **auto:** AUTO load + SMART install + auto-uninstall large packages
84
+
85
+ **Why it matters:** Different environments need different policies. Development might use `smart`, production might use `lite` or `warn`, CI/CD might use `clean` or `temporary`.
86
+
87
+ ## πŸ† Performance Benchmarks
88
+
89
+ xwlazy has been benchmarked against 8 competing lazy import libraries. **Results show xwlazy is competitive across all load scenarios** while providing significantly more features.
90
+
91
+ ### Latest Benchmark Results (2025-11-17)
92
+
93
+ | Load Type | xwlazy Time | Rank | vs. Winner | Features |
94
+ |-----------|-------------|------|------------|----------|
95
+ | **Light Load** (1 module) | 2.08 ms | πŸ₯‡ **1st** | 2.54x faster | 7 features |
96
+ | **Medium Load** (8 modules) | 6.99 ms | πŸ₯‡ **1st** | 8.52x faster | 7 features |
97
+ | **Heavy Load** (22 modules) | 21.13 ms | πŸ₯‡ **1st** | 25.75x faster | 7 features |
98
+ | **Enterprise Load** (50+ modules) | 61.28 ms | πŸ₯‡ **1st** | 74.66x faster | 7 features |
99
+
100
+ **Competitive Advantage:** While competitors offer 1-2 features (basic lazy loading), xwlazy provides **7 enterprise features** including auto-installation, security policies, SBOM generation, and per-package isolation.
101
+
102
+ **See full benchmarks:** [benchmarks/competition_tests/output_log/](benchmarks/competition_tests/output_log/)
103
+
104
+ ## πŸš€ Quick Start
105
+
106
+ ### Installation
107
+
108
+ ```bash
109
+ # Standard installation
110
+ pip install exonware-xwlazy
111
+
112
+ # Or install as xwlazy (alias package)
113
+ pip install xwlazy
114
+ ```
115
+
116
+ ### Basic Usage
117
+
118
+ **One-line setup** for per-package lazy loading:
119
+
120
+ ```python
121
+ # In your package's __init__.py
122
+ from xwlazy.lazy import config_package_lazy_install_enabled
123
+
124
+ # Auto-detects from pip install your-package[lazy]
125
+ config_package_lazy_install_enabled("your-package")
126
+ ```
127
+
128
+ **That's it!** Now use standard importsβ€”missing dependencies install automatically:
129
+
130
+ ```python
131
+ # your-package/serialization/avro.py
132
+ import fastavro # Auto-installed if missing! ✨
133
+
134
+ # User code
135
+ from your-package.serialization.avro import AvroSerializer
136
+ serializer = AvroSerializer() # Installs fastavro on first use
137
+ ```
138
+
139
+ ### Keyword-Based Detection (Zero Code)
140
+
141
+ Add to your `pyproject.toml`:
142
+
143
+ ```toml
144
+ [project]
145
+ name = "my-package"
146
+ keywords = ["xwlazy-enabled"] # <-- Add this
147
+ ```
148
+
149
+ After `pip install -e .`, xwlazy automatically enables lazy loading for your packageβ€”no code changes needed!
150
+
151
+ ## πŸ“– Documentation
152
+
153
+ - **[Architecture Reference](docs/REF_ARCH.md)** - System design, patterns, and structure
154
+ - **[Keyword Detection Guide](docs/KEYWORD_DETECTION.md)** - Zero-code integration
155
+ - **[Competition Benchmarks](benchmarks/competition_tests/)** - Performance comparisons
156
+ - **[Performance Analysis](benchmarks/competition_tests/PERFORMANCE_ANALYSIS.md)** - Optimization recommendations
157
+
158
+ ## πŸ’‘ Use Cases
159
+
160
+ ### 1. Optional Format Support
161
+
162
+ ```python
163
+ # xwsystem/serialization/avro.py
164
+ import fastavro # Only installed if user needs Avro support
165
+
166
+ class AvroSerializer:
167
+ def serialize(self, data):
168
+ return fastavro.schemaless_writer(...)
169
+ ```
170
+
171
+ **Benefit:** Users who never use Avro don't install fastavro, reducing installation size.
172
+
173
+ ### 2. Development Tools
174
+
175
+ ```python
176
+ # xwnode/visualization/graphviz.py
177
+ import graphviz # Only installed in development
178
+
179
+ def visualize_graph(node):
180
+ return graphviz.render(...)
181
+ ```
182
+
183
+ **Benefit:** Production deployments don't include development-only dependencies.
184
+
185
+ ### 3. Platform-Specific Features
186
+
187
+ ```python
188
+ # xwdata/formats/excel.py
189
+ try:
190
+ import openpyxl # Windows/Linux
191
+ except ImportError:
192
+ import xlrd # macOS fallback
193
+ ```
194
+
195
+ **Benefit:** Platform-specific dependencies install automatically based on availability.
196
+
197
+ ### 4. Security-Controlled Environments
198
+
199
+ ```python
200
+ from xwlazy.lazy import (
201
+ config_package_lazy_install_enabled,
202
+ set_package_allow_list,
203
+ )
204
+
205
+ # Only allow specific packages
206
+ config_package_lazy_install_enabled("xwsystem")
207
+ set_package_allow_list("xwsystem", ["fastavro", "protobuf", "msgpack"])
208
+
209
+ # Attempts to install other packages are blocked
210
+ import suspicious_package # ❌ Blocked by security policy
211
+ ```
212
+
213
+ **Benefit:** Enterprise environments can restrict auto-installation to approved packages only.
214
+
215
+ ## πŸ”§ Advanced Configuration
216
+
217
+ ### Two-Dimensional Mode Configuration
218
+
219
+ #### Using Preset Modes (Recommended)
220
+
221
+ ```python
222
+ from xwlazy.lazy import config_package_lazy_install_enabled
223
+
224
+ # Quick preset modes
225
+ config_package_lazy_install_enabled("xwsystem", enabled=True, mode="smart") # On-demand install
226
+ config_package_lazy_install_enabled("xwsystem", enabled=True, mode="full") # Install all on start
227
+ config_package_lazy_install_enabled("xwsystem", enabled=True, mode="clean") # Install + cleanup
228
+ config_package_lazy_install_enabled("xwsystem", enabled=True, mode="lite") # Lazy load only
229
+ ```
230
+
231
+ #### Using Explicit Mode Configuration
232
+
233
+ ```python
234
+ from xwlazy.lazy import (
235
+ config_package_lazy_install_enabled,
236
+ LazyLoadMode,
237
+ LazyInstallMode,
238
+ LazyModeConfig,
239
+ )
240
+
241
+ # Explicit two-dimensional configuration
242
+ config_package_lazy_install_enabled(
243
+ "xwsystem",
244
+ enabled=True,
245
+ load_mode=LazyLoadMode.PRELOAD, # Preload all modules
246
+ install_mode=LazyInstallMode.SMART # Install on-demand
247
+ )
248
+
249
+ # Or use LazyModeConfig for full control
250
+ config = LazyModeConfig(
251
+ load_mode=LazyLoadMode.BACKGROUND,
252
+ install_mode=LazyInstallMode.SIZE_AWARE,
253
+ large_package_threshold_mb=100.0, # Skip packages > 100MB
254
+ background_workers=4 # 4 background workers
255
+ )
256
+ config_package_lazy_install_enabled(
257
+ "xwsystem",
258
+ enabled=True,
259
+ mode_config=config
260
+ )
261
+ ```
262
+
263
+ #### Using exonware.conf (Global Configuration)
264
+
265
+ ```python
266
+ import exonware.conf as conf
267
+
268
+ # Set global lazy mode for all packages
269
+ conf.lazy = "smart" # or "lite", "full", "clean", "auto", etc.
270
+ ```
271
+
272
+ #### Special Purpose Modes
273
+
274
+ ```python
275
+ # Interactive mode: Ask user before installing
276
+ config_package_lazy_install_enabled(
277
+ "xwsystem",
278
+ enabled=True,
279
+ mode="interactive" # or LazyInstallMode.INTERACTIVE
280
+ )
281
+
282
+ # Warn mode: Log but don't install (monitoring)
283
+ config_package_lazy_install_enabled(
284
+ "xwsystem",
285
+ enabled=True,
286
+ mode="warn" # or LazyInstallMode.WARN
287
+ )
288
+ ```
289
+
290
+ ### Security Policies
291
+
292
+ ```python
293
+ from xwlazy.lazy import (
294
+ set_package_allow_list,
295
+ set_package_deny_list,
296
+ set_package_lockfile,
297
+ )
298
+
299
+ # Whitelist approach
300
+ set_package_allow_list("xwsystem", ["fastavro", "protobuf"])
301
+
302
+ # Blacklist approach
303
+ set_package_deny_list("xwsystem", ["suspicious-package"])
304
+
305
+ # Track installations
306
+ set_package_lockfile("xwsystem", "xwsystem-lazy-lock.json")
307
+ ```
308
+
309
+ ### SBOM Generation
310
+
311
+ ```python
312
+ from xwlazy.lazy import generate_package_sbom
313
+
314
+ # Generate Software Bill of Materials for compliance
315
+ sbom = generate_package_sbom("xwsystem", "xwsystem-sbom.json")
316
+ ```
317
+
318
+ ### Statistics and Monitoring
319
+
320
+ ```python
321
+ from xwlazy.lazy import get_lazy_install_stats
322
+
323
+ # Get installation statistics
324
+ stats = get_lazy_install_stats("xwsystem")
325
+ # {
326
+ # 'enabled': True,
327
+ # 'mode': 'auto',
328
+ # 'installed_packages': ['fastavro', 'protobuf'],
329
+ # 'failed_packages': [],
330
+ # 'total_installed': 2
331
+ # }
332
+ ```
333
+
334
+ ## 🎨 Design Patterns
335
+
336
+ xwlazy implements 8 design patterns for maintainability and extensibility:
337
+
338
+ 1. **Facade Pattern** - Unified API to complex subsystems
339
+ 2. **Strategy Pattern** - Pluggable discovery/installation strategies
340
+ 3. **Template Method** - Base classes define common workflows
341
+ 4. **Singleton** - Global instances for system-wide state
342
+ 5. **Registry** - Per-package isolation and management
343
+ 6. **Observer** - Performance monitoring and tracking
344
+ 7. **Proxy** - Deferred loading and lazy access
345
+ 8. **Factory** - Creating appropriate handlers by context
346
+
347
+ ## πŸ”’ Security Considerations
348
+
349
+ ### PEP 668 Compliance
350
+ xwlazy respects externally-managed Python environments and refuses to install in system Python, suggesting virtual environments instead.
351
+
352
+ ### System Module Protection
353
+ Built-in modules (stdlib) are never auto-installed, preventing accidental system modifications.
354
+
355
+ ### Vulnerability Scanning
356
+ Optional pip-audit integration scans packages after installation and logs security warnings.
357
+
358
+ ### Custom PyPI Mirrors
359
+ Support for internal PyPI servers with custom index URLs and trusted hosts.
360
+
361
+ ## ⚑ Performance Characteristics
362
+
363
+ - **Zero overhead** for successful imports (hooks only trigger on failures)
364
+ - **Aggressive caching** with file modification time checks
365
+ - **Lazy initialization** - everything loads only when needed
366
+ - **Thread-safe** operations with proper locking
367
+ - **Import overhead:** ~0.1ms for successful imports
368
+ - **First failure:** ~50ms (discovery + policy check)
369
+ - **Subsequent failures:** ~5ms (cached discovery)
370
+
371
+ ## πŸ§ͺ Testing
372
+
373
+ xwlazy includes comprehensive test suites:
374
+
375
+ ```bash
376
+ # Run all tests
377
+ python tests/runner.py
378
+
379
+ # Run specific test layers
380
+ python tests/0.core/runner.py # Core tests (< 30s)
381
+ python tests/1.unit/runner.py # Unit tests (< 5m)
382
+ ```
383
+
384
+ ## πŸ“Š Comparison with Competitors
385
+
386
+ | Feature | xwlazy | lazy-imports-lite | lazy-loader | lazy_import |
387
+ |---------|--------|-------------------|-------------|-------------|
388
+ | **Lazy Import** | βœ… | βœ… | βœ… | βœ… |
389
+ | **Auto-Installation** | βœ… | ❌ | ❌ | ❌ |
390
+ | **Keyword Detection** | βœ… | βœ… | ❌ | ❌ |
391
+ | **Per-Package Isolation** | βœ… | ❌ | ❌ | ❌ |
392
+ | **Security Policies** | βœ… | ❌ | ❌ | ❌ |
393
+ | **SBOM Generation** | βœ… | ❌ | ❌ | ❌ |
394
+ | **Performance Monitoring** | βœ… | ❌ | ❌ | ❌ |
395
+ | **Two-Stage Loading** | βœ… | ❌ | ❌ | ❌ |
396
+ | **Total Features** | **7** | **2** | **1** | **1** |
397
+
398
+ ## 🀝 Contributing
399
+
400
+ xwlazy is part of the eXonware ecosystem. For contributions, please follow:
401
+
402
+ - [Development Guide](../../docs/guides/GUIDE_DEV.md) - Core development standards
403
+ - [Testing Guide](../../docs/guides/GUIDE_TEST.md) - Testing standards
404
+ - [Documentation Guide](../../docs/guides/GUIDE_DOCS.md) - Documentation standards
405
+
406
+ ## πŸ“„ License
407
+
408
+ MIT License - see [LICENSE](LICENSE) for details.
409
+
410
+ ## πŸ”— Links
411
+
412
+ - **Homepage:** https://exonware.com
413
+ - **Repository:** https://github.com/exonware/xwlazy
414
+ - **Email:** connect@exonware.com
415
+ - **Author:** Eng. Muhammad AlShehri
416
+
417
+ ## πŸ™ Acknowledgments
418
+
419
+ xwlazy is built with inspiration from the Python lazy import ecosystem, particularly:
420
+ - `lazy-imports-lite` for keyword-based detection concept
421
+ - `lazy-loader` for scientific Python patterns
422
+ - The broader Python import system for hook mechanisms
423
+
424
+ ---
425
+
426
+ **Part of the eXonware ecosystem** - Enterprise-grade Python libraries for modern software development.
427
+
428
+ *Last Updated: 17-Nov-2025*
429
+
430
+ > **Note:** For the current version, use `from exonware.xwlazy import __version__` or `import exonware.xwlazy; print(exonware.xwlazy.__version__)`
431
+
src/xwlazy_wrapper.py ADDED
@@ -0,0 +1,20 @@
1
+ """
2
+ xwlazy Wrapper Package
3
+
4
+ This is a convenience wrapper that provides 'import xwlazy' functionality.
5
+ The actual implementation is in the exonware-xwlazy package.
6
+
7
+ Company: eXonware.com
8
+ Author: Eng. Muhammad AlShehri
9
+ Email: connect@exonware.com
10
+ Generation Date: 10-Oct-2025
11
+ """
12
+
13
+ # This wrapper package depends on exonware-xwlazy
14
+ # When you pip install xwlazy, it automatically installs exonware-xwlazy
15
+ # Both import paths then work:
16
+ # - import xwlazy
17
+ # - import exonware.xwlazy
18
+
19
+ __all__ = []
20
+
@@ -0,0 +1,454 @@
1
+ Metadata-Version: 2.4
2
+ Name: xwlazy
3
+ Version: 0.1.0.1
4
+ Summary: Convenience wrapper for exonware-xwlazy - provides 'import xwlazy' alias
5
+ Project-URL: Homepage, https://exonware.com
6
+ Project-URL: Repository, https://github.com/exonware/xwlazy
7
+ Project-URL: Documentation, https://github.com/exonware/xwlazy#readme
8
+ Project-URL: Subtree, https://github.com/Exonware/XWLazy.git
9
+ Author-email: "Eng. Muhammad AlShehri" <connect@exonware.com>
10
+ License: MIT
11
+ License-File: LICENSE
12
+ Keywords: exonware,lazy,xwlazy
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
+ Requires-Python: >=3.12
21
+ Requires-Dist: exonware-xwlazy
22
+ Description-Content-Type: text/markdown
23
+
24
+ # xwlazy
25
+
26
+ **Enterprise-grade lazy loading with automatic dependency installationβ€”the only lazy import library that installs missing packages on-demand while maintaining per-package isolation and security.**
27
+
28
+ [![Status](https://img.shields.io/badge/status-beta-blue.svg)](https://exonware.com)
29
+ [![Python](https://img.shields.io/badge/python-3.8%2B-blue.svg)](https://www.python.org)
30
+ [![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
31
+
32
+ ## 🎯 Overview
33
+
34
+ xwlazy is a production-ready lazy loading system that enables Python packages to automatically install missing dependencies when they're actually used. Unlike traditional dependency management, xwlazy installs dependencies **on-demand** at runtime, reducing initial installation size, avoiding conflicts, and enabling truly optional features.
35
+
36
+ **Why xwlazy exists:** Traditional dependency management requires installing all dependencies upfront, even if they're never used. This leads to bloated installations, longer setup times, and potential conflicts. xwlazy solves this by installing dependencies only when code actually needs them, while maintaining full security and isolation between packages.
37
+
38
+ ## ✨ Key Features
39
+
40
+ ### πŸš€ **Auto-Installation on Demand**
41
+ Dependencies are automatically installed when code first uses themβ€”no manual intervention required. Perfect for optional features that users may never need.
42
+
43
+ **Why it matters:** Reduces initial installation size by 60-80% for packages with many optional dependencies, while maintaining zero overhead for successful imports.
44
+
45
+ ### πŸ”’ **Per-Package Isolation**
46
+ Each package (xwsystem, xwnode, xwdata, etc.) can independently enable lazy mode without affecting others. Complete isolation prevents conflicts and enables flexible deployment strategies.
47
+
48
+ **Why it matters:** Allows mixing lazy and non-lazy packages in the same environment, giving developers full control over which packages use auto-installation.
49
+
50
+ ### 🎯 **Keyword-Based Auto-Detection**
51
+ Packages can opt-in to lazy loading by simply adding `"xwlazy-enabled"` to their `pyproject.toml` keywordsβ€”no code changes required.
52
+
53
+ **Why it matters:** Zero-code integration for package maintainers. Just add a keyword and lazy loading works automatically.
54
+
55
+ ### πŸ›‘οΈ **Enterprise Security**
56
+ - **Allow/Deny Lists:** Whitelist or blacklist specific packages
57
+ - **SBOM Generation:** Software Bill of Materials for compliance
58
+ - **Vulnerability Auditing:** Automatic security scanning with pip-audit
59
+ - **Lockfile Management:** Track installed packages with versions
60
+ - **PEP 668 Compliance:** Respects externally-managed environments
61
+
62
+ **Why it matters:** Production environments require security controls. xwlazy provides enterprise-grade security without sacrificing usability.
63
+
64
+ ### ⚑ **Two-Stage Lazy Loading**
65
+ **Stage 1 (Import Time):** Missing imports are logged but don't raise errorsβ€”modules load successfully.
66
+ **Stage 2 (Usage Time):** Dependencies are installed automatically when code first accesses them.
67
+
68
+ **Why it matters:** Enables clean Python code with standard imports. No defensive `try/except ImportError` blocks needed.
69
+
70
+ ### πŸ“Š **Performance Monitoring**
71
+ Built-in tracking of module load times, access counts, memory usage, and cache hit ratios. Comprehensive statistics API for optimization.
72
+
73
+ **Why it matters:** Visibility into lazy loading performance helps identify bottlenecks and optimize import strategies.
74
+
75
+ ### 🎨 **Two-Dimensional Mode System**
76
+
77
+ xwlazy uses a powerful two-dimensional mode system that separates **loading behavior** from **installation behavior**, giving you precise control over how modules are loaded and when packages are installed.
78
+
79
+ #### **Lazy Load Modes** (When modules load)
80
+ - **NONE:** Standard imports (no lazy loading)
81
+ - **AUTO:** Lazy loading enabled (deferred module loading)
82
+ - **PRELOAD:** Preload all modules on start (parallel loading)
83
+ - **BACKGROUND:** Load modules in background threads (non-blocking)
84
+ - **CACHED:** Cache loaded modules but allow unloading
85
+
86
+ #### **Lazy Install Modes** (When packages install)
87
+ - **NONE:** No auto-installation
88
+ - **SMART:** Install on first usage (on-demand)
89
+ - **FULL:** Install all dependencies on start (parallel batch)
90
+ - **CLEAN:** Install on usage + uninstall after completion
91
+ - **TEMPORARY:** Always uninstall after use (aggressive cleanup)
92
+ - **SIZE_AWARE:** Install small packages, skip large ones
93
+ - **INTERACTIVE:** Ask user before installing
94
+ - **WARN:** Log warning but don't install (monitoring mode)
95
+ - **DISABLED:** Don't install anything (explicit)
96
+ - **DRY_RUN:** Show what would be installed
97
+
98
+ #### **Preset Modes** (Quick combinations)
99
+ - **none:** NONE load + NONE install (standard imports)
100
+ - **lite:** AUTO load + NONE install (lazy loading only)
101
+ - **smart:** AUTO load + SMART install (on-demand installation)
102
+ - **full:** AUTO load + FULL install (install all on start)
103
+ - **clean:** AUTO load + CLEAN install (install + cleanup)
104
+ - **temporary:** AUTO load + TEMPORARY install (aggressive cleanup)
105
+ - **size_aware:** AUTO load + SIZE_AWARE install (smart sizing)
106
+ - **auto:** AUTO load + SMART install + auto-uninstall large packages
107
+
108
+ **Why it matters:** Different environments need different policies. Development might use `smart`, production might use `lite` or `warn`, CI/CD might use `clean` or `temporary`.
109
+
110
+ ## πŸ† Performance Benchmarks
111
+
112
+ xwlazy has been benchmarked against 8 competing lazy import libraries. **Results show xwlazy is competitive across all load scenarios** while providing significantly more features.
113
+
114
+ ### Latest Benchmark Results (2025-11-17)
115
+
116
+ | Load Type | xwlazy Time | Rank | vs. Winner | Features |
117
+ |-----------|-------------|------|------------|----------|
118
+ | **Light Load** (1 module) | 2.08 ms | πŸ₯‡ **1st** | 2.54x faster | 7 features |
119
+ | **Medium Load** (8 modules) | 6.99 ms | πŸ₯‡ **1st** | 8.52x faster | 7 features |
120
+ | **Heavy Load** (22 modules) | 21.13 ms | πŸ₯‡ **1st** | 25.75x faster | 7 features |
121
+ | **Enterprise Load** (50+ modules) | 61.28 ms | πŸ₯‡ **1st** | 74.66x faster | 7 features |
122
+
123
+ **Competitive Advantage:** While competitors offer 1-2 features (basic lazy loading), xwlazy provides **7 enterprise features** including auto-installation, security policies, SBOM generation, and per-package isolation.
124
+
125
+ **See full benchmarks:** [benchmarks/competition_tests/output_log/](benchmarks/competition_tests/output_log/)
126
+
127
+ ## πŸš€ Quick Start
128
+
129
+ ### Installation
130
+
131
+ ```bash
132
+ # Standard installation
133
+ pip install exonware-xwlazy
134
+
135
+ # Or install as xwlazy (alias package)
136
+ pip install xwlazy
137
+ ```
138
+
139
+ ### Basic Usage
140
+
141
+ **One-line setup** for per-package lazy loading:
142
+
143
+ ```python
144
+ # In your package's __init__.py
145
+ from xwlazy.lazy import config_package_lazy_install_enabled
146
+
147
+ # Auto-detects from pip install your-package[lazy]
148
+ config_package_lazy_install_enabled("your-package")
149
+ ```
150
+
151
+ **That's it!** Now use standard importsβ€”missing dependencies install automatically:
152
+
153
+ ```python
154
+ # your-package/serialization/avro.py
155
+ import fastavro # Auto-installed if missing! ✨
156
+
157
+ # User code
158
+ from your-package.serialization.avro import AvroSerializer
159
+ serializer = AvroSerializer() # Installs fastavro on first use
160
+ ```
161
+
162
+ ### Keyword-Based Detection (Zero Code)
163
+
164
+ Add to your `pyproject.toml`:
165
+
166
+ ```toml
167
+ [project]
168
+ name = "my-package"
169
+ keywords = ["xwlazy-enabled"] # <-- Add this
170
+ ```
171
+
172
+ After `pip install -e .`, xwlazy automatically enables lazy loading for your packageβ€”no code changes needed!
173
+
174
+ ## πŸ“– Documentation
175
+
176
+ - **[Architecture Reference](docs/REF_ARCH.md)** - System design, patterns, and structure
177
+ - **[Keyword Detection Guide](docs/KEYWORD_DETECTION.md)** - Zero-code integration
178
+ - **[Competition Benchmarks](benchmarks/competition_tests/)** - Performance comparisons
179
+ - **[Performance Analysis](benchmarks/competition_tests/PERFORMANCE_ANALYSIS.md)** - Optimization recommendations
180
+
181
+ ## πŸ’‘ Use Cases
182
+
183
+ ### 1. Optional Format Support
184
+
185
+ ```python
186
+ # xwsystem/serialization/avro.py
187
+ import fastavro # Only installed if user needs Avro support
188
+
189
+ class AvroSerializer:
190
+ def serialize(self, data):
191
+ return fastavro.schemaless_writer(...)
192
+ ```
193
+
194
+ **Benefit:** Users who never use Avro don't install fastavro, reducing installation size.
195
+
196
+ ### 2. Development Tools
197
+
198
+ ```python
199
+ # xwnode/visualization/graphviz.py
200
+ import graphviz # Only installed in development
201
+
202
+ def visualize_graph(node):
203
+ return graphviz.render(...)
204
+ ```
205
+
206
+ **Benefit:** Production deployments don't include development-only dependencies.
207
+
208
+ ### 3. Platform-Specific Features
209
+
210
+ ```python
211
+ # xwdata/formats/excel.py
212
+ try:
213
+ import openpyxl # Windows/Linux
214
+ except ImportError:
215
+ import xlrd # macOS fallback
216
+ ```
217
+
218
+ **Benefit:** Platform-specific dependencies install automatically based on availability.
219
+
220
+ ### 4. Security-Controlled Environments
221
+
222
+ ```python
223
+ from xwlazy.lazy import (
224
+ config_package_lazy_install_enabled,
225
+ set_package_allow_list,
226
+ )
227
+
228
+ # Only allow specific packages
229
+ config_package_lazy_install_enabled("xwsystem")
230
+ set_package_allow_list("xwsystem", ["fastavro", "protobuf", "msgpack"])
231
+
232
+ # Attempts to install other packages are blocked
233
+ import suspicious_package # ❌ Blocked by security policy
234
+ ```
235
+
236
+ **Benefit:** Enterprise environments can restrict auto-installation to approved packages only.
237
+
238
+ ## πŸ”§ Advanced Configuration
239
+
240
+ ### Two-Dimensional Mode Configuration
241
+
242
+ #### Using Preset Modes (Recommended)
243
+
244
+ ```python
245
+ from xwlazy.lazy import config_package_lazy_install_enabled
246
+
247
+ # Quick preset modes
248
+ config_package_lazy_install_enabled("xwsystem", enabled=True, mode="smart") # On-demand install
249
+ config_package_lazy_install_enabled("xwsystem", enabled=True, mode="full") # Install all on start
250
+ config_package_lazy_install_enabled("xwsystem", enabled=True, mode="clean") # Install + cleanup
251
+ config_package_lazy_install_enabled("xwsystem", enabled=True, mode="lite") # Lazy load only
252
+ ```
253
+
254
+ #### Using Explicit Mode Configuration
255
+
256
+ ```python
257
+ from xwlazy.lazy import (
258
+ config_package_lazy_install_enabled,
259
+ LazyLoadMode,
260
+ LazyInstallMode,
261
+ LazyModeConfig,
262
+ )
263
+
264
+ # Explicit two-dimensional configuration
265
+ config_package_lazy_install_enabled(
266
+ "xwsystem",
267
+ enabled=True,
268
+ load_mode=LazyLoadMode.PRELOAD, # Preload all modules
269
+ install_mode=LazyInstallMode.SMART # Install on-demand
270
+ )
271
+
272
+ # Or use LazyModeConfig for full control
273
+ config = LazyModeConfig(
274
+ load_mode=LazyLoadMode.BACKGROUND,
275
+ install_mode=LazyInstallMode.SIZE_AWARE,
276
+ large_package_threshold_mb=100.0, # Skip packages > 100MB
277
+ background_workers=4 # 4 background workers
278
+ )
279
+ config_package_lazy_install_enabled(
280
+ "xwsystem",
281
+ enabled=True,
282
+ mode_config=config
283
+ )
284
+ ```
285
+
286
+ #### Using exonware.conf (Global Configuration)
287
+
288
+ ```python
289
+ import exonware.conf as conf
290
+
291
+ # Set global lazy mode for all packages
292
+ conf.lazy = "smart" # or "lite", "full", "clean", "auto", etc.
293
+ ```
294
+
295
+ #### Special Purpose Modes
296
+
297
+ ```python
298
+ # Interactive mode: Ask user before installing
299
+ config_package_lazy_install_enabled(
300
+ "xwsystem",
301
+ enabled=True,
302
+ mode="interactive" # or LazyInstallMode.INTERACTIVE
303
+ )
304
+
305
+ # Warn mode: Log but don't install (monitoring)
306
+ config_package_lazy_install_enabled(
307
+ "xwsystem",
308
+ enabled=True,
309
+ mode="warn" # or LazyInstallMode.WARN
310
+ )
311
+ ```
312
+
313
+ ### Security Policies
314
+
315
+ ```python
316
+ from xwlazy.lazy import (
317
+ set_package_allow_list,
318
+ set_package_deny_list,
319
+ set_package_lockfile,
320
+ )
321
+
322
+ # Whitelist approach
323
+ set_package_allow_list("xwsystem", ["fastavro", "protobuf"])
324
+
325
+ # Blacklist approach
326
+ set_package_deny_list("xwsystem", ["suspicious-package"])
327
+
328
+ # Track installations
329
+ set_package_lockfile("xwsystem", "xwsystem-lazy-lock.json")
330
+ ```
331
+
332
+ ### SBOM Generation
333
+
334
+ ```python
335
+ from xwlazy.lazy import generate_package_sbom
336
+
337
+ # Generate Software Bill of Materials for compliance
338
+ sbom = generate_package_sbom("xwsystem", "xwsystem-sbom.json")
339
+ ```
340
+
341
+ ### Statistics and Monitoring
342
+
343
+ ```python
344
+ from xwlazy.lazy import get_lazy_install_stats
345
+
346
+ # Get installation statistics
347
+ stats = get_lazy_install_stats("xwsystem")
348
+ # {
349
+ # 'enabled': True,
350
+ # 'mode': 'auto',
351
+ # 'installed_packages': ['fastavro', 'protobuf'],
352
+ # 'failed_packages': [],
353
+ # 'total_installed': 2
354
+ # }
355
+ ```
356
+
357
+ ## 🎨 Design Patterns
358
+
359
+ xwlazy implements 8 design patterns for maintainability and extensibility:
360
+
361
+ 1. **Facade Pattern** - Unified API to complex subsystems
362
+ 2. **Strategy Pattern** - Pluggable discovery/installation strategies
363
+ 3. **Template Method** - Base classes define common workflows
364
+ 4. **Singleton** - Global instances for system-wide state
365
+ 5. **Registry** - Per-package isolation and management
366
+ 6. **Observer** - Performance monitoring and tracking
367
+ 7. **Proxy** - Deferred loading and lazy access
368
+ 8. **Factory** - Creating appropriate handlers by context
369
+
370
+ ## πŸ”’ Security Considerations
371
+
372
+ ### PEP 668 Compliance
373
+ xwlazy respects externally-managed Python environments and refuses to install in system Python, suggesting virtual environments instead.
374
+
375
+ ### System Module Protection
376
+ Built-in modules (stdlib) are never auto-installed, preventing accidental system modifications.
377
+
378
+ ### Vulnerability Scanning
379
+ Optional pip-audit integration scans packages after installation and logs security warnings.
380
+
381
+ ### Custom PyPI Mirrors
382
+ Support for internal PyPI servers with custom index URLs and trusted hosts.
383
+
384
+ ## ⚑ Performance Characteristics
385
+
386
+ - **Zero overhead** for successful imports (hooks only trigger on failures)
387
+ - **Aggressive caching** with file modification time checks
388
+ - **Lazy initialization** - everything loads only when needed
389
+ - **Thread-safe** operations with proper locking
390
+ - **Import overhead:** ~0.1ms for successful imports
391
+ - **First failure:** ~50ms (discovery + policy check)
392
+ - **Subsequent failures:** ~5ms (cached discovery)
393
+
394
+ ## πŸ§ͺ Testing
395
+
396
+ xwlazy includes comprehensive test suites:
397
+
398
+ ```bash
399
+ # Run all tests
400
+ python tests/runner.py
401
+
402
+ # Run specific test layers
403
+ python tests/0.core/runner.py # Core tests (< 30s)
404
+ python tests/1.unit/runner.py # Unit tests (< 5m)
405
+ ```
406
+
407
+ ## πŸ“Š Comparison with Competitors
408
+
409
+ | Feature | xwlazy | lazy-imports-lite | lazy-loader | lazy_import |
410
+ |---------|--------|-------------------|-------------|-------------|
411
+ | **Lazy Import** | βœ… | βœ… | βœ… | βœ… |
412
+ | **Auto-Installation** | βœ… | ❌ | ❌ | ❌ |
413
+ | **Keyword Detection** | βœ… | βœ… | ❌ | ❌ |
414
+ | **Per-Package Isolation** | βœ… | ❌ | ❌ | ❌ |
415
+ | **Security Policies** | βœ… | ❌ | ❌ | ❌ |
416
+ | **SBOM Generation** | βœ… | ❌ | ❌ | ❌ |
417
+ | **Performance Monitoring** | βœ… | ❌ | ❌ | ❌ |
418
+ | **Two-Stage Loading** | βœ… | ❌ | ❌ | ❌ |
419
+ | **Total Features** | **7** | **2** | **1** | **1** |
420
+
421
+ ## 🀝 Contributing
422
+
423
+ xwlazy is part of the eXonware ecosystem. For contributions, please follow:
424
+
425
+ - [Development Guide](../../docs/guides/GUIDE_DEV.md) - Core development standards
426
+ - [Testing Guide](../../docs/guides/GUIDE_TEST.md) - Testing standards
427
+ - [Documentation Guide](../../docs/guides/GUIDE_DOCS.md) - Documentation standards
428
+
429
+ ## πŸ“„ License
430
+
431
+ MIT License - see [LICENSE](LICENSE) for details.
432
+
433
+ ## πŸ”— Links
434
+
435
+ - **Homepage:** https://exonware.com
436
+ - **Repository:** https://github.com/exonware/xwlazy
437
+ - **Email:** connect@exonware.com
438
+ - **Author:** Eng. Muhammad AlShehri
439
+
440
+ ## πŸ™ Acknowledgments
441
+
442
+ xwlazy is built with inspiration from the Python lazy import ecosystem, particularly:
443
+ - `lazy-imports-lite` for keyword-based detection concept
444
+ - `lazy-loader` for scientific Python patterns
445
+ - The broader Python import system for hook mechanisms
446
+
447
+ ---
448
+
449
+ **Part of the eXonware ecosystem** - Enterprise-grade Python libraries for modern software development.
450
+
451
+ *Last Updated: 17-Nov-2025*
452
+
453
+ > **Note:** For the current version, use `from exonware.xwlazy import __version__` or `import exonware.xwlazy; print(exonware.xwlazy.__version__)`
454
+
@@ -0,0 +1,6 @@
1
+ README.md,sha256=_TPNldwgooH5cGTNpt1GFAQTtrYM5yS-AFc0fy1VfdE,15672
2
+ src/xwlazy_wrapper.py,sha256=qYc2lJ5WZdSxgBhHrEUC39KHSmWl5YGqirw_ro4WhpE,498
3
+ xwlazy-0.1.0.1.dist-info/METADATA,sha256=57uPbcauFmQb-yYD0pwp2COgB7mObxDP2UYQJ7AxPXg,16622
4
+ xwlazy-0.1.0.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
5
+ xwlazy-0.1.0.1.dist-info/licenses/LICENSE,sha256=w42ohoEUfhyT0NgiivAL4fWg2AMRLGnfXPMAR4EO-MU,1094
6
+ xwlazy-0.1.0.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.27.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 eXonware.com - Eng. Muhammad AlShehri
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.