|
| 1 | +# ModuLink-Py Import Migration Guide |
| 2 | + |
| 3 | +## What Changed |
| 4 | + |
| 5 | +ModuLink-py now supports clean, intuitive import paths while maintaining backward compatibility with existing code. |
| 6 | + |
| 7 | +## New (Preferred) Import Pattern |
| 8 | + |
| 9 | +```python |
| 10 | +# Clean, direct imports (recommended) |
| 11 | +from modulink import Chain, Context, Logging, Timing |
| 12 | + |
| 13 | +async def validate_email(ctx: Context) -> Context: |
| 14 | + if "email" not in ctx: |
| 15 | + ctx["error"] = "Missing email" |
| 16 | + return ctx |
| 17 | + |
| 18 | +async def send_welcome(ctx: Context) -> Context: |
| 19 | + print(f"Welcome sent to {ctx['email']}") |
| 20 | + return ctx |
| 21 | + |
| 22 | +# Build and run chain |
| 23 | +signup = Chain(validate_email, send_welcome) |
| 24 | +signup.use(Logging()) |
| 25 | +signup.use(Timing()) |
| 26 | + |
| 27 | +result = await signup.run({"email": "alice@example.com"}) |
| 28 | +``` |
| 29 | + |
| 30 | +## Old (Deprecated) Import Pattern |
| 31 | + |
| 32 | +```python |
| 33 | +# Still works but deprecated |
| 34 | +from modulink.src.chain import Chain |
| 35 | +from modulink.src.context import Context |
| 36 | +from modulink.src.middleware import Logging, Timing |
| 37 | + |
| 38 | +# Same functionality, but imports are more verbose |
| 39 | +``` |
| 40 | + |
| 41 | +## Migration Benefits |
| 42 | + |
| 43 | +✅ **Cleaner imports**: `from modulink import Chain` instead of `from modulink.src.chain import Chain` |
| 44 | +✅ **Better IDE support**: Improved autocomplete and documentation |
| 45 | +✅ **Standard Python practices**: Follows conventional package structure |
| 46 | +✅ **No breaking changes**: Existing code continues to work |
| 47 | + |
| 48 | +## Migration Timeline |
| 49 | + |
| 50 | +- **Now**: Both patterns work identically |
| 51 | +- **Recommended**: Update new code to use clean imports |
| 52 | +- **Existing code**: No immediate changes required |
| 53 | +- **Future versions**: Deprecated imports will include warnings (but continue working) |
| 54 | + |
| 55 | +## Examples |
| 56 | + |
| 57 | +### Before (still works) |
| 58 | +```python |
| 59 | +from modulink.src.chain import Chain |
| 60 | +from modulink.src.middleware import Logging |
| 61 | +``` |
| 62 | + |
| 63 | +### After (recommended) |
| 64 | +```python |
| 65 | +from modulink import Chain, Logging |
| 66 | +``` |
| 67 | + |
| 68 | +Both patterns provide identical functionality - choose what works best for your project's timeline. |
0 commit comments