YuktaiDocs v5.3.12

Python (pip)

YuktAI for Python

The yuktai package adds YuktAI to pages made by Django, Flask or FastAPI in one line: the ♿ accessibility widget, the 🛠 page tools and everything in window.yuktai. YuktAI still runs in the visitor's browser. The package only writes the right script tags for you.

1. Install

Terminal
pip install yuktai

On PyPI: pypi.org/project/yuktai (opens in a new tab)

2. Flask

app.py
from flask import Flask
import yuktai

app = Flask(__name__)
yuktai.init_app(app, position="right", show_page_tools=True)
templates/base.html (before </body>)
{{ yuktai_script() }}

3. FastAPI

main.py
from fastapi.templating import Jinja2Templates
import yuktai

templates = Jinja2Templates(directory="templates")
yuktai.init_jinja(templates.env, show_page_tools=True)
templates/base.html (before </body>)
{{ yuktai_script() }}

4. Django

settings.py
INSTALLED_APPS = [
    # ...
    "yuktai",
]

# optional defaults for every page
YUKTAI = {"position": "right", "show_page_tools": True}
templates/base.html (before </body>)
{% load yuktai_tags %}
{% yuktai_script %}

Change options for one page: {% yuktai_script default_tab="ask" %}

5. Any other Python code

any.py
import yuktai

html = yuktai.script_tag(position="right", show_page_tools=True, voice_lang="te-IN")
# put html just before </body>

The result is ready HTML: a small window.YUKTAI_CONFIG script (only when you pass options) and the YuktAI script from jsDelivr.

Options

Arguments of script_tag() and yuktai_script
OptionWhat it does
versionYuktAI release to load. The package pins a tested release; "latest" follows new releases.
position"left" or "right"
primary_colorButton colour, for example "#0a4a85"
titleTitle of the settings dialog (Telugu works)
show_page_toolsAdds the 🛠 page tools button
default_tabcopilot, qa, forms, design, ask or voice
voice_langSpeech language, for example "te-IN"
auto_fix, show_skip_linksAccessibility engine options
extraAny other YUKTAI_CONFIG key, as a dict
cdn"jsdelivr" (default) or "unpkg"
nonceFor pages with a Content Security Policy

Safe by design

Safe JSON

Options are written as JSON with <, > and & escaped, so a value like </script> can't break out of the tag.

Checked values

Position, colour, tab, version, CDN and nonce are checked. A wrong value raises ValueError instead of writing broken HTML.

CSP ready

Pass nonce= and both script tags get it. Add cdn.jsdelivr.net to script-src, and 'wasm-unsafe-eval' for the Rust engines.

Not escaped twice

The tag is marked safe for Jinja2 and Django, so autoescaping does not turn it into text.

Coming next

Version 0.2 brings YuktAI's Rust engines to Python: fast grid search and the BM25 index for page RAG, with the same results as in the browser.