Documentation
Python: run code
Run a file or code snippet without creating a persistent sandbox. Every run comes back in the standard submission format — the same JSON as the HTTP API.
Before you run it
Install the Python SDK and create an API key in your dashboard. The SDK reads it from the environment or a .env file:
BOLTZLABS_API_KEY=ak_your_key_hereRun code
import boltzlabs
print(boltzlabs.execute("print(sum(range(101)))", language="python")) # 5050
print(boltzlabs.execute(file="main.go", language="go"))
print(boltzlabs.execute("console.log(40 + 2)", language=101)) # an id works too
boltzlabs.languages() # ids, codes and names, from the platformRead the result
res = boltzlabs.execute(file="solution.py", language="python")
print(res) # what it printed
if res: # True when the status is Accepted
...
res.check() # raises unless Accepted
res.status # {"id": 3, "description": "Accepted"}
res.time # "0.012" seconds of CPU the program used
res.wall_time # "0.015" seconds of wall time
res.memory # 9216 peak memory, KB
res.stdout, res.stderr, res.compile_output, res.message, res.exit_code
res.json # the whole response, exactly as it came backTimes and memory are your program's own; the sandbox building itself is not counted. A program that exits non-zero is a result, not an exception: its status says what happened.
Judge a solution
Give the test input, the problem's limits and the expected answer. Limits are seconds and KB, and only ever lower the platform's own (15 s CPU, 30 s wall, 256 MB).
res = boltzlabs.execute(
file="solution.py", language="python",
stdin="3\n1 2 3\n",
expected_output="6",
cpu_time_limit=1, # seconds
memory_limit=65536, # KB
)
res.status["description"] # Accepted, Wrong Answer, Time Limit Exceeded, ...Output is compared the usual way: trailing spaces on each line and trailing blank lines are ignored, everything else must match.
Run every test case at once
source = open("solution.py").read()
tests = [("1 2\n", "3"), ("5 5\n", "10"), ("0 0\n", "0")]
results = boltzlabs.execute_batch([
{"code": source, "language": "python", "stdin": i, "expected_output": o, "cpu_time_limit": 1}
for i, o in tests
]) # up to 20; runs in parallel, returns in order
[r.status["description"] for r in results]Compiled languages
TypeScript, Go, C, C++, Java and Rust are compiled first, in their own sandbox with their own
budget. Code that does not compile comes back with status Compilation Error and the compiler's
message in compile_output; a time limit you set applies to your program, not
to the compiler.
Supported languages
Ids, codes and versions are listed on Supported languages.