django-db-chat-widget
Django integration for db-chat-widget: drop a natural-language database chatbot into any Django template as a floating popup (or inline panel), backed by your existing Django database connection.
- Reuses your existing Django database connection — no separate
credentials to configure; the SQLAlchemy URL is derived automatically from
settings.DATABASES(PostgreSQL, MySQL, SQLite). - Pluggable LLM backend: Anthropic Claude, OpenAI, Groq, or a local Ollama model (via db-chat-widget).
- Read-only by default: generated SQL is parsed and only
SELECTstatements are allowed unless you explicitly opt into write access. - One template tag:
{% db_chat_widget %}renders a floating chat bubble (or an inline panel) — no extra views or URLs to wire up yourself. - Proper CSRF handling: works with Django's CSRF protection out of the
box, no
csrf_exemptrequired.
Install
pip install django-db-chat-widget
This pulls in db-chat-widget
(the framework-agnostic core: LLM providers, SQL safety checks, query
execution) as a dependency.
Add the app and its URLs:
# settings.py
INSTALLED_APPS = [
...,
"django.contrib.staticfiles",
"django_db_chat_widget",
]
TEMPLATES = [
{
...,
"OPTIONS": {
"context_processors": [
...,
"django.template.context_processors.request", # required
],
},
},
]
DB_CHAT_WIDGET = {
"DB_ALIAS": "default", # which DATABASES entry to query
"LLM_PROVIDER": "groq", # "anthropic" | "openai" | "groq" | "ollama"
"LLM_API_KEY": "gsk_...", # or read from os.environ
"READ_ONLY": True, # default: only SELECT statements allowed
"MAX_ROWS": 200,
"ALLOWED_TABLES": None, # e.g. ["orders", "customers"] to scope access
"TITLE": "Ask your database",
}
# urls.py
from django.urls import include, path
urlpatterns = [
...,
path("db-chat/", include("django_db_chat_widget.urls")),
]
Then drop the tag into any template:
{% load db_chat_widget %}
{% db_chat_widget %}
That's it — a floating chat bubble now appears in the bottom-right corner of
that page. See example_project/ for a complete, runnable
Django project demonstrating this end to end.
Template tag options
{% db_chat_widget %} {# popup, bottom-right #}
{% db_chat_widget position="bottom-left" %} {# popup, bottom-left #}
{% db_chat_widget target="#my-chat-div" %} {# inline instead of popup #}
{% db_chat_widget title="Ask HR" placeholder="..." %}
Multiple databases / explicit connection
If your Django project has several DATABASES entries, point
DB_CHAT_WIDGET["DB_ALIAS"] at the one to query. To bypass Django's
DATABASES entirely (e.g. a read replica not declared there), set
DB_CHAT_WIDGET["DB_URL"] to an explicit SQLAlchemy URL instead — it takes
precedence over DB_ALIAS.
Safety notes
READ_ONLY=True(the default) is enforced by parsing the generated SQL withsqlglot, not just by prompting the model — treat it as the actual security boundary. See db-chat-widget's safety notes for details.- Use
ALLOWED_TABLESto scope the chatbot away from sensitive tables (e.g. Django's ownauth_user/ session tables). - The
/db-chat/chat/endpoint is a normal Django view protected by Django's CSRF middleware; the template tag ensures the CSRF cookie is set on any page that renders it.
Development
pip install -e ".[dev]"
pytest
ruff check .
License
MIT
Metadata
Release files for django-db-chat-widget 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django_db_chat_widget-0.1.1.tar.gz | 14.7 kB | Without provenance | Details for django_db_chat_widget-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_db_chat_widget-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for django_db_chat_widget-0.1.1-py3-none-any.whl |
Total release size: 27.8 kB
Release files / django_db_chat_widget-0.1.1.tar.gz
| Download URL | django_db_chat_widget-0.1.1.tar.gz |
|---|---|
| Size | 14.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1dda47432d37268baca15784c560c8c49529e338df916117015d67296ca9cd37
|
|
BLAKE2b-256 checksum How to use checksums |
9e4f3ce83074b5ae862839cee8e6b5e1af545d2be02c5bfa78e729257e8e2440
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Release files / django_db_chat_widget-0.1.1-py3-none-any.whl
| Download URL | django_db_chat_widget-0.1.1-py3-none-any.whl |
|---|---|
| Size | 13.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4574de2af45c3fdd181c4b35b6d7ca37bd08d4220ea08e6038221d9291f1d196
|
|
BLAKE2b-256 checksum How to use checksums |
4864f4ca23949fc1b3fe67d8a4a1bfa35aeb25a8bb29ac3a5c90fd3918c0a152
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Security for django-db-chat-widget 0.1.1
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.