Official API of OpenAGI Foundation
Project description
OAGI Python SDK
Python SDK for the OAGI API - vision-based task automation.
Installation
# Recommended: All features (desktop automation + server)
pip install oagi
# Or install core only (minimal dependencies)
pip install oagi-core
# Or install with specific features
pip install oagi-core[desktop] # Desktop automation support
pip install oagi-core[server] # Server support
Requires Python >= 3.10
Installation Options
oagi(Recommended): Metapackage that includes all features (desktop + server). Equivalent tooagi-core[desktop,server].oagi-core: Core SDK with minimal dependencies (httpx, pydantic). Suitable for server deployments or custom automation setups.oagi-core[desktop]: Addspyautoguiandpillowfor desktop automation features like screenshot capture and GUI control.oagi-core[server]: Adds FastAPI and Socket.IO dependencies for running the real-time server for browser extensions.
Note: Features requiring desktop dependencies (like PILImage.from_screenshot(), PyautoguiActionHandler, ScreenshotMaker) will show helpful error messages if you try to use them without installing the desktop extra.
Quick Start
Set your API credentials:
export OAGI_API_KEY="your-api-key"
export OAGI_BASE_URL="https://api.oagi.com" # or your server URL
Automated Task Execution
Run tasks automatically with screenshot capture and action execution:
from oagi import ShortTask, ScreenshotMaker, PyautoguiActionHandler
task = ShortTask()
completed = task.auto_mode(
"Search weather on Google",
max_steps=10,
executor=PyautoguiActionHandler(), # Executes mouse/keyboard actions
image_provider=ScreenshotMaker(), # Captures screenshots
)
Configure PyAutoGUI behavior with custom settings:
from oagi import PyautoguiActionHandler, PyautoguiConfig
# Customize action behavior
config = PyautoguiConfig(
drag_duration=1.0, # Slower drags for precision (default: 0.5)
scroll_amount=50, # Larger scroll steps (default: 30)
wait_duration=2.0, # Longer waits (default: 1.0)
action_pause=0.2, # More pause between actions (default: 0.1)
hotkey_interval=0.1, # Interval between keys in hotkey combinations (default: 0.1)
capslock_mode="session" # Caps lock mode: 'session' or 'system' (default: 'session')
)
executor = PyautoguiActionHandler(config=config)
task.auto_mode("Complete form", executor=executor, image_provider=ScreenshotMaker())
Image Processing
Process and optimize images before sending to API:
from oagi import PILImage, ImageConfig
# Load and compress an image
image = PILImage.from_file("large_screenshot.png")
config = ImageConfig(
format="JPEG",
quality=85,
width=1260,
height=700
)
compressed = image.transform(config)
Async Support
Use async client for non-blocking operations and better concurrency:
import asyncio
from oagi import AsyncShortTask
async def main():
# Async task automation
task = AsyncShortTask()
async with task:
await task.init_task("Complete the form")
# ... continue with async operations
asyncio.run(main())
Examples
See the examples/ directory for more usage patterns:
google_weather.py- Basic task execution withShortTaskscreenshot_with_config.py- Image compression and optimizationexecute_task_auto.py- Automated task executionsocketio_server_basic.py- Socket.IO server examplesocketio_client_example.py- Socket.IO client implementation
Socket.IO Server (Optional)
The SDK includes an optional Socket.IO server for real-time bidirectional communication with browser extensions or custom clients.
Installation
# Install with server support
pip install oagi # Includes server features
# Or
pip install oagi-core[server] # Core + server only
Running the Server
import uvicorn
from oagi.server import create_app, ServerConfig
# Create FastAPI app with Socket.IO
app = create_app()
# Run server
uvicorn.run(app, host="0.0.0.0", port=8000)
Or use the example script:
export OAGI_API_KEY="your-api-key"
python examples/socketio_server_basic.py
Server Features
- Dynamic namespaces: Each session gets its own namespace (
/session/{session_id}) - Simplified events: Single
initevent from client with instruction - Action execution: Emit individual actions (click, type, scroll, etc.) to client
- S3 integration: Server sends presigned URLs for direct screenshot uploads
- Session management: In-memory session storage with timeout cleanup
- REST API: Health checks and session management endpoints
Client Integration
Clients connect to a session namespace and handle action events:
import socketio
sio = socketio.AsyncClient()
namespace = "/session/my_session_id"
@sio.on("request_screenshot", namespace=namespace)
async def on_screenshot(data):
# Upload screenshot to S3 using presigned URL
return {"success": True}
@sio.on("click", namespace=namespace)
async def on_click(data):
# Execute click at coordinates
return {"success": True}
await sio.connect("http://localhost:8000", namespaces=[namespace])
await sio.emit("init", {"instruction": "Click the button"}, namespace=namespace)
See examples/socketio_client_example.py for a complete implementation.
Documentation
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file oagi_core-0.9.1.tar.gz.
File metadata
- Download URL: oagi_core-0.9.1.tar.gz
- Upload date:
- Size: 165.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7885e527c4c80121ec946c34f49798948d8df80be6924c79885a219b8ef88330
|
|
| MD5 |
e4a85b02d9b0d87021c766f6270f2f24
|
|
| BLAKE2b-256 |
8cf5e7782e86376068d5ce46e746da96dd6692f73aaaa3440cc0b403ff23824c
|
File details
Details for the file oagi_core-0.9.1-py3-none-any.whl.
File metadata
- Download URL: oagi_core-0.9.1-py3-none-any.whl
- Upload date:
- Size: 74.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fdb1a880b632911075c7f9ff92493d139ebbc2fd66b4eba6aef7e6798f2c0e3e
|
|
| MD5 |
65f271a09e86c05e8d25dd8c3889f0e0
|
|
| BLAKE2b-256 |
805ca5ba4897bf8522659de7ef379e504c29de1cda4cc0b4fc72a5224a9c00aa
|