Marvin (PrefectHQ)

3.2.7 · active · verified Tue Mar 24

AI functions and agentic workflow library by PrefectHQ. Provides decorator-based AI functions (marvin.fn, marvin.classify, marvin.extract, marvin.cast) and agent/task orchestration. v3.0 released 2024 — merged with ControlFlow, switched LLM backend from OpenAI-only to Pydantic AI (multi-provider). Current version: 3.2.7 (Mar 2026). WARNING: 'marvin' on PyPI is PrefectHQ's AI library — not the SDSS astronomy Marvin library (sdss-marvin on PyPI).

Warnings

Install

Imports

Quickstart

Core marvin 3.x structured output functions.

# pip install marvin
import marvin
import os

# Set OPENAI_API_KEY env var — marvin uses OpenAI by default

# Structured extraction
numbers = marvin.extract(
    'I paid $45 for lunch and $12 for coffee',
    int,
    instructions='USD amounts only'
)
print(numbers)  # [45, 12]

# Classification
category = marvin.classify(
    'The new iPhone has great camera features',
    labels=['tech', 'sports', 'politics']
)
print(category)  # 'tech'

# AI function
@marvin.fn
def translate(text: str, language: str) -> str:
    """Translates text to the given language."""

print(translate('Hello world', 'Spanish'))  # 'Hola mundo'

view raw JSON →