Alloy (Python)
Python for logic. English for intelligence.
from alloy import command
@command(output=float)
def extract_price(text: str) -> str:
return f"Extract the price from: {text}"
print(extract_price("This costs $49.99")) # 49.99
Write typed AI functions that feel like normal Python. No framework, no abstractions — just functions that happen to use AI.
Install • Tutorial • Examples • Docs
Install
pip install alloy-ai # OpenAI only
pip install 'alloy-ai[anthropic]' # With Anthropic
pip install 'alloy-ai[providers]' # All providers
Quick start (OpenAI):
export OPENAI_API_KEY=sk-...
python -c "from alloy import ask; print(ask('Say hello'))"
Why Alloy?
🎯 Types you can trust: Provider‑enforced structured outputs. Get a real float, not a string to parse.
🐍 Just Python: Commands are functions. Tools are functions. Everything composes.
⚡ Production‑ready: Retries, contracts, streaming, cross‑provider support — batteries included.
🔍 Zero magic: See what’s happening. Control what’s happening. No hidden state.
Examples
Exploration with ask — Quick one‑offs and streaming
from alloy import ask
# One‑liner exploration
print(ask("List 3 reasons Alloy is useful."))
# Stream text output (text‑only streaming)
for chunk in ask.stream("Write a two‑sentence pitch for Alloy."):
print(chunk, end="")
Typed outputs — Get back real Python objects
from dataclasses import dataclass
from alloy import command
@dataclass
class Analysis:
sentiment: str
score: float
keywords: list[str]
@command(output=Analysis)
def analyze(text: str) -> str:
return f"Analyze this text: {text}"
result = analyze("Alloy is amazing!")
print(result.score) # 0.95
TypedDict outputs are supported too:
from typing import TypedDict
from alloy import command
class Product(TypedDict):
name: str
price: float
@command(output=Product)
def make() -> str:
return "Return a Product with name='Test' and price=9.99 (numeric literal)."
print(make()["price"]) # 9.99
Tools + Contracts — Safe multi‑step workflows
from alloy import command, tool, ensure, require
@tool
@ensure(lambda x: x > 0, "Result must be positive")
def calculate(expression: str) -> float:
return eval(expression) # simplified example
@command(tools=[calculate])
def solve(problem: str) -> str:
return f"Solve step by step: {problem}"
See more in examples/ and the Examples guide.
📦 More installation options
# Specific providers
pip install 'alloy-ai[anthropic]'
pip install 'alloy-ai[gemini]'
pip install 'alloy-ai[ollama]'
# Development
pip install -e '.[dev]'
🔧 Configuration
export ALLOY_MODEL=gpt-5-mini
export ALLOY_TEMPERATURE=0.2
export ALLOY_MAX_TOOL_TURNS=10
Or in Python:
from alloy import configure
configure(model="gpt-5-mini", temperature=0.2)
🧪 Run examples offline
export ALLOY_BACKEND=fake
make examples-quick
Providers
Works with major providers — same code, zero changes:
| Provider | Models (examples) | Setup |
|---|---|---|
| OpenAI | gpt‑5 | export OPENAI_API_KEY=... |
| Anthropic | claude‑4 | export ANTHROPIC_API_KEY=... |
| gemini | export GOOGLE_API_KEY=... |
|
| Local | ollama | ollama run <model> + ALLOY_MODEL=ollama:<model> |
See the full provider guide.
Next Steps
New to Alloy? → 10‑minute tutorial
Ready to build? → Browse examples
Need details? → Read the docs
Contributing
We welcome contributions! See .github/CONTRIBUTING.md.
License
MIT — see LICENSE.
Metadata
Release files for alloy-ai 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| alloy_ai-0.3.1.tar.gz | 31.0 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| alloy_ai-0.3.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 66.4 kB
Release files / alloy_ai-0.3.1.tar.gz
| Download URL | alloy_ai-0.3.1.tar.gz |
|---|---|
| Size | 31.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b3d769d04bb44702e84ce083c7675faff514581236fefc84e71bf258164bd113
|
|
BLAKE2b-256 checksum How to use checksums |
f92355b026669d95526d0eac7014fe64eb7cf952ec246bb4da5c2367f096ebb8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 6, 2025.
Transparency logRelease files / alloy_ai-0.3.1-py3-none-any.whl
| Download URL | alloy_ai-0.3.1-py3-none-any.whl |
|---|---|
| Size | 35.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
21123a3961a418647ab206161082bfaa127105b9b2780249118a8651e4b2d86a
|
|
BLAKE2b-256 checksum How to use checksums |
e8006f3f9a5b62f50786f1ca86b037f3605353f3549bc256d9f605d2d2510686
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 6, 2025.
Transparency logSecurity for alloy-ai 0.3.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for alloy_ai-0.3.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 6, 2025.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.