Skip to main content

drf-toon

Native TOON (Token Oriented Object Notation) parser and renderer for Django REST Framework.

TOON is a token-efficient serialization format designed for LLM contexts. It can result in 30–60% fewer tokens than JSON.

drf-toon is built on toons, a high-performance Rust implementation meant to mimic the native python json package.

Compatibility

drf-toon supports Django 5.2 LTS on Python 3.10–3.13, matching Django's own support matrix. Every supported Python version is exercised in CI.

Django Python
5.2 LTS 3.10, 3.11, 3.12, 3.13

Support for additional Django releases can be added later by extending the CI matrix.

Installation

pip install drf-toon

Usage

Add the parser and renderer to your DRF settings:

# settings.py
REST_FRAMEWORK = {
    "DEFAULT_PARSER_CLASSES": [
        "drf_toon.parsers.TOONParser",
        "rest_framework.parsers.JSONParser",
    ],
    "DEFAULT_RENDERER_CLASSES": [
        "drf_toon.renderers.TOONRenderer",
        "rest_framework.renderers.JSONRenderer",
    ],
}

Or enable them per-view:

from rest_framework.views import APIView
from rest_framework.response import Response

from drf_toon.parsers import TOONParser
from drf_toon.renderers import TOONRenderer


class UserView(APIView):
    parser_classes = [TOONParser]
    renderer_classes = [TOONRenderer]

    def get(self, request):
        return Response({"name": "Alice", "age": 30})

Both classes use the application/toon media type. Send requests with Content-Type: application/toon to parse, and Accept: application/toon (or ?format=toon) to render.

Development

Install the dev dependencies and run the checks with uv:

uv sync --dev

uv run ruff check .          # lint
uv run ruff format .         # format
uv run ruff format --check . # format check (CI)
uv run mypy                  # type check
uv run pytest                # tests + coverage

Optionally install the git hooks:

uv run pre-commit install --install-hooks

This wires up both a pre-commit hook (autofix + format) and a pre-push hook that blocks the push if the code is not properly linted/formatted.

License

MIT

Release files for drf-toon 0.1.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 drf-toon 0.1.0
File Size Uploaded
drf_toon-0.1.0.tar.gz 2.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for drf-toon 0.1.0
File Interpreter ABI Platform
drf_toon-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 6.3 kB

Release files / drf_toon-0.1.0.tar.gz

Download URL drf_toon-0.1.0.tar.gz
Size 2.8 kB
Tags Source
SHA-256 checksum
How to use checksums
d579bcd7bc91ecfc74e6da43dcd68527a540390362b2ce8c43a8ca370164b77f
BLAKE2b-256 checksum
How to use checksums
056a8c1fcd247238a43cafc4eb65fa8d1bc6fa218d16baafa4651a39843c867d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / drf_toon-0.1.0-py3-none-any.whl

Download URL drf_toon-0.1.0-py3-none-any.whl
Size 3.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
556ae6c5133bb848ca35e7a3e3df9374ca477323ba17a77ef12faf707929c194
BLAKE2b-256 checksum
How to use checksums
cdb4902d5e891378b4c01b857ff92f2ec4fab4e246f50872606bb1ca29a14a10
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

0.1.0 This release

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