OpenEnv documentation
Async vs Sync Usage
Get Started
Guides
Tutorials
OverviewHello WorldTrain a reasoning model with TRLMCP EnvironmentsRubricsRL Training with TRLRL Training with UnslothEvaluating with Inspect AIRL Training with an Agentic HarnessSFT Training with Environments
Environments
API Reference
Project
Async vs Sync Usage
OpenEnv supports both asynchronous and synchronous usage patterns.
When to Use Each
| Pattern | Best For | Performance |
|---|---|---|
| Async | Production, multiple environments, high throughput | ⚡ Best |
| Sync | Scripts, notebooks, quick experiments | 🐢 Good enough |
Sync Usage
For simple scripts and notebooks, use the .sync() wrapper:
from openenv import AutoEnv
env = AutoEnv.from_env("echo")
with env.sync() as client:
result = client.reset()
result = client.step(action)Async Usage (Recommended)
For production and parallel environments, use async directly:
import asyncio
from openenv import AutoEnv
async def main():
env = AutoEnv.from_env("echo")
async with env as client:
result = await client.reset()
result = await client.step(action)
asyncio.run(main())Parallel Environments
Run multiple environments concurrently:
import asyncio
from openenv import AutoEnv
async def run_episode(env_name: str):
env = AutoEnv.from_env(env_name)
async with env as client:
result = await client.reset()
# ... run episode
return result
async def main():
# Run 4 environments in parallel
results = await asyncio.gather(
run_episode("echo"),
run_episode("echo"),
run_episode("echo"),
run_episode("echo"),
)
asyncio.run(main())Next Steps
- RL Framework Integration - Using async with RL training
- Auto-Discovery - Discover and load environments