Async Examples¶
The AsyncKibana client provides native async/await support for all Kibana APIs with the same interface as the synchronous client.
Async Examples
Overview¶
Learn how to:
Use async context managers
Execute concurrent operations
Handle async errors
Implement async patterns
Example Files¶
async_example.py¶
Purpose: Comprehensive async demonstration with all namespace clients
What You’ll Learn:
Async context manager usage
Actions, spaces, saved objects, and status operations
Concurrent API calls
Options pattern
async_comprehensive.py¶
Purpose: Advanced async patterns
What You’ll Learn:
Concurrent operations with
asyncio.gather()Per-request configuration
Error handling in async context
Basic Async Usage¶
import asyncio
from kibana import AsyncKibana
async def main():
async with AsyncKibana("http://localhost:5601") as client:
# Get status
status = await client.status.get_status()
print(status.body["status"]["overall"]["level"])
# Create connector
connector = await client.actions.create(
name="Async Connector",
connector_type_id=".server-log",
config={}
)
asyncio.run(main())
Concurrent Operations¶
async def fetch_all_data(client):
# Execute multiple operations concurrently
results = await asyncio.gather(
client.status.get_status(),
client.spaces.get_all(),
client.actions.list_types()
)
status, spaces, types = results
return status, spaces, types
When to Use Async¶
Use AsyncKibana when:
Making multiple concurrent API calls
Building async web applications (FastAPI, aiohttp)
Integrating with async frameworks
Need high throughput with many requests
Best Practices¶
Use context managers for automatic cleanup
Batch operations with
asyncio.gather()Handle exceptions in concurrent operations
Set appropriate timeouts for async operations
Next Steps¶
Async Patterns - Detailed examples