Direct container execution with custom Docker images and resource control.
pip install cognitora
1from cognitora import Cognitora
2
3client = Cognitora(api_key="your_api_key")
4
5# Create compute execution
6execution = client.compute.create_execution(
7 image="docker.io/library/python:3.11",
8 command=[
9 "python", "-c",
10 "import time; print('Starting...'); time.sleep(5); print('Done!')"
11 ],
12 cpu_cores=1.0,
13 memory_mb=512,
14 max_cost_credits=10,
15 timeout_seconds=60
16)
17
18print(f"Execution created: {execution.id}")
19print(f"Status: {execution.status}")
20
21# Wait for completion and get logs
22result = client.compute.run_and_wait(
23 {
24 "image": "docker.io/library/ubuntu:latest",
25 "command": ["bash", "-c", "echo 'Hello' && ls -la"],
26 "cpu_cores": 0.5,
27 "memory_mb": 256,
28 "max_cost_credits": 5
29 },
30 timeout_ms=30000
31)
32
33print(f"Execution completed: {result.execution.status}")
34print(f"Logs: {result.logs}")
35print(f"Cost: {result.execution.actual_cost_credits} credits")
Get started with Compute API and Cognitora in minutes. Secure, scalable, and ready for anything.