deepinfra
The official Python SDK for the DeepInfra API: Sandboxes (isolated microVMs for running untrusted code) and inference.
Installation
pip install deepinfra
Authentication uses your DeepInfra API key — pass api_key= or set the
DEEPINFRA_API_KEY environment variable (the same key you use for inference,
from deepinfra.com/dash/api_keys).
Sandboxes
Create an isolated Linux microVM, run bash/python inside it, move files in and out, and tear it down — in a few lines:
from deepinfra import Sandbox
sb = Sandbox.create(plan="medium", timeout="10m") # blocks until running
r = sb.exec("bash", "-c", "pip install pandas && python -c 'import pandas; print(pandas.__version__)'")
print(r.stdout, r.stderr, r.returncode)
out = sb.run_python("print(21 * 2)").check() # .check() raises on non-zero exit
print(out.stdout) # "42"
sb.fs.write("/work/in.csv", b"a,b\n1,2\n")
data = sb.fs.read("/work/in.csv")
sb.stop() # frees compute, keeps disk; blocks until stopped
sb.start() # resumes on the same disk; blocks until running
sb.terminate() # deletes the sandbox (stays fetchable by id as "deleted" briefly)
Every network method has an async twin prefixed with a:
sb = await Sandbox.acreate(plan="small")
r = await sb.aexec("uname", "-a")
await sb.aterminate()
The zero-config async calls share one process-wide client whose connection
pool binds to the first event loop that uses it. If your program calls
asyncio.run() more than once, create a DeepInfraClient per loop and pass
it via client= (closing it with await client.aclose() before the loop
exits), instead of relying on the default client.
Useful patterns:
# Auto-terminate with a context manager
with Sandbox.create(plan="small") as sb:
sb.run_python("open('/work/out.txt', 'w').write('hi')")
print(sb.fs.read("/work/out.txt"))
# Find existing sandboxes
sb = Sandbox.from_id("sb_...")
etl_boxes = Sandbox.list(tags={"job": "etl-42"})
# List available plans (id, vcpu, ram_gb, disk_gb, price_per_hour)
for plan in Sandbox.catalog():
print(plan.id, plan.vcpu, plan.ram_gb, plan.price_per_hour)
# Large scripts: upload, then run
sb.fs.write("/work/script.py", open("script.py").read())
sb.exec("python3", "/work/script.py", timeout="30m")
Errors are typed: AuthenticationError (401), NotFoundError (404),
ConflictError (409, e.g. exec on a stopped sandbox), RateLimitError
(429; for sandboxes that's the per-account cap — TooManySandboxesError is
an alias), CapacityError (503), plus SDK-side SandboxTimeoutError /
SandboxFailedError / CommandFailedError. If Sandbox.create(wait=True)
fails while waiting, the raised error carries .sandbox_id so you can
inspect or terminate the sandbox it created.
Roadmap (API designed, lands in an upcoming release): exec_stream (live
output), snapshot() / Sandbox.from_snapshot(), expose_port(),
fs.upload_dir().
Inference
The inference wrappers predate the SDK's OpenAI-compatible endpoints and remain supported:
Automatic Speech Recognition
from deepinfra import AutomaticSpeechRecognition
asr = AutomaticSpeechRecognition("openai/whisper-base")
body = {"audio": "path/to/audio/file"} # or a URL, or raw bytes
transcription = asr.generate(body)
print(transcription.text)
Text Generation
from deepinfra import TextGeneration
llm = TextGeneration("mistralai/Mixtral-8x22B-Instruct-v0.1")
res = llm.generate({"input": "What is the capital of France?"})
print(res.results[0].generated_text)
Embeddings and TextToImage work the same way. For chat-style LLM usage you
can also point the official OpenAI client at
https://api.deepinfra.com/v1/openai.
Development
pip install -e ".[dev]"
pytest tests # unit tests (no network)
mypy && ruff check . # types + lint
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 deepinfra-0.2.1.tar.gz.
File metadata
- Download URL: deepinfra-0.2.1.tar.gz
- Upload date:
- Size: 26.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f353ab33ea7735000374aaddc85396d38a0ac210fcb200a647db42eaa065b32b
|
|
| MD5 |
adad18ca96c64c752ae4f306bf201713
|
|
| BLAKE2b-256 |
a64f03fc9cfca4532fa6ade9524390d87a39cc3542fb927b55dfab6b96fb6ed3
|
Provenance
The following attestation bundles were made for deepinfra-0.2.1.tar.gz:
Publisher:
deploy.yaml on deepinfra/deepinfra-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
deepinfra-0.2.1.tar.gz -
Subject digest:
f353ab33ea7735000374aaddc85396d38a0ac210fcb200a647db42eaa065b32b - Sigstore transparency entry: 2344496189
- Sigstore integration time:
-
Permalink:
deepinfra/deepinfra-python@4708a134965848b139ace26e4204bd5fd3950164 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/deepinfra
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
deploy.yaml@4708a134965848b139ace26e4204bd5fd3950164 -
Trigger Event:
push
-
Statement type:
File details
Details for the file deepinfra-0.2.1-py3-none-any.whl.
File metadata
- Download URL: deepinfra-0.2.1-py3-none-any.whl
- Upload date:
- Size: 29.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d5b0938b0e4fe6a63b8dccf1315f1399383b36b58cea71c87ab114853ff08998
|
|
| MD5 |
7950e228f662723ec029591575ae47a3
|
|
| BLAKE2b-256 |
f5698ec93ba091dc5dbf96c435e63030b06f2ab6ab2d6dc990fc6217baf796b2
|
Provenance
The following attestation bundles were made for deepinfra-0.2.1-py3-none-any.whl:
Publisher:
deploy.yaml on deepinfra/deepinfra-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
deepinfra-0.2.1-py3-none-any.whl -
Subject digest:
d5b0938b0e4fe6a63b8dccf1315f1399383b36b58cea71c87ab114853ff08998 - Sigstore transparency entry: 2344496227
- Sigstore integration time:
-
Permalink:
deepinfra/deepinfra-python@4708a134965848b139ace26e4204bd5fd3950164 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/deepinfra
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
deploy.yaml@4708a134965848b139ace26e4204bd5fd3950164 -
Trigger Event:
push
-
Statement type: