> ## Documentation Index
> Fetch the complete documentation index at: https://docs.praison.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Lazy Imports & Fast Startup

> Optimize import time and memory usage with lazy loading

# Lazy Imports & Fast Startup

PraisonAI Agents v0.5.0+ uses lazy imports to dramatically reduce startup time and memory usage. Heavy dependencies like `litellm`, `requests`, and `chromadb` are only loaded when actually needed.

## Performance Benefits

| Metric       | Before | After  | Improvement         |
| ------------ | ------ | ------ | ------------------- |
| Import Time  | 820ms  | 18ms   | **97.8% faster**    |
| Memory Usage | 93.3MB | 33.0MB | **64.6% reduction** |

## How It Works

### Lazy Module Loading

Core modules are loaded on-demand using Python's `__getattr__` mechanism:

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# These imports are fast - modules loaded lazily
from praisonaiagents import Agent, Session, Memory, Knowledge

# Agent is only fully loaded when you use it
agent = Agent(name="MyAgent")  # litellm loaded here
```

### Heavy Dependencies

The following dependencies are NOT loaded at import time:

* **litellm** - Only loaded when LLM calls are made
* **requests** - Only loaded when HTTP calls are needed
* **chromadb** - Only loaded when vector stores are used
* **mem0** - Only loaded when memory features are used

## Verifying Lazy Imports

You can verify lazy imports are working:

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
import sys

# Import the package
import praisonaiagents

# Check that heavy deps are NOT loaded
assert 'litellm' not in sys.modules
assert 'requests' not in sys.modules
assert 'chromadb' not in sys.modules

print("✓ All heavy dependencies are lazy loaded")
```

## Configuration

Lazy imports are enabled by default. You can check the configuration:

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents._config import LAZY_IMPORTS

print(f"Lazy imports enabled: {LAZY_IMPORTS}")
```

## Best Practices

1. **Import at module level** - Imports are fast, so import at the top of your file
2. **Use specific imports** - Import only what you need
3. **Avoid star imports** - `from praisonaiagents import *` loads everything

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# Good - specific imports
from praisonaiagents import Agent, Task

# Avoid - loads all modules
from praisonaiagents import *
```

## Measuring Performance

Use the built-in benchmarks to measure import time:

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
import time

start = time.perf_counter()
import praisonaiagents
end = time.perf_counter()

print(f"Import time: {(end - start) * 1000:.1f}ms")
```

## Related

* [Performance Benchmarks](/docs/features/performance-benchmarks)
* [Telemetry Configuration](/docs/features/telemetry)
* [Lite Package](/docs/features/lite-package)
