Skip to main content

llm-only

🧠 Conditionally serve content only to AI crawlers (LLMs) using Python.

This lightweight library detects LLM user agents and allows you to render or expose certain HTML blocks exclusively for them.


⚙️ Installation

pip install llm-only

🚀 Usage (FastAPI)

from fastapi import FastAPI, Request
from fastapi.responses import HTMLResponse
from llm_only.fastapi_middleware import LLMOnlyMiddleware

app = FastAPI()
app.add_middleware(LLMOnlyMiddleware)

@app.get("/", response_class=HTMLResponse)
async def homepage(request: Request):
    if request.state.is_llm:
        return "<h1>Pricing: 50 credits for $100/mo</h1>"
    return "<h1>Your React slider here</h1>"

🧩 Usage (Flask)

from flask import Flask
from llm_only.flask_decorator import llm_only

app = Flask(__name__)

@app.route("/")
def homepage():
    @llm_only
    def llm_content():
        return "<h3>Pricing: 50 credits for $100/mo</h3>"

    html = f"""
    <html><body>
        <div id='ui'>[React slider here]</div>
        {llm_content()}
    </body></html>
    """
    return html

📜 License

MIT License © Amal Alexander

Metadata

Release files for llm-only 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 llm-only 0.1.0
File Size Uploaded
llm_only-0.1.0.tar.gz 3.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for llm-only 0.1.0
File Interpreter ABI Platform
llm_only-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 7.2 kB

Release files / llm_only-0.1.0.tar.gz

Download URL llm_only-0.1.0.tar.gz
Size 3.2 kB
Tags Source
SHA-256 checksum
How to use checksums
b809c61081c0a910c89b6da50ab3d222b35c7adfc990e1a21639ee41909166da
BLAKE2b-256 checksum
How to use checksums
e2a993f6064d95b1a941dba71b601b3140fe5018d52c42fd55f49bd4672e84c3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.8

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

Download URL llm_only-0.1.0-py3-none-any.whl
Size 3.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2c2049b40ee3226e2da6da0d6eb6aa0276a1bddc3e2206a5d61a147fdd482c74
BLAKE2b-256 checksum
How to use checksums
5d94b2a32b7e464e0afdd31e9c629a53ddb0d58500ebdd55b2b604d469130f34
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.8

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