Skip to main content

brollm

A lightweight, opinionated contract for talking to LLMs. We tell you the shape you should build in — pack a request, fetch a response, parse it into whatever your program needs — then get out of your way. Use it exactly as-is, or build on top of it. Either way, you're shipping faster.

v0.2.0 — a real shift, not a patch

This version changes a lot from the last one, and on purpose. Here's the deal:

  • One contract, not three. BaseContract replaces BaseLLM, BaseEmbedding, and BaseReranker. Same shape for chat, embeddings, reranking — whatever you're calling.
  • You're in the driver's seat now. input_fn packs the request and fetches the response — context management, retries, the actual provider call, all yours. output_fn takes that response and turns it into whatever shape your program actually needs — a string, a dataclass with token counts, whatever. brollm doesn't guess for you anymore.
  • Providers moved to cookbook/. AWS Bedrock and Ollama can (and do) change their APIs without notice. Instead of brollm quietly breaking under you when that happens, provider code lives as copy-paste, version-pinned recipes you control.

Yeah, that's more you have to write than before. That's the point, not a shortcut we took. A generic base class can't know what your response object should look like, what your retry policy should be, or what your context window strategy is — you can, and you'll write it once, correctly, for your actual use case instead of fighting a one-size-fits-none abstraction. Less magic, more control, and you walk away actually understanding your own LLM layer instead of trusting a black box. That's a win.

Features

  • BaseContract: the one shape — input_fn in, output_fn out. Implement it your way, no subclassing gymnastics required.
  • brollm.retry: a @retry(...) decorator for wrapping a flaky input_fn — exponential or fixed backoff, jitter, exception filtering. Stop hand-rolling retry loops.
  • brollm.parsing.extract_codeblocks: pulls fenced codeblocks out of raw LLM text, even if the model got cut off mid-stream and never closed the fence.
  • Zero runtime dependencies. brollm doesn't drag boto3 or httpx into your project just because it knows what those libraries are.
  • Provider recipes in cookbook/: copy-paste, version-pinned integrations for AWS Bedrock and Ollama — a fast start, not a dependency you're locked into.

Installation

pip install brollm

or

uv add brollm

Quick Start

Build a contract with your own input_fn (pack + fetch) and output_fn (parse):

from brollm import BaseContract

def input_fn(system_prompt, messages):
    # own your context management, call whatever provider you want
    return provider_client.call(system_prompt, messages)

def output_fn(response):
    # parse the raw response into whatever your program needs
    return response["text"]

chat = BaseContract(input_fn=input_fn, output_fn=output_fn)
chat("You are a helpful assistant.", [{"role": "user", "content": "Hello!"}])

Same shape works for embeddings, reranking, anything — swap input_fn/output_fn for the call you're making.

Want token usage, a custom dataclass, parsed codeblocks? That's what output_fn is for:

from dataclasses import dataclass
from brollm.parsing import extract_codeblocks

@dataclass
class Tokens:
    input: int
    output: int

@dataclass
class ResponseModel:
    content: str
    usage: Tokens

def output_fn(response):
    return ResponseModel(
        content=response["text"],
        usage=Tokens(input=response["usage"]["input"], output=response["usage"]["output"]),
    )

Want retries on a flaky input_fn? Wrap it:

from brollm.retry import retry

@retry(max_attempts=3, on=(TimeoutError, ConnectionError))
def input_fn(system_prompt, messages):
    return provider_client.call(system_prompt, messages)

For ready-made, version-pinned examples (AWS Bedrock, Ollama) built on this exact pattern, see cookbook/ — copy the recipe into your project rather than depending on brollm for it.

License

MIT License

Metadata

Release files for brollm 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for brollm 0.2.0
File Size Uploaded
brollm-0.2.0.tar.gz 11.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for brollm 0.2.0
File Interpreter ABI Platform
brollm-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 19.6 kB

Release files / brollm-0.2.0.tar.gz

Download URL brollm-0.2.0.tar.gz
Size 11.0 kB
Tags Source
SHA-256 checksum
How to use checksums
a7371f3be86cbe91d5fef5f79b579892edb437e26191341c22d2ce6248b0ef5b
BLAKE2b-256 checksum
How to use checksums
c4b611f79ad8f212211184cc756f9183aa60d2628c4e3c5b81d9a0b85c038159
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 8, 2026.

Transparency log

Release files / brollm-0.2.0-py3-none-any.whl

Download URL brollm-0.2.0-py3-none-any.whl
Size 8.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3f0f6877c15a00d1dfccd351ce393150c17067208a27674cf5cd765c9502f081
BLAKE2b-256 checksum
How to use checksums
d7280dbd28fac80185990af98f28799562848de2899b2c156941fcfea5781c47
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 8, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page