Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Django Chain

A Django library for seamless LangChain integration, making it easy to add LLM capabilities to your Django applications.

Python pre-commit License: MIT pre-commit Ruff documentation

codecov GitHub Actions Workflow Status


This is a reusable Django application that provides a robust framework for defining, managing, and executing multi-step Large Language Model (LLM) workflows. It offers a set of API endpoints to interact with prompts, workflows, and their execution, enabling dynamic LLM applications without direct code changes for each new workflow. You can find the documentation here.

[!WARNING] This project is currently in early alpha and is still a work in progress. You could possibly experience specific builds failing to run, loss of data between upgrades and a lot of bugs. It is highly encouraged you wait for a stable release.

Features

  • Dynamic prompt and workflow management out of the box
  • Easy integration with existing Django models and views
  • Built-in utilities for common LLM tasks
  • Type-safe and well-documented API
  • Comprehensive test coverage
  • Customizable LLM logging and telemetry
  • Production-ready with proper error handling

Core Concepts

  • Prompt: Represents a configurable template for generating LLM prompts. This can be a HumanMessagePromptTemplate, SystemMessagePromptTemplate, or ChatPromptTemplate.
  • Workflow: A sequence of ordered steps, each defining an action to be performed (e.g., format a prompt, call an LLM, parse JSON output, use a tool). Workflows orchestrate the flow of data through these steps.

Prerequisites

  1. Python 3.9+
  2. Django 4.0+

Installation

pip install django-chain

Add django_chain to your INSTALLED_APPS:

INSTALLED_APPS = [
    ...
    'django_chain',
    ...
]

Add you LLM model configurations:

DJANGO_LLM_SETTINGS = {
    "DEFAULT_LLM_PROVIDER": "fake",
    "DEFAULT_CHAT_MODEL": {
        "name": "fake-model",
        "temperature": 0.7,
        "max_tokens": 1024,
        "api_key": "fake key",
    },
    "DEFAULT_EMBEDDING_MODEL": {
        "provider": "fake",
        "name": "fake-embedding",
    },
    "VECTOR_STORE": {
        "TYPE": "pgvector",
        "PGVECTOR_COLLECTION_NAME": "test_documents",
    },
    "ENABLE_LLM_LOGGING": True,
    "LLM_LOGGING_LEVEL": "DEBUG",
    "MEMORY": {"PROVIDER": "django"},  # Use Django ChatHistory model as primary storage
    "CHAIN": {
        "DEFAULT_OUTPUT_PARSER": "str",
        "ENABLE_MEMORY": True,
    },
    "CACHE_LLM_RESPONSES": True,
    "CACHE_TTL_SECONDS": 3600,
}

Run migrations:

python manage.py makemigrations django_chain
python manage.py migrate django_chain

Quick Start

Add these urls to your app:

# your_project/urls.py
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('api/', include('django_chain.urls')), # Or your chosen app name
]

Development

  1. Clone the repository
  2. Install development dependencies:
    pip install -e ".[dev]"
    
  3. Install pre-commit hooks:
    pre-commit install
    
  4. Run tests:
    pytest
    

License

MIT License

Release files for django-chain 0.2.0a4

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

Source distribution (sdist)

Source distribution for django-chain 0.2.0a4
File Size Uploaded
django_chain-0.2.0a4.tar.gz 107.4 kB Details

Built distribution (wheel)

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

Total release size: 156.6 kB

Release files / django_chain-0.2.0a4.tar.gz

Download URL django_chain-0.2.0a4.tar.gz
Size 107.4 kB
Tags Source
SHA-256 checksum
How to use checksums
28b6c05975e1ada6b37cbec403125c607f527835e849cbca50f36250b771d80e
BLAKE2b-256 checksum
How to use checksums
6f43d20aa699d0d155c5969ce0c9b8d0b8387be5579984f7b50ec77ca7d1d299
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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 Jul 24, 2025.

Transparency log

Release files / django_chain-0.2.0a4-py3-none-any.whl

Download URL django_chain-0.2.0a4-py3-none-any.whl
Size 49.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
feb3c49c4bba45f956afd225f899021754a5adb3216967391001bdc866a1fb45
BLAKE2b-256 checksum
How to use checksums
43d36f7ce691c0086fddc60a63cea8ec50e7e425e56f57b0ad99c95a3b7b6dfd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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 Jul 24, 2025.

Transparency log
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