This example demonstrates pactown’s fast startup capabilities with dependency caching.
demo.py - Python script demonstrating fast_run vs regular runapi/README.md - Sample FastAPI serviceapi2/README.md - Second service with same deps (will use cache)# Run the demo
python demo.py
# Or use pactown CLI
pactown up fast-start.pactown.yaml
=== Fast Start Demo ===
Run 1 (fresh):
Creating sandbox...
Installing dependencies (fastapi, uvicorn)...
✓ Started in 5.2s
Run 2 (cached):
⚡ Cache hit! Reusing venv
✓ Started in 0.08s
Speedup: 65x faster!
from pactown import ServiceRunner
runner = ServiceRunner(enable_fast_start=True)
# First run - creates and caches venv
result1 = await runner.fast_run(
service_id="api-1",
content=open("api/README.md").read(),
port=8001,
)
# Second run - reuses cached venv
result2 = await runner.fast_run(
service_id="api-2",
content=open("api2/README.md").read(), # Same deps!
port=8002,
)
/tmp/pactown-sandboxes/
├── .cache/
│ └── venvs/
│ └── venv_a1b2c3d4/ # Cached: fastapi + uvicorn
├── api-1/
│ └── .venv -> ../.cache/venvs/venv_a1b2c3d4
└── api-2/
└── .venv -> ../.cache/venvs/venv_a1b2c3d4 # Same cache!