Fructose logo

Fructose

Free

Fructose is a python package to create a dependable, strongly-typed interface around an LLM call. ![GitHub Repo stars](https://img.shields.io/github/stars/bananaml/fructose?style=social)

FreeFree tier
Inputs: text
Type
Open Source
Company
bananaml

About Fructose

Fructose is a Python package that enables developers to define LLM calls as strongly-typed functions using a simple @ai decorator. By decorating a type-annotated function, Fructose automatically builds a prompt for an LLM (currently OpenAI) and returns structured data matching the function's return type. It supports primitive types (str, int, bool, float), compound types (list, dict, tuple, Enum, Optional), complex dataclasses, nested types, custom prompt templates, and local function calling. The package is lightweight and syntactic sugar, making it easy to integrate into existing Python projects. Note: maintenance is paused; alternative packages like Instructor or Marvin are recommended for active development.

Key Features

Define LLM calls as strongly-typed functions using @ai decorator
Supports primitive and compound types including @dataclass and nested types
Local function calling: @ai functions can call other Python functions
Custom prompt templates
Model selection (e.g., OpenAI models)
Lightweight syntactic sugar, no complex frameworks

Pros & Cons

Pros
  • Simple decorator-based syntax integrates naturally with Python
  • Strongly-typed interface ensures predictable outputs
  • Supports complex nested data types including dataclasses
  • Local function calling allows composition of LLM calls with traditional code
  • Lightweight and easy to install
Cons
  • Maintenance paused; project may not receive updates
  • Only supports OpenAI models (requires API key)
  • Local function calling requires specific annotations (type hints, docstrings)
  • Not actively maintained; consider alternatives like Instructor or Marvin

Best For

Building structured data extraction pipelinesGenerating fake data with specific schemasFetching and parsing web content (e.g., HackerNews comments)Any task requiring structured output from an LLM with type safety

FAQ

How does Fructose work?
Fructose uses a @ai decorator that introspects the function signature (type annotations, docstring) to build a prompt for an LLM. When the function is called, it executes the LLM call and returns the result in the specified type.
Does Fructose support local function calling?
Yes, @ai functions can call local Python functions (including other @ai functions) by passing them via the 'uses' argument of the decorator. This requires type annotations, docstrings, and sane variable names.
Is Fructose actively maintained?
Maintenance is paused as the developers have directed attention elsewhere. The project can be forked, and users are welcome to open issues to request maintainer status.
What LLM providers does Fructose support?
Currently, Fructose executes prompts with OpenAI models. You need to set your own OPENAI_API_KEY.