Skip to main content

dj-evals

Internal Django helper for running one eval function with multiple argument sets in parallel, so you can visually compare output, tool calls, usage, cost, and completion behavior as the runs happen.

Django setup

Add dj_evals to INSTALLED_APPS:

INSTALLED_APPS = [
    "dj_evals",
]

Create one view that connects the package to your project. This is the only view required by dj-evals:

from django.contrib.admin.views.decorators import staff_member_required
from dj_evals import handle_eval_request


@staff_member_required
async def eval_run(request):
    return await handle_eval_request(
        request,
        allowed_paths={"myapp.evals.echo_eval"},
    )

Mount that view in your URL configuration:

from django.urls import path

urlpatterns = [
    path("evals/run/", eval_run, name="eval-run"),
]

Replace staff_member_required with your project's authorization check if staff-only access is not appropriate.

A project can have a small page that lists its eval suites. Use generate_eval_url() to build the URL behind each link:

from django.contrib.admin.views.decorators import staff_member_required
from django.shortcuts import render
from django.urls import reverse
from dj_evals import generate_eval_url


@staff_member_required
def eval_index(request):
    question = (
        "Give me 7 tips to improve my game in chess. "
        "My ELO is 500. I make lots of blunders."
    )
    url = reverse("eval-run") + generate_eval_url(
        "myapp.evals.echo_eval",
        {
            "model": "gpt-5.6-terra",
            "question": question,
        },
        {
            "model": "gpt-5.6-luna",
            "question": question,
        },
        # Optional. Requires OPENAI_API_KEY.
        expectations=[
            "Don't leave things hanging",
            "Castle early",
            "The answer mentions using a checklist",
            "The checklist is something simple yet effective",
        ],
    )
    return render(
        request,
        "eval_index.html",
        {"eval_suites": [("Chess tips for beginners", url)]},
    )

Render those URLs as normal links in eval_index.html:

{% for name, url in eval_suites %}
  <a href="{{ url }}">{{ name }}</a>
{% endfor %}

Clicking the link opens the comparison page. It starts one POST request per argument set and renders the streamed results side by side.

Expectations and Auto-rate use OPENAI_API_KEY to judge and compare completed runs.

Eval function contract

The eval function must be importable by dotted path and whitelisted in allowed_paths. It can be a sync or async function that returns one event, or an async generator that yields events.

def echo_eval(question="hello", model=""):
    return question


async def async_eval(question="hello", model=""):
    return question


async def streaming_eval(question="hello"):
    yield {"type": "response.output_text.delta", "delta": question}
    yield {"type": "response.output_text.done", "text": question}
    yield {"type": "response.completed", "response": {"cost": 0}}

Eval argument dictionaries are passed to the eval function as keyword arguments.

Helper utilities

You can yield EvalEvent for custom progress messages in the output panel:

from dj_evals import EvalEvent


async def streaming_eval():
    event: EvalEvent = {
        "type": "dj_evals.event",
        "message": "Fetched documents",
    }
    yield event

Developers

Run a local demo server to try the library in a browser:

uv run --with daphne daphne -p 8003 examples.local_server:application
# or, if you have just installed:
just run

Then open http://127.0.0.1:8003/ and choose an example. The OpenAI example requires OPENAI_API_KEY.

Run checks from this repo:

uv run --with ruff ruff check .
uv run --with pytest --with pytest-asyncio pytest -q
# or, if you have just installed:
just test

Metadata

Release files for dj-evals 0.7.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 dj-evals 0.7.0
File Size Uploaded
dj_evals-0.7.0.tar.gz 98.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dj-evals 0.7.0
File Interpreter ABI Platform
dj_evals-0.7.0-py3-none-any.whl Python 3 none any Details

Total release size: 193.1 kB

Release files / dj_evals-0.7.0.tar.gz

Download URL dj_evals-0.7.0.tar.gz
Size 98.5 kB
Tags Source
SHA-256 checksum
How to use checksums
2343b337a94b0d39459bb5d465890841ced69d4337f21b1e8da870605e5e14d4
BLAKE2b-256 checksum
How to use checksums
3c395ad0ff8ae774477814b10cc0940ce44b68c8c9d364d56b31e2f78ce20430
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.6 {"installer":{"name":"uv","version":"0.12.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / dj_evals-0.7.0-py3-none-any.whl

Download URL dj_evals-0.7.0-py3-none-any.whl
Size 94.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7d1fbda2a0841b039188aee8504a4df586f2ef34ae79829548888a5c8d7e33e4
BLAKE2b-256 checksum
How to use checksums
d58af258ff6cbb810e6b19f71487d3228339871f89fb98634651646a3a33861f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.6 {"installer":{"name":"uv","version":"0.12.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

0.10.0

2 release files

0.9.0

2 release files

0.8.1

2 release files

0.8.0

2 release files

This release

0.7.0 This release

2 release files

0.6.0

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

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